ExpandBar expandBar = new ExpandBar(composite, SWT.V_SCROLL);
- ExpandItem inlineItem = new ExpandItem(expandBar, SWT.NONE);
- inlineItem.setText("Inline");
- inlineViewer = new ListViewer(expandBar);
- inlineViewer.setLabelProvider(new ComponentLabelProvider());
- inlineViewer.setContentProvider(new ComponentContentProvider());
-
- ExpandItem turnItem = new ExpandItem(expandBar, SWT.NONE);
- turnItem.setText("Elbow");
- turnViewer = new ListViewer(expandBar);
- turnViewer.setLabelProvider(new ComponentLabelProvider());
- turnViewer.setContentProvider(new ComponentContentProvider());
-
- ExpandItem endItem = new ExpandItem(expandBar, SWT.NONE);
- endItem.setText("End");
- endViewer = new ListViewer(expandBar);
- endViewer.setLabelProvider(new ComponentLabelProvider());
- endViewer.setContentProvider(new ComponentContentProvider());
-
- inlineItem.setControl(inlineViewer.getList());
- turnItem.setControl(turnViewer.getList());
- endItem.setControl(endViewer.getList());
-
- inlineViewer.setInput(inlines);
- turnViewer.setInput(turns);
- endViewer.setInput(ends);
-
- inlineItem.setHeight(inlineViewer.getList().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
- turnItem.setHeight(turnViewer.getList().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
- endItem.setHeight(endViewer.getList().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
-
- inlineViewer.addSelectionChangedListener(this);
- turnViewer.addSelectionChangedListener(this);
- endViewer.addSelectionChangedListener(this);
+ if (!inlines.isEmpty()) {
+ inlineViewer = createItemList(expandBar, inlines, "Inline");
+ }
+
+ // Only allow elbows and ends to be added to open ends of the pipelines
+ boolean isOpen = component.getNext() == null || component.getPrevious() == null;
+ if (isOpen) {
+ if (!turns.isEmpty()) {
+ turnViewer = createItemList(expandBar, turns, "Elbow");
+ }
+
+ if (!ends.isEmpty()) {
+ turnViewer = createItemList(expandBar, ends, "End");
+ }
+ }
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(expandBar);
GridDataFactory.fillDefaults().grab(true, true).minSize(500, 500).hint(500, 500).applyTo(composite);
return composite;
}
+ private ListViewer createItemList(ExpandBar expandBar, List<Item> items, String name) {
+ ExpandItem expandItem = new ExpandItem(expandBar, SWT.NONE);
+ expandItem.setText(name);
+ ListViewer viewer = new ListViewer(expandBar);
+ viewer.setLabelProvider(new ComponentLabelProvider());
+ viewer.setContentProvider(new ComponentContentProvider());
+
+ expandItem.setControl(viewer.getList());
+ viewer.setInput(items);
+ expandItem.setHeight(viewer.getList().computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
+ viewer.addSelectionChangedListener(this);
+ return viewer;
+ }
+
private boolean hasInsertPosition() {
return component.getNext() == null || component.getPrevious() == null;
}
Item i = (Item) sel.getFirstElement();
if (i != null) {
selected = i;
- if (event.getSource() == inlineViewer) {
- turnViewer.setSelection(new StructuredSelection());
- endViewer.setSelection(new StructuredSelection());
- } else if (event.getSource() == turnViewer) {
- inlineViewer.setSelection(new StructuredSelection());
- endViewer.setSelection(new StructuredSelection());
- } else if (event.getSource() == endViewer) {
- inlineViewer.setSelection(new StructuredSelection());
- turnViewer.setSelection(new StructuredSelection());
+ if (inlineViewer != null && event.getSource() == inlineViewer) {
+ clearSelection(turnViewer);
+ clearSelection(endViewer);
+ } else if (turnViewer != null && event.getSource() == turnViewer) {
+ clearSelection(inlineViewer);
+ clearSelection(endViewer);
+ } else if (endViewer != null && event.getSource() == endViewer) {
+ clearSelection(inlineViewer);
+ clearSelection(turnViewer);
}
name = generateUniqueName(selected.getName());
}
}
+ private void clearSelection(ListViewer possibleListViewer) {
+ if (possibleListViewer != null)
+ possibleListViewer.setSelection(new StructuredSelection());
+ }
+
private void validate() {
filterAllowed.clear();
Set<PositionType> filterAllowed = new HashSet<PositionType>();