X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.plant3d%2Fsrc%2Forg%2Fsimantics%2Fplant3d%2Fdialog%2FComponentSelectionDialog.java;h=30f2540d5ccee1be1953ff0db181d2247c24a2ae;hb=53d55c24c779745f188bdb18d32f71d20acb61b2;hp=adfd98c97278dbc0e9b9df57a15bcf47d9a77032;hpb=f36217aeeb09c0c46f99886ee99772156ce9cfe6;p=simantics%2F3d.git diff --git a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java index adfd98c9..30f2540d 100644 --- a/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java +++ b/org.simantics.plant3d/src/org/simantics/plant3d/dialog/ComponentSelectionDialog.java @@ -46,8 +46,8 @@ import org.simantics.utils.ui.ExceptionUtils; public class ComponentSelectionDialog extends Dialog implements ISelectionChangedListener{ - private ResourceManager resourceManager; - + private ResourceManager resourceManager; + private Item selected; private Set allowed; private Set filterAllowed; @@ -91,8 +91,8 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange @Override protected Control createDialogArea(Composite parent) { - resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent); - + resourceManager = new LocalResourceManager(JFaceResources.getResources(), parent); + Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2,false); layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); @@ -170,42 +170,42 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange GridDataFactory.fillDefaults().minSize(500, 500).hint(500, 500).applyTo(composite); Label label = new Label(composite, SWT.NONE); - label.setText("Position"); + label.setText("Position"); Composite buttonComposite = new Composite(composite, SWT.NONE); - startButton = new Button(buttonComposite, SWT.TOGGLE); - middleButton = new Button(buttonComposite, SWT.TOGGLE); - endButton = new Button(buttonComposite, SWT.TOGGLE); - startButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_start.png"))); - middleButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_middle.png"))); - endButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_end.png"))); - GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(buttonComposite); - GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); + startButton = new Button(buttonComposite, SWT.TOGGLE); + middleButton = new Button(buttonComposite, SWT.TOGGLE); + endButton = new Button(buttonComposite, SWT.TOGGLE); + startButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_start.png"))); + middleButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_middle.png"))); + endButton.setImage(resourceManager.createImage(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/insert_end.png"))); + GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).applyTo(buttonComposite); + GridLayoutFactory.fillDefaults().numColumns(3).applyTo(buttonComposite); + + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(false); + + startButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateInsertPosition(PositionType.PREVIOUS); + } + }); + + middleButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateInsertPosition(PositionType.SPLIT); + } + }); + endButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateInsertPosition(PositionType.NEXT); + } + }); + endButton.setSelection(true); - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(false); - - startButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateInsertPosition(PositionType.PREVIOUS); - } - }); - - middleButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateInsertPosition(PositionType.SPLIT); - } - }); - endButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateInsertPosition(PositionType.NEXT); - } - }); - endButton.setSelection(true); - label = new Label(composite, SWT.NONE); label.setText("Length"); lengthText = new Text(composite, SWT.SINGLE|SWT.BORDER); @@ -289,12 +289,12 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange private void updateInsertPosition(PositionType type) { - if (insertPosition == type) - return; - endButton.setSelection(type == PositionType.NEXT); - middleButton.setSelection(type == PositionType.SPLIT); - startButton.setSelection(type == PositionType.PREVIOUS); - insertPosition = type; + if (insertPosition == type) + return; + endButton.setSelection(type == PositionType.NEXT); + middleButton.setSelection(type == PositionType.SPLIT); + startButton.setSelection(type == PositionType.PREVIOUS); + insertPosition = type; } @Override @@ -302,18 +302,18 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange IStructuredSelection sel = (IStructuredSelection)event.getSelection(); 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()); - } - validate(); + 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()); + } + validate(); } } @@ -326,66 +326,66 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange } else if (selected.isCode()) {// TODO : instead of disabling the button, we should filter the content. ok = false; } else { - lenghtAdjustable = ((selected.getType() == Type.INLINE) && selected.isVariable()); - if (insertAdjustable) { - switch (selected.getType()) { - case END: - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - updateInsertPosition(PositionType.NEXT); - break; - case INLINE: - if (!selected.isVariable()) { - startButton.setEnabled(true); - middleButton.setEnabled(true); - endButton.setEnabled(true); - } else { - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - updateInsertPosition(PositionType.NEXT); - } - break; - case NOZZLE: - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - updateInsertPosition(PositionType.NEXT); - break; - case TURN: - startButton.setEnabled(false); - middleButton.setEnabled(true); - endButton.setEnabled(true); - if (insertPosition == PositionType.PREVIOUS) - updateInsertPosition(PositionType.NEXT); - break; - case EQUIPMENT: - throw new RuntimeException("Expected component, got equipment " + selected); - } - } else if (lenghtAdjustable) { - if (component instanceof InlineComponent) { - startButton.setEnabled(true); - middleButton.setEnabled(true); - endButton.setEnabled(true); - } else if (component instanceof TurnComponent) { - startButton.setEnabled(false); - middleButton.setEnabled(true); - endButton.setEnabled(true); - if (insertPosition == PositionType.PREVIOUS) - updateInsertPosition(PositionType.NEXT); - } else if (component instanceof EndComponent || component instanceof Nozzle) { - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - updateInsertPosition(PositionType.NEXT); - } - } else { - startButton.setEnabled(false); - middleButton.setEnabled(false); - endButton.setEnabled(true); - } - if (selected.isVariable()) { + lenghtAdjustable = ((selected.getType() == Type.INLINE) && selected.isVariable()); + if (insertAdjustable) { + switch (selected.getType()) { + case END: + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + updateInsertPosition(PositionType.NEXT); + break; + case INLINE: + if (!selected.isVariable()) { + startButton.setEnabled(true); + middleButton.setEnabled(true); + endButton.setEnabled(true); + } else { + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + updateInsertPosition(PositionType.NEXT); + } + break; + case NOZZLE: + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + updateInsertPosition(PositionType.NEXT); + break; + case TURN: + startButton.setEnabled(false); + middleButton.setEnabled(true); + endButton.setEnabled(true); + if (insertPosition == PositionType.PREVIOUS) + updateInsertPosition(PositionType.NEXT); + break; + case EQUIPMENT: + throw new RuntimeException("Expected component, got equipment " + selected); + } + } else if (lenghtAdjustable) { + if (component instanceof InlineComponent) { + startButton.setEnabled(true); + middleButton.setEnabled(true); + endButton.setEnabled(true); + } else if (component instanceof TurnComponent) { + startButton.setEnabled(false); + middleButton.setEnabled(true); + endButton.setEnabled(true); + if (insertPosition == PositionType.PREVIOUS) + updateInsertPosition(PositionType.NEXT); + } else if (component instanceof EndComponent || component instanceof Nozzle) { + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + updateInsertPosition(PositionType.NEXT); + } + } else { + startButton.setEnabled(false); + middleButton.setEnabled(false); + endButton.setEnabled(true); + } + if (selected.isVariable()) { if (selected.getType() == Type.INLINE) { filterAllowed.add(PositionType.NEXT); filterAllowed.add(PositionType.PREVIOUS); @@ -488,15 +488,15 @@ public class ComponentSelectionDialog extends Dialog implements ISelectionChange } public PositionType getInsertPosition() { - return insertPosition; - } + return insertPosition; + } public boolean isInsertAdjustable() { - return insertAdjustable; - } + return insertAdjustable; + } public boolean isLenghtAdjustable() { - return lenghtAdjustable; - } + return lenghtAdjustable; + } }