Example usage for org.eclipse.jface.viewers StructuredSelection StructuredSelection

List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection StructuredSelection.

Prototype

public StructuredSelection(List elements) 

Source Link

Document

Creates a structured selection from the given List.

Usage

From source file:au.gov.ansto.bragg.kowari.exp.command.AdvancedParameter.java

License:Open Source License

@Override
public void createParameterUI(final Composite parent, final AbstractScanCommandView commandView,
        final FormToolkit toolkit) {
    final Group parameterGroup = new Group(parent, SWT.NULL);
    //      toolkit.adapt(parameterGroup);
    //      parameterGroup.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    parameterGroup.setBackground(parent.getBackground());
    parameterGroup.setText("Dimension-" + commandView.getCommand().indexOfParameter(this));

    //      GridLayoutFactory.swtDefaults().spacing(6, 0).numColumns(5).applyTo(parameterGroup);
    GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).applyTo(parameterGroup);

    //      Composite singleParameterComposite = toolkit.createComposite(parent);
    //      GridLayoutFactory.swtDefaults().margins(0, 0).spacing(6, 4).numColumns(5).applyTo(singleParameterComposite);
    if (parameters.size() == 0) {
        SingleADParameter parameter = new SingleADParameter(this);
        parameter.setScanVariable("sx");
        parameters.add(parameter);/*  www  . ja va 2s . c  o  m*/
    }
    for (SingleADParameter parameter : parameters) {
        parameter.createParameterUI(parameterGroup, commandView, toolkit);
    }

    final Text numberOfPointsText = toolkit.createText(parent, "");
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).indent(0, 12)
            .hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT).applyTo(numberOfPointsText);
    addValidator(numberOfPointsText, ParameterValidator.integerValidator);

    final Button multiFileButton = toolkit.createButton(parent, "multiple_files", SWT.RADIO);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).indent(0, 12).hint(80, SWT.DEFAULT)
            .applyTo(multiFileButton);

    multiFileButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            firePropertyChange("multiple files", null, true);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });

    Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), new Runnable() {
        public void run() {
            DataBindingContext bindingContext = new DataBindingContext();
            bindingContext.bindValue(SWTObservables.observeText(numberOfPointsText, SWT.Modify),
                    BeansObservables.observeValue(getInstance(), "numberOfPoints"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
            bindingContext.bindValue(SWTObservables.observeSelection(multiFileButton),
                    BeansObservables.observeValue(getInstance(), "doCreateFile"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
        }
    });

    final AbstractScanCommand command = commandView.getCommand();

    Button addButton = toolkit.createButton(parent, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).indent(0, 9).hint(24, 24).applyTo(addButton);
    try {
        addButton.setImage(SicsBatchUIUtils.getBatchEditorImage("ADD"));
    } catch (FileNotFoundException e2) {
        LoggerFactory.getLogger(this.getClass()).error("can not find ADD image", e2);
    }
    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addNewParameter(command);
            commandView.refreshParameterComposite();
            //            notifyPropertyChanged(newCommand, null);
        }
    });

    Button removeButton = toolkit.createButton(parent, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).indent(0, 9).hint(24, 24).applyTo(removeButton);
    try {
        removeButton.setImage(SicsBatchUIUtils.getBatchEditorImage("REMOVE"));
    } catch (FileNotFoundException e1) {
        LoggerFactory.getLogger(this.getClass()).error("can not find REMOVE image", e1);
    }
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeParameter(command);
            commandView.refreshParameterComposite();
        }
    });

    DragSource dragSource = new DragSource(parameterGroup, DND.DROP_MOVE);
    dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
    final AdvancedParameter parameter = this;
    dragSource.addDragListener(new DragSourceAdapter() {

        @Override
        public void dragFinished(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(null);
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
                DndTransferData transferData = new DndTransferData();
                transferData.setParent(command);
                transferData.setChild(parameter);
                LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(transferData));
            }
        }
    });

    DropTarget dropTarget = new DropTarget(parameterGroup, DND.DROP_MOVE);
    final AdvancedParameter parentParameter = this;
    dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
    dropTarget.addDropListener(new DropTargetAdapter() {
        @Override
        public void drop(DropTargetEvent event) {
            if (event.data instanceof StructuredSelection) {
                DndTransferData transferData = (DndTransferData) ((StructuredSelection) event.data)
                        .getFirstElement();
                Object parentData = transferData.getParent();
                Object child = transferData.getChild();
                if (parentData == parentParameter) {
                    Point relativePoint = parameterGroup.toControl(new Point(event.x, event.y));
                    int index = 0;
                    for (Control control : parameterGroup.getChildren()) {
                        if (control instanceof Combo) {
                            if (relativePoint.y < control.getBounds().y + control.getBounds().height) {
                                break;
                            }
                            index++;
                        }
                    }
                    if (child instanceof SingleADParameter) {
                        SingleADParameter parameter = (SingleADParameter) child;
                        int currentIndex = indexOfSingleADParameter(parameter);
                        if (currentIndex == index) {
                            return;
                        }
                        removeSigleParameter(parameter);
                        insertSigleADParameter(index, parameter);
                        commandView.refreshParameterComposite();
                    }
                } else if (parentData == command) {
                    Point relativePoint = parent.toControl(new Point(event.x, event.y));
                    int index = 0;
                    for (Control control : parent.getChildren()) {
                        if (control instanceof Group) {
                            if (relativePoint.y < (control.getBounds().y + control.getBounds().height)) {
                                break;
                            }
                            index++;
                        }
                    }
                    if (child instanceof AdvancedParameter) {
                        AdvancedParameter parameter = (AdvancedParameter) child;
                        int currentIndex = command.indexOfParameter(parameter);
                        if (currentIndex == index) {
                            return;
                        }
                        command.removeParameter(parameter);
                        command.insertParameter(index, parameter);
                        commandView.refreshParameterComposite();
                    }
                }
            }
        }
    });
}

From source file:au.gov.ansto.bragg.kowari.exp.command.HmmscanParameter.java

License:Open Source License

@Override
public void createParameterUI(Composite parent, final AbstractScanCommandView commandView,
        final FormToolkit toolkit) {
    Group parameterGroup = new Group(parent, SWT.NULL);
    //      toolkit.adapt(parameterGroup);
    //      parameterGroup.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    parameterGroup.setBackground(parent.getBackground());
    parameterGroup.setText("Position-" + commandView.getCommand().indexOfParameter(this));

    //      GridLayoutFactory.swtDefaults().spacing(6, 0).numColumns(5).applyTo(parameterGroup);
    GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).applyTo(parameterGroup);

    //      Composite singleParameterComposite = toolkit.createComposite(parent);
    //      GridLayoutFactory.swtDefaults().margins(0, 0).spacing(6, 4).numColumns(5).applyTo(singleParameterComposite);
    if (parameters.size() == 0) {
        SinglePositionParameter parameter = new SinglePositionParameter(this);
        parameter.setScanVariable("sx");
        parameters.add(parameter);/* ww w  .j  a  va  2  s.c om*/
    }

    for (SinglePositionParameter parameter : parameters) {
        parameter.createParameterUI(parameterGroup, commandView, toolkit);
    }

    final AbstractScanCommand command = commandView.getCommand();

    Button addButton = toolkit.createButton(parent, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).indent(0, 10).hint(24, 24).applyTo(addButton);
    try {
        addButton.setImage(SicsBatchUIUtils.getBatchEditorImage("ADD"));
    } catch (FileNotFoundException e2) {
        LoggerFactory.getLogger(this.getClass()).error("can not find ADD image", e2);
    }
    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addNewParameter(command);
            commandView.refreshParameterComposite();
            //            notifyPropertyChanged(newCommand, null);
        }
    });

    Button removeButton = toolkit.createButton(parent, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).indent(0, 10).hint(24, 24).applyTo(removeButton);
    try {
        removeButton.setImage(SicsBatchUIUtils.getBatchEditorImage("REMOVE"));
    } catch (FileNotFoundException e1) {
        LoggerFactory.getLogger(this.getClass()).error("can not find REMOVE image", e1);
    }
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeParameter(command);
            commandView.refreshParameterComposite();
        }
    });

    DragSource dragSource = new DragSource(parameterGroup, DND.DROP_MOVE);
    final HmmscanParameter child = this;
    dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
    dragSource.addDragListener(new DragSourceAdapter() {
        @Override
        public void dragFinished(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(null);
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
                DndTransferData transferData = new DndTransferData();
                transferData.setParent(command);
                transferData.setChild(child);
                LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(transferData));
            }
        }
    });
}

From source file:au.gov.ansto.bragg.kowari.exp.command.SimpleNDParameter.java

License:Open Source License

@Override
public void createParameterUI(final Composite parent, final AbstractScanCommandView commandView,
        final FormToolkit toolkit) {
    GridLayoutFactory.swtDefaults().margins(0, 0).spacing(6, 4).numColumns(9).applyTo(parent);
    //      GridLayoutFactory.swtDefaults().numColumns(6).applyTo(parent);
    Label dragLabel = toolkit.createLabel(parent, "\u2022");
    dragLabel.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    final ComboViewer scanVariableCombo = new ComboViewer(parent, SWT.READ_ONLY);
    scanVariableCombo.setContentProvider(new ArrayContentProvider());
    scanVariableCombo.setLabelProvider(new LabelProvider());
    scanVariableCombo.setSorter(new ViewerSorter());
    scanVariableCombo.setInput(SicsBatchUIUtils.getSicsDrivableIds());
    GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).hint(WIDTH_COMBO, SWT.DEFAULT)
            .applyTo(scanVariableCombo.getCombo());
    //      GridDataFactory.fillDefaults().grab(true, false).applyTo(scanVariableCombo.getCombo());
    //      GridDataFactory.swtDefaults().hint(WIDTH_COMBO, SWT.DEFAULT).applyTo(scanVariableCombo.getCombo());
    addSelectionValidator(scanVariableCombo.getCombo(), ParameterValidator.notEmptyValidator);

    final Text startPositionText = toolkit.createText(parent, "");
    //      GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(WIDTH_PARAMETER, SWT.DEFAULT).applyTo(startPositionText);
    //      GridData data = new GridData();
    //      data.grabExcessHorizontalSpace = true;
    //      data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
    //      data.heightHint = SWT.DEFAULT;
    //      startPositionText.setLayoutData(data);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT)
            .applyTo(startPositionText);
    addValidator(startPositionText, ParameterValidator.floatValidator);

    final Text finishPositionText = toolkit.createText(parent, "");
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT)
            .applyTo(finishPositionText);
    addValidator(finishPositionText, ParameterValidator.floatValidator);

    final Text stepSizeBox = toolkit.createText(parent, "");
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT)
            .applyTo(stepSizeBox);//from  w ww. j  av  a2  s .  c om
    addValidator(stepSizeBox, ParameterValidator.floatValidator);

    final Text nostepsText = toolkit.createText(parent, "");
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT)
            .applyTo(nostepsText);
    addValidator(nostepsText, ParameterValidator.integerValidator);

    final Button multiFileButton = toolkit.createButton(parent, "multiple_files", SWT.RADIO);
    GridDataFactory.swtDefaults().hint(80, SWT.DEFAULT).applyTo(multiFileButton);

    multiFileButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            firePropertyChange("multiple files", null, true);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });

    startPositionText.addKeyListener(new KeyListener() {
        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.keyCode == SWT.KEYPAD_CR || arg0.keyCode == SWT.CR)
                finishPositionText.setFocus();
        }
    });

    finishPositionText.addKeyListener(new KeyListener() {
        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.keyCode == SWT.KEYPAD_CR || arg0.keyCode == SWT.CR)
                stepSizeBox.setFocus();
        }
    });

    stepSizeBox.addKeyListener(new KeyListener() {
        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.keyCode == SWT.KEYPAD_CR || arg0.keyCode == SWT.CR) {
                nostepsText.setFocus();
            }
        }
    });

    nostepsText.addKeyListener(new KeyListener() {
        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.keyCode == SWT.KEYPAD_CR || arg0.keyCode == SWT.CR) {
                parent.setFocus();
                nostepsText.setFocus();
            }
        }
    });

    Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), new Runnable() {
        public void run() {
            DataBindingContext bindingContext = new DataBindingContext();
            bindingContext.bindValue(ViewersObservables.observeSingleSelection(scanVariableCombo),
                    BeansObservables.observeValue(getInstance(), "scanVariable"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
            bindingContext.bindValue(SWTObservables.observeText(startPositionText, SWT.FocusOut),
                    BeansObservables.observeValue(getInstance(), "startPosition"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
            bindingContext.bindValue(SWTObservables.observeText(finishPositionText, SWT.FocusOut),
                    BeansObservables.observeValue(getInstance(), "finishPosition"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
            bindingContext.bindValue(SWTObservables.observeText(stepSizeBox, SWT.FocusOut),
                    BeansObservables.observeValue(getInstance(), "stepSize"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
            bindingContext.bindValue(SWTObservables.observeText(nostepsText, SWT.FocusOut),
                    BeansObservables.observeValue(getInstance(), "numberOfPoints"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
            bindingContext.bindValue(SWTObservables.observeSelection(multiFileButton),
                    BeansObservables.observeValue(getInstance(), "doCreateFile"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
        }
    });

    final AbstractScanCommand command = commandView.getCommand();

    final Button addButton = toolkit.createButton(parent, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(18, 18).applyTo(addButton);
    try {
        addButton.setImage(SicsBatchUIUtils.getBatchEditorImage("ADD"));
    } catch (FileNotFoundException e2) {
        LoggerFactory.getLogger(this.getClass()).error("can not find ADD image", e2);
    }
    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addNewParameter(command);
            commandView.refreshParameterComposite();
            //            notifyPropertyChanged(newCommand, null);
        }
    });

    final Button removeButton = toolkit.createButton(parent, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(18, 18).applyTo(removeButton);
    try {
        removeButton.setImage(SicsBatchUIUtils.getBatchEditorImage("REMOVE"));
    } catch (FileNotFoundException e1) {
        LoggerFactory.getLogger(this.getClass()).error("can not find REMOVE image", e1);
    }
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeParameter(command);
            commandView.refreshParameterComposite();
        }
    });

    //      initDnD(command, this);
    //   }
    //
    //   private void initDnD(final AbstractScanCommand command, final AbstractScanParameter parameter) {
    int operations = DND.DROP_MOVE;
    DragSource dragSource = new DragSource(dragLabel, operations);

    LocalSelectionTransfer transferObject = LocalSelectionTransfer.getTransfer();

    Transfer[] types = new Transfer[] { transferObject };
    dragSource.setTransfer(types);
    final SimpleNDParameter child = this;
    dragSource.addDragListener(new DragSourceAdapter() {

        @Override
        public void dragFinished(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(null);
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
                DndTransferData transferData = new DndTransferData();
                transferData.setParent(command);
                transferData.setChild(child);
                LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(transferData));
            }
        }
    });

}

From source file:au.gov.ansto.bragg.kowari.exp.command.SingleADParameter.java

License:Open Source License

@Override
public void createParameterUI(Composite parent, final AbstractScanCommandView commandView,
        final FormToolkit toolkit) {
    GridLayoutFactory.swtDefaults().margins(0, 0).spacing(6, 4).numColumns(7).applyTo(parent);
    //      GridLayoutFactory.swtDefaults().numColumns(6).applyTo(parent);
    final Label dragLabel = toolkit.createLabel(parent, "\u2022");
    dragLabel.setCursor(parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
    final ComboViewer scanVariableCombo = new ComboViewer(parent, SWT.READ_ONLY);
    scanVariableCombo.setContentProvider(new ArrayContentProvider());
    scanVariableCombo.setLabelProvider(new LabelProvider());
    scanVariableCombo.setSorter(new ViewerSorter());
    scanVariableCombo.setInput(SicsBatchUIUtils.getSicsDrivableIds());
    GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).hint(WIDTH_COMBO, SWT.DEFAULT)
            .applyTo(scanVariableCombo.getCombo());
    addSelectionValidator(scanVariableCombo.getCombo(), ParameterValidator.notEmptyValidator);
    //      GridDataFactory.fillDefaults().grab(true, false).applyTo(scanVariableCombo.getCombo());

    //      GridDataFactory.swtDefaults().hint(WIDTH_COMBO, SWT.DEFAULT).applyTo(scanVariableCombo.getCombo());

    final Text startPositionText = toolkit.createText(parent, "");
    //      GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(WIDTH_PARAMETER, SWT.DEFAULT).applyTo(startPositionText);
    //      GridData data = new GridData();
    //      data.grabExcessHorizontalSpace = true;
    //      data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
    //      data.heightHint = SWT.DEFAULT;
    //      startPositionText.setLayoutData(data);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT)
            .applyTo(startPositionText);
    addValidator(startPositionText, ParameterValidator.floatValidator);

    final Text finishPositionText = toolkit.createText(parent, "");
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT)
            .applyTo(finishPositionText);
    addValidator(finishPositionText, ParameterValidator.floatValidator);

    final Text stepSizeText = toolkit.createText(parent, "");
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT)
            .applyTo(stepSizeText);/*from  w  ww .j  av a2s .  c om*/
    addValidator(stepSizeText, ParameterValidator.floatValidator);

    Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), new Runnable() {
        public void run() {
            DataBindingContext bindingContext = new DataBindingContext();
            bindingContext.bindValue(ViewersObservables.observeSingleSelection(scanVariableCombo),
                    BeansObservables.observeValue(getInstance(), "scanVariable"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
            bindingContext.bindValue(SWTObservables.observeText(startPositionText, SWT.Modify),
                    BeansObservables.observeValue(getInstance(), "startPosition"), new UpdateValueStrategy() {

                        /* (non-Javadoc)
                         * @see org.eclipse.core.databinding.UpdateValueStrategy#convert(java.lang.Object)
                         */
                        @Override
                        public Object convert(Object value) {
                            if ("*".equals(String.valueOf(value)))
                                return Float.NaN;
                            else
                                return super.convert(value);
                        }

                        @Override
                        public IStatus validateAfterGet(Object value) {
                            if ("*".equals(value)) {
                                return Status.OK_STATUS;
                            }
                            return super.validateAfterGet(value);
                        }

                    }, new UpdateValueStrategy() {

                        /* (non-Javadoc)
                         * @see org.eclipse.core.databinding.UpdateValueStrategy#convert(java.lang.Object)
                         */
                        @Override
                        public Object convert(Object value) {
                            if (value instanceof Float)
                                if (Float.isNaN((Float) value))
                                    return "*";
                                else
                                    super.convert(value);
                            return super.convert(value);
                        }

                        @Override
                        public IStatus validateAfterGet(Object value) {
                            if ("*".equals(value)) {
                                return Status.OK_STATUS;
                            }
                            return super.validateAfterGet(value);
                        }

                    });
            bindingContext.bindValue(SWTObservables.observeText(finishPositionText, SWT.Modify),
                    BeansObservables.observeValue(getInstance(), "finishPosition"), new UpdateValueStrategy() {

                        /* (non-Javadoc)
                         * @see org.eclipse.core.databinding.UpdateValueStrategy#convert(java.lang.Object)
                         */
                        @Override
                        public Object convert(Object value) {
                            if ("*".equals(String.valueOf(value)))
                                return Float.NaN;
                            else
                                return super.convert(value);
                        }

                    }, new UpdateValueStrategy() {

                        /* (non-Javadoc)
                         * @see org.eclipse.core.databinding.UpdateValueStrategy#convert(java.lang.Object)
                         */
                        @Override
                        public Object convert(Object value) {
                            if (value instanceof Float)
                                if (Float.isNaN((Float) value))
                                    return "*";
                                else
                                    super.convert(value);
                            return super.convert(value);
                        }
                    });
            bindingContext.bindValue(SWTObservables.observeText(stepSizeText, SWT.Modify),
                    BeansObservables.observeValue(getInstance(), "stepSize"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
        }
    });

    final AbstractScanCommand command = commandView.getCommand();

    Button addButton = toolkit.createButton(parent, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(18, 18).applyTo(addButton);
    try {
        addButton.setImage(SicsBatchUIUtils.getBatchEditorImage("ADD"));
    } catch (FileNotFoundException e2) {
        LoggerFactory.getLogger(this.getClass()).error("can not find ADD image", e2);
    }
    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addNewParameter(command);
            commandView.refreshParameterComposite();
            //            notifyPropertyChanged(newCommand, null);
        }
    });

    Button removeButton = toolkit.createButton(parent, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).hint(18, 18).applyTo(removeButton);
    try {
        removeButton.setImage(SicsBatchUIUtils.getBatchEditorImage("REMOVE"));
    } catch (FileNotFoundException e1) {
        LoggerFactory.getLogger(this.getClass()).error("can not find REMOVE image", e1);
    }
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeParameter(command);
            commandView.refreshParameterComposite();
        }
    });

    DragSource dragSource = new DragSource(dragLabel, DND.DROP_MOVE);
    dragSource.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() });
    final SingleADParameter child = this;
    dragSource.addDragListener(new DragSourceAdapter() {
        @Override
        public void dragFinished(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(null);
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
                DndTransferData transferData = new DndTransferData();
                transferData.setParent(parentParameter);
                transferData.setChild(child);
                LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(transferData));
            }
        }
    });
}

From source file:au.gov.ansto.bragg.nbi.ui.core.commands.TableScanParameter.java

License:Open Source License

@Override
public void createParameterUI(final Composite parameterComposite, final AbstractScanCommandView commandView,
        final FormToolkit toolkit) {
    //         final Label dragLabel = toolkit.createLabel(parent, "\u2022");
    //      parameterComposite = toolkit.createComposite(parent);
    //      parameterComposite = new Composite(parent, SWT.NONE);
    final Label dragLabel = toolkit.createLabel(parameterComposite, "\u2022");
    dragLabel.setCursor(parameterComposite.getDisplay().getSystemCursor(SWT.CURSOR_HAND));

    final Button selectBox = toolkit.createButton(parameterComposite, "", SWT.CHECK);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).indent(0, 2).applyTo(selectBox);

    selectBox.addSelectionListener(new SelectionListener() {

        @Override/*www  .ja v  a 2  s .  c om*/
        public void widgetSelected(SelectionEvent e) {
            Control[] children = parameterComposite.getChildren();
            for (Control child : children) {
                if (child instanceof Text) {
                    child.setEnabled(selectBox.getSelection());
                }
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    for (int i = 0; i < getLength(); i++) {
        final String name = "p" + i;
        final Text pText = toolkit.createText(parameterComposite, "");
        GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT)
                .applyTo(pText);
        addValidator(pText, ParameterValidator.floatValidator);
        Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), new Runnable() {
            public void run() {
                DataBindingContext bindingContext = new DataBindingContext();
                bindingContext.bindValue(SWTObservables.observeText(pText, SWT.Modify),
                        BeansObservables.observeValue(getInstance(), name), new UpdateValueStrategy(),
                        new UpdateValueStrategy());
            }
        });
    }

    final Text presetText = toolkit.createText(parameterComposite, "");
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.CENTER).hint(WIDTH_PARAMETER_LONG, SWT.DEFAULT)
            .applyTo(presetText);
    addValidator(presetText, ParameterValidator.floatValidator);

    Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), new Runnable() {
        public void run() {
            DataBindingContext bindingContext = new DataBindingContext();
            bindingContext.bindValue(SWTObservables.observeSelection(selectBox),
                    BeansObservables.observeValue(getInstance(), "isSelected"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
            bindingContext.bindValue(SWTObservables.observeText(presetText, SWT.Modify),
                    BeansObservables.observeValue(getInstance(), "preset"), new UpdateValueStrategy(),
                    new UpdateValueStrategy());
        }
    });

    Button addButton = toolkit.createButton(parameterComposite, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).indent(0, 0).applyTo(addButton);
    try {
        addButton.setImage(SicsBatchUIUtils.getBatchEditorImage("ADD"));
    } catch (FileNotFoundException e2) {
        LoggerFactory.getLogger(this.getClass()).error("can not find ADD image", e2);
    }
    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addNewParameter(command);
            commandView.refreshParameterComposite();
            //            notifyPropertyChanged(newCommand, null);
        }
    });

    Button removeButton = toolkit.createButton(parameterComposite, "", SWT.PUSH);
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.TOP).indent(0, 0).applyTo(removeButton);
    try {
        removeButton.setImage(SicsBatchUIUtils.getBatchEditorImage("REMOVE"));
    } catch (FileNotFoundException e1) {
        LoggerFactory.getLogger(this.getClass()).error("can not find REMOVE image", e1);
    }
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeParameter(command);
            commandView.refreshParameterComposite();
        }
    });

    DragSource dragSource = new DragSource(dragLabel, DND.DROP_MOVE);

    LocalSelectionTransfer transferObject = LocalSelectionTransfer.getTransfer();

    Transfer[] types = new Transfer[] { transferObject };
    dragSource.setTransfer(types);
    final TableScanParameter child = this;
    dragSource.addDragListener(new DragSourceAdapter() {

        @Override
        public void dragFinished(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(null);
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
                DndTransferData transferData = new DndTransferData();
                transferData.setParent(command);
                transferData.setChild(child);
                LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(transferData));
            }
        }
    });

}

From source file:au.gov.ansto.bragg.nbi.ui.widgets.HMControlWidget.java

License:Open Source License

private void updateData(final Object control, final Object data) {
    SafeUIRunner.asyncExec(new SafeRunnable() {
        public void run() throws Exception {
            if (control instanceof ComboViewer) {
                // Update Mode
                ((ComboViewer) control).setSelection(new StructuredSelection(data));
            } else if (control instanceof Text) {
                // Update preset
                ((Text) control).setText(data.toString());
            } else if (control instanceof Button) {
                // Command status
                if (CommandStatus.valueOf((String) data).equals(CommandStatus.IDLE)) {
                    ((Button) control).setImage(InternalImage.START_32.getImage());
                    ((Button) control).setData("status", "idle");
                } else {
                    ((Button) control).setImage(InternalImage.STOP_32.getImage());
                    ((Button) control).setData("status", "running");
                }/*www .  j  a  v a2s .c o  m*/
            }
        }
    });
}

From source file:au.gov.ansto.bragg.nbi.ui.widgets.HMImageDisplayWidget.java

License:Open Source License

protected Composite createImageArea() {
    GridLayoutFactory.swtDefaults().numColumns(9).margins(0, 0).applyTo(this);

    // Mode/*  w w w.  j  a v a  2  s  .c o m*/
    Label label = getToolkit().createLabel(this, "Mode: ");
    label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).grab(true, false).applyTo(label);
    comboViewer = new ComboViewer(this, SWT.READ_ONLY);
    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setLabelProvider(new LabelProvider());
    comboViewer.setInput(getImageMode().getValues());
    comboViewer.setSelection(new StructuredSelection(getImageMode()));
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            // Change display mode
            setImageMode((HMImageMode) ((IStructuredSelection) event.getSelection()).getFirstElement());
            // Update NOW
            Job job = new Job(HMImageDisplayWidget.class.getName()) {
                protected IStatus run(IProgressMonitor monitor) {
                    try {
                        // Get data (one off)
                        pullData();
                    } catch (Exception e) {
                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to fetch data.", e);
                    }
                    return Status.OK_STATUS;
                }
            };
            job.setSystem(true);
            job.schedule();
        }
    });

    // Separator
    label = getToolkit().createLabel(this, "");
    GridDataFactory.swtDefaults().hint(8, SWT.DEFAULT).applyTo(label);

    Label scaleLabel = getToolkit().createLabel(this, "Scale: ");
    scaleLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).grab(true, false).applyTo(scaleLabel);
    ComboViewer scaleViewer = new ComboViewer(this, SWT.READ_ONLY);
    scaleViewer.setContentProvider(new ArrayContentProvider());
    scaleViewer.setLabelProvider(new LabelProvider());
    scaleViewer.setInput(SCALE_INPUT);
    isScaleEnabled = true;
    try {
        isScaleEnabled = Boolean.valueOf(System.getProperty(IS_SCALE_ENABLED));
    } catch (Exception e) {
    }
    scaleViewer.setSelection(new StructuredSelection(SCALE_INPUT[isScaleEnabled ? 0 : 1]));
    scaleViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            // Change display mode
            setScaleEnabled(
                    SCALE_INPUT[0].equals(((IStructuredSelection) event.getSelection()).getFirstElement()));
            // Update NOW
            Job job = new Job(HMImageDisplayWidget.class.getName()) {
                protected IStatus run(IProgressMonitor monitor) {
                    try {
                        // Get data (one off)
                        pullData();
                    } catch (Exception e) {
                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to fetch data.", e);
                    }
                    return Status.OK_STATUS;
                }
            };
            job.setSystem(true);
            job.schedule();
        }
    });

    label = getToolkit().createLabel(this, "");
    GridDataFactory.swtDefaults().hint(8, SWT.DEFAULT).applyTo(label);

    // Refresh
    label = getToolkit().createLabel(this, "Refresh: ");
    label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    final Text refreshText = getToolkit().createText(this, "");
    Realm.runWithDefault(SWTObservables.getRealm(Display.getDefault()), new Runnable() {
        public void run() {
            DataBindingContext bindingContext = new DataBindingContext();
            bindingContext.bindValue(SWTObservables.observeText(refreshText, SWT.Modify),
                    BeansObservables.observeValue(HMImageDisplayWidget.this, "refreshDelay"),
                    new UpdateValueStrategy(), new UpdateValueStrategy());
        }
    });
    GridDataFactory.swtDefaults().hint(20, SWT.DEFAULT).applyTo(refreshText);
    label = getToolkit().createLabel(this, "sec ");
    label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));

    Composite imageArea = getToolkit().createComposite(this, SWT.NONE);
    GridLayoutFactory.fillDefaults().margins(0, 0).spacing(0, 0).applyTo(imageArea);
    GridDataFactory.fillDefaults().grab(true, true).span(9, 1).applyTo(imageArea);

    return imageArea;
}

From source file:au.gov.ga.earthsci.bookmark.part.BookmarksPart.java

License:Apache License

/**
 * Highlight the given bookmark in the part
 * /*from w w  w .ja  v  a 2s .c om*/
 * @param bookmark The bookmark to highlight. If <code>null</code>, clears any highlighting
 */
public void highlight(final IBookmark bookmark) {
    Display.getDefault().asyncExec(new Runnable() {
        @Override
        public void run() {
            bookmarkListTableViewer.setSelection(bookmark == null ? null : new StructuredSelection(bookmark));
        }
    });
}

From source file:au.gov.ga.earthsci.bookmark.part.BookmarksPart.java

License:Apache License

public void refreshDropdown() {
    Display.getDefault().asyncExec(new Runnable() {
        @Override/*from   w  w  w.j  ava 2 s.c  om*/
        public void run() {
            if (controller.getCurrentList() == getSelectedBookmarkList()) {
                return;
            }
            bookmarkListsComboViewer.setSelection(new StructuredSelection(controller.getCurrentList()), true);
        }
    });
}

From source file:au.gov.ga.earthsci.bookmark.part.BookmarksPart.java

License:Apache License

private void initCombo(Composite parent) {
    bookmarkListsComboViewer = new ComboViewer(parent, SWT.READ_ONLY | SWT.DROP_DOWN);

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;/*from   w  ww  .j  a  v a  2  s  .  c om*/
    bookmarkListsComboViewer.getCombo().setLayoutData(gd);

    bookmarkListsComboViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            if (!(element instanceof IBookmarkList)) {
                return super.getText(element);
            }
            return ((IBookmarkList) element).getName();
        }
    });

    // Trigger a label refresh if a list name changes etc.
    ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    IObservableMap nameMap = BeanProperties.value("name").observeDetail(contentProvider.getKnownElements()); //$NON-NLS-1$
    nameMap.addMapChangeListener(new IMapChangeListener() {
        @Override
        public void handleMapChange(MapChangeEvent event) {
            for (Object key : event.diff.getChangedKeys()) {
                bookmarkListsComboViewer.refresh(key, true);
            }
        }
    });

    bookmarkListsComboViewer.setContentProvider(contentProvider);
    bookmarkListsComboViewer.setInput(BeanProperties.list("lists").observe(bookmarks)); //$NON-NLS-1$
    bookmarkListsComboViewer.setSelection(new StructuredSelection(bookmarks.getDefaultList()));

    bookmarkListsComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            controller.setCurrentList(getSelectedBookmarkList());
        }
    });
}