use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.
the class WidgetTree method removeWidget.
/**
* Remove widget from existing model & tree
* @param removed_widget
*/
private void removeWidget(final Widget removed_widget) {
if (removed_widget instanceof TabsWidget) {
final ArrayWidgetProperty<TabItemProperty> tabs = ((TabsWidget) removed_widget).propTabs();
tabs.removePropertyListener(tabs_property_listener);
removeTabs(tabs.getValue());
}
removed_widget.propName().removePropertyListener(name_listener);
final ChildrenProperty children = ChildrenProperty.getChildren(removed_widget);
if (children != null) {
children.removePropertyListener(children_listener);
for (Widget child : children.getValue()) removeWidget(child);
}
final TreeItem<WidgetOrTab> item = widget2tree.remove(removed_widget);
item.getParent().getChildren().remove(item);
}
use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.
the class WidgetTree method addWidget.
/**
* Add widget to existing model & tree
* @param added_widget Widget to add
* @param index Index of widget within parent. -1 to add at end
*/
private void addWidget(final Widget added_widget, final int index) {
// Have widget and its parent in model
final Widget widget_parent = added_widget.getParent().get();
// Determine parent tree item
TreeItem<WidgetOrTab> item_parent = null;
if (widget_parent instanceof TabsWidget) {
for (TabItemProperty tab : ((TabsWidget) widget_parent).propTabs().getValue()) if (tab.children().getValue().contains(added_widget)) {
item_parent = tab_name2tree.get(tab.name());
break;
}
} else
item_parent = widget2tree.get(widget_parent);
Objects.requireNonNull(item_parent, "Cannot obtain parent item for " + added_widget);
// Create Tree item
final TreeItem<WidgetOrTab> item = new TreeItem<>(WidgetOrTab.of(added_widget));
widget2tree.put(added_widget, item);
item.setExpanded(true);
if (index >= 0)
// Add at same index into Tree
item_parent.getChildren().add(index, item);
else
// Append to end
item_parent.getChildren().add(item);
added_widget.propName().addPropertyListener(name_listener);
if (added_widget instanceof TabsWidget) {
final ArrayWidgetProperty<TabItemProperty> tabs = ((TabsWidget) added_widget).propTabs();
addTabs(tabs.getValue());
tabs.addPropertyListener(tabs_property_listener);
} else {
final ChildrenProperty children = ChildrenProperty.getChildren(added_widget);
if (children != null) {
children.addPropertyListener(children_listener);
for (Widget child : children.getValue()) addWidget(child, -1);
}
}
}
use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.
the class WidgetTree method removeWidgetListeners.
/**
* Recursively remove model widget listeners
* @param container Widgets to unlink
*/
private void removeWidgetListeners(final Widget widget) {
if (widget instanceof TabsWidget) {
final ArrayWidgetProperty<TabItemProperty> tabs = ((TabsWidget) widget).propTabs();
tabs.removePropertyListener(tabs_property_listener);
for (TabItemProperty tab : tabs.getValue()) {
tab.children().removePropertyListener(children_listener);
tab.name().removePropertyListener(tab_name_listener);
}
}
widget.propName().removePropertyListener(name_listener);
final ChildrenProperty children = ChildrenProperty.getChildren(widget);
if (children != null) {
children.removePropertyListener(children_listener);
for (Widget child : children.getValue()) removeWidgetListeners(child);
}
}
use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.
the class JFXBaseRepresentation method createComponents.
/**
* {@inheritDoc}
*/
@Override
public Parent createComponents(final Parent parent) throws Exception {
jfx_node = createJFXNode();
if (jfx_node != null) {
// Order JFX children same as model widgets within their container
int index = -1;
final Optional<Widget> container = model_widget.getParent();
if (container.isPresent()) {
if (container.get() instanceof TabsWidget) {
// Locate model_widget inside one of the Tab's children
final List<TabItemProperty> tabs = ((TabsWidget) container.get()).propTabs().getValue();
for (TabItemProperty tab : tabs) {
final int i = tab.children().getValue().indexOf(model_widget);
if (i >= 0) {
index = i;
break;
}
}
} else
index = container.get().getProperty(ChildrenProperty.DESCRIPTOR).getValue().indexOf(model_widget);
}
if (index < 0)
JFXRepresentation.getChildren(parent).add(jfx_node);
else
JFXRepresentation.getChildren(parent).add(index, jfx_node);
if (toolkit.isEditMode()) {
// Any visible item can be 'clicked' to allow editor to 'select' it
final EventHandler<MouseEvent> detect_click = event -> {
if (event.isPrimaryButtonDown()) {
event.consume();
toolkit.fireClick(model_widget, event.isControlDown());
}
};
if (isFilteringEditModeClicks())
jfx_node.addEventFilter(MouseEvent.MOUSE_PRESSED, detect_click);
else
jfx_node.addEventHandler(MouseEvent.MOUSE_PRESSED, detect_click);
} else
jfx_node.setOnContextMenuRequested((event) -> {
event.consume();
toolkit.fireContextMenu(model_widget);
});
}
registerListeners();
updateChanges();
return getChildParent(parent);
}
use of org.csstudio.display.builder.model.widgets.TabsWidget in project org.csstudio.display.builder by kasemir.
the class ChildrenProperty method getParentsChildren.
/**
* Get the 'children' list of a widget's parent.
*
* <p>This is either the children list of a plain parent,
* or the children list inside a TabWidget's tab.
*
* @param widget Widget where parent (plain or TabWidget) is checked for
* @return {@link ChildrenProperty} that contains the widget
* @throws NoSuchElementException if widget has no parent
* @throws IllegalArgumentException If no tab of parent {@link TabWidget} contains the widget,
* @throws IllegalStateException If parent has no children
*/
public static ChildrenProperty getParentsChildren(final Widget widget) {
final Widget parent = widget.getParent().get();
if (parent instanceof TabsWidget) {
final List<TabItemProperty> tabs = ((TabsWidget) parent).propTabs().getValue();
for (TabItemProperty tab : tabs) {
final ChildrenProperty children = tab.children();
if (children.getValue().contains(widget))
return children;
}
throw new IllegalArgumentException("Cannot locate " + widget + " in " + parent);
}
final Optional<WidgetProperty<List<Widget>>> children = parent.checkProperty(DESCRIPTOR);
if (children.isPresent())
return (ChildrenProperty) children.get();
throw new IllegalStateException("Parent of " + widget + " has no 'children': " + parent);
}
Aggregations