Skip to content

Commit

Permalink
#7461 introducing WidgetItem interface for handling display on output…
Browse files Browse the repository at this point in the history
… container items
  • Loading branch information
Lukasz Mitusinski committed Jul 17, 2018
1 parent 9a2db3d commit 73f020f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.twosigma.beakerx.widget.DisplayableWidget;
import com.twosigma.beakerx.widget.ValueWidget;
import com.twosigma.beakerx.widget.Widget;
import com.twosigma.beakerx.widget.WidgetItem;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
Expand All @@ -45,7 +46,7 @@
import java.util.stream.Collectors;

@SuppressWarnings("unchecked")
public class EasyForm extends ObservableMap<String, Object> implements DisplayableWidget {
public class EasyForm extends ObservableMap<String, Object> implements DisplayableWidget, WidgetItem {

public static final Integer HORIZONTAL = 1;
public static final Integer VERTICAL = 2;
Expand Down Expand Up @@ -387,4 +388,8 @@ public void display() {
this.getView().display();
}

@Override
public Widget asWidget() {
return getView();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package com.twosigma.beakerx.jvm.object;

import com.twosigma.beakerx.MIMEContainerFactory;
import com.twosigma.beakerx.easyform.EasyForm;
import com.twosigma.beakerx.mimetype.MIMEContainer;
import com.twosigma.beakerx.widget.HTML;
import com.twosigma.beakerx.widget.HTMLPre;
import com.twosigma.beakerx.widget.Widget;
import com.twosigma.beakerx.widget.WidgetItem;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -55,16 +55,13 @@ private Optional<Widget> toWidget(Object item) {
if (item == null) {
return handleNull();
}
if (item instanceof EasyForm) {
return of(((EasyForm) item).getView());
if (item instanceof WidgetItem) {
return of(((WidgetItem) item).asWidget());
}
Widget widget = MIMEContainerFactory.getTableDisplay(item);
if (widget != null) {
return of(widget);
}
if (item instanceof Widget) {
return of((Widget) item);
}
if (item instanceof MIMEContainer) {
return of(createHTML(((MIMEContainer) item).getData().toString()));
}
Expand Down
17 changes: 11 additions & 6 deletions kernel/base/src/main/java/com/twosigma/beakerx/widget/Widget.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
*/
package com.twosigma.beakerx.widget;

import com.twosigma.beakerx.kernel.KernelManager;
import com.twosigma.beakerx.kernel.comm.Comm;
import com.twosigma.beakerx.kernel.comm.TargetNamesEnum;
import com.twosigma.beakerx.message.Message;

import java.io.Serializable;
import java.util.HashMap;

import static com.twosigma.beakerx.handler.KernelHandlerWrapper.wrapBusyIdle;
import static com.twosigma.beakerx.kernel.msg.JupyterMessages.DISPLAY_DATA;

import com.twosigma.beakerx.kernel.KernelManager;
import com.twosigma.beakerx.kernel.comm.Comm;
import com.twosigma.beakerx.kernel.comm.TargetNamesEnum;
import com.twosigma.beakerx.message.Message;

public abstract class Widget implements CommFunctionality, DisplayableWidget {
public abstract class Widget implements CommFunctionality, DisplayableWidget, WidgetItem {

public static final String APPLICATION_VND_JUPYTER_WIDGET_VIEW_JSON = "application/vnd.jupyter.widget-view+json";
public static final String MODEL_ID = "model_id";
Expand Down Expand Up @@ -179,4 +179,9 @@ public interface WidgetDisplayMethodStrategy {
void display(Widget widget);
}

@Override
public Widget asWidget() {
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2018 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.twosigma.beakerx.widget;

import com.twosigma.beakerx.widget.Widget;

public interface WidgetItem {

Widget asWidget();
}

0 comments on commit 73f020f

Please sign in to comment.