List of usage examples for org.eclipse.jface.layout GridLayoutFactory swtDefaults
public static GridLayoutFactory swtDefaults()
From source file:au.gov.ansto.bragg.echidna.ui.preference.DRAPreferencePage.java
License:Open Source License
@Override public void createControl(Composite parent) { // TODO Auto-generated method stub super.createControl(parent); GridLayoutFactory.swtDefaults().numColumns(3).applyTo(getFieldEditorParent()); }
From source file:au.gov.ansto.bragg.echidna.ui.preference.EchidnaGlobalPreferencePage.java
License:Open Source License
@Override public void createControl(Composite parent) { // TODO Auto-generated method stub super.createControl(parent); GridLayoutFactory.swtDefaults().numColumns(3).applyTo(getFieldEditorParent()); Label newProfileLabel = new Label(getFieldEditorParent(), SWT.NONE); newProfileLabel.setText("Configurations for Echidna instrument"); GridDataFactory.fillDefaults().span(3, 1).grab(true, false).applyTo(newProfileLabel); }
From source file:au.gov.ansto.bragg.echidna.ui.views.ExperimentTaskViewer.java
License:Open Source License
@Override protected void createViewerControl(final Composite parent) { super.createViewerControl(parent); int itemCount = tabFolder.getItemCount(); if (itemCount == 2) { tabFolder.getItem(1).dispose();//from www . ja v a2 s.com tabFolder.setSingle(true); } addBlockButton.dispose(); Composite estimatedTimeComposite = getToolkit().createComposite(designArea, SWT.NONE); GridLayoutFactory.swtDefaults().margins(1, 0).numColumns(4).applyTo(estimatedTimeComposite); getToolkit().createLabel(estimatedTimeComposite, "Estimated Time: "); estimatedTime = getToolkit().createText(estimatedTimeComposite, ""); // estimatedTime.; GridDataFactory.fillDefaults().grab(true, false).applyTo(estimatedTime); estimatedTime.setEditable(false); estimatedTime.setText(String.valueOf(getEstimatedTime())); getToolkit().createLabel(estimatedTimeComposite, "Hour(s)"); estimatedTimeComposite.moveAbove(saveButton); addToQueueButton = getToolkit().createButton(estimatedTimeComposite, "Add to Queue", SWT.PUSH); addToQueueButton.setImage( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/add_to_queue.gif").createImage()); addToQueueButton.setToolTipText("Put tasks into run queue."); addToQueueButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { // Ensure the current workflow is valid if (getWorkflow() == null) { return; } ISicsBatchScript batchScript = getWorkflow().getContext().getSingleValue(ISicsBatchScript.class); if (batchScript == null) { return; } // Ask for buffer name input // InputDialog dialog = new InputDialog(parent.getShell(), // "New Batch Buffer", "Enter new batch buffer name:", // "Batch", new IInputValidator() { // public String isValid(String newText) { // if (newText == null || newText.length() == 0) { // return "Buffer name is empty"; // } // return null; // } // }); // if (dialog.open() == Window.CANCEL) { // return; // } // Create a unique batch name String batchName = "batch"; String extension = getBatchDateString(); batchName += extension; // Add to the queue IBatchBufferManager manager = ServiceUtils.getService(IBatchBufferManager.class); // IBatchBuffer buffer = new VisualBatchBuffer(dialog.getValue(), getWorkflow()); IBatchBuffer buffer = new VisualBatchBuffer(batchName, getWorkflow()); manager.getBatchBufferQueue().add(buffer); batchName = "EXP" + extension + ".wml"; saveTempWorkflow(batchName); // Clean the viewer by swapping to a new workflow // getWorkflowViewer().setWorkflow(WorkflowFactory.createEmptyWorkflow()); } }); GridDataFactory.fillDefaults().grab(true, false).applyTo(estimatedTimeComposite); GridDataFactory.fillDefaults().grab(true, false).applyTo(saveButton); GridDataFactory.fillDefaults().grab(true, false).applyTo(loadButton); GridDataFactory.fillDefaults().grab(true, false).applyTo(addToQueueButton); }
From source file:au.gov.ansto.bragg.echidna.ui.views.ExperimentTaskViewer.java
License:Open Source License
@Override protected void createCommandBlocksArea(Composite parent) { for (Control child : parent.getChildren()) { child.dispose();/*from www .ja va 2 s . co m*/ } for (ITaskView taskView : getTaskViews()) { destoryTaskView(taskView); } getTaskViews().clear(); GridLayoutFactory.swtDefaults().margins(1, 1).applyTo(parent); for (final ITask task : getWorkflow().getTasks()) { if (task instanceof HeaderInformationBlockTask) { final MenuBasedGroup group = new MenuBasedGroup(parent, SWT.SMOOTH); group.setClickExpandEnabled(true); group.setLayout(new FillLayout()); getToolkit().adapt(group); GridDataFactory.fillDefaults().grab(true, false).applyTo(group); // Header display // final ISicsCommandBlock commandBlock = ((CommandBlockTask) task).getDataModel(); // if (commandBlock.getName() != null) { group.setText("Header Information"); // } createTaskView(group, task); } if (task instanceof SicsScriptBlockTask) { final MenuBasedGroup group = new MenuBasedGroup(parent, SWT.SMOOTH); group.setClickExpandEnabled(true); group.setLayout(new FillLayout()); getToolkit().adapt(group); GridDataFactory.fillDefaults().grab(true, false).applyTo(group); // Header display // final ISicsCommandBlock commandBlock = ((CommandBlockTask) task).getDataModel(); // if (commandBlock.getName() != null) { group.setText(SicsScriptBlockTask.TITLE); // } createTaskView(group, task); // ((SicsBlockTask) task).addPropertyChangeListener(new ITaskPropertyChangeListener() { // // @Override // public void propertyChanged(ISicsCommandElement command, // PropertyChangeEvent event) { // group.setText(((SicsBlockTask) task).getTitle()); // } // }); } if (task instanceof AbstractEchidnaScanTask) { final MenuBasedGroup group = new MenuBasedGroup(parent, SWT.SMOOTH); group.setClickExpandEnabled(true); group.setLayout(new FillLayout()); getToolkit().adapt(group); GridDataFactory.fillDefaults().grab(true, false).applyTo(group); // Header display // final ISicsCommandBlock commandBlock = ((CommandBlockTask) task).getDataModel(); // if (commandBlock.getName() != null) { group.setText(((AbstractEchidnaScanTask) task).getTitle()); // } Menu menu = group.getMenu(); addManuItems(group, menu, (AbstractEchidnaScanTask) task); createTaskView(group, task); ((AbstractEchidnaScanTask) task).addPropertyChangeListener(new ITaskPropertyChangeListener() { public void propertyChanged(ISicsCommandElement command, PropertyChangeEvent event) { if (estimatedTime != null && !estimatedTime.isDisposed()) estimatedTime .setText(String.valueOf(((AbstractEchidnaScanTask) task).getEstimatedTime())); } }); if (estimatedTime != null && !estimatedTime.isDisposed()) estimatedTime.setText(String.valueOf(((AbstractEchidnaScanTask) task).getEstimatedTime())); } } }
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);/* ww w. j av a 2s.co m*/ 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 w w .j a v a 2 s . c o m 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.kowari.exp.command.SinglePositionParameter.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(4).applyTo(parent); // GridLayoutFactory.swtDefaults().numColumns(6).applyTo(parent); 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()); final Text positionText = 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(positionText);//from www . j a v a2 s . co m addValidator(positionText, 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(positionText, SWT.Modify), BeansObservables.observeValue(getInstance(), "position"), 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(); } }); }
From source file:au.gov.ansto.bragg.kowari.exp.commandView.AdvancedScanCommandView.java
License:Open Source License
@Override protected void createPartControl(Composite parent, final AbstractScanCommand command) { super.createPartControl(parent, command); GridLayoutFactory.swtDefaults().numColumns(3).applyTo(parent); // Label titleLabel = getToolkit().createLabel(parent, command.getCommandName()); // titleLabel.setFont(new Font(titleLabel.getFont().getDevice(), new FontData[]{new FontData("Courier New", 10, SWT.BOLD)})); // GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).indent(0, 12).applyTo(titleLabel); // GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.TOP).applyTo(titleLabel); parameterComposite = getToolkit().createComposite(parent); GridLayoutFactory.swtDefaults().margins(0, 0).numColumns(5).applyTo(parameterComposite); GridDataFactory.swtDefaults().indent(2, 0).align(SWT.BEGINNING, SWT.TOP).applyTo(parameterComposite); if (command.getParameterList().size() == 0) { AdvancedParameter parameter = new AdvancedParameter(); // parameter.setScanVariable("sx"); command.insertParameter(parameter); }//from ww w . j av a2 s.c o m // GridLayoutFactory.swtDefaults().spacing(3, 3).applyTo(parameterComposite); for (AbstractScanParameter parameter : command.getParameterList()) { parameter.createParameterUI(parameterComposite, this, getToolkit()); } final ComboViewer modeCombo = new ComboViewer(parent, SWT.READ_ONLY); modeCombo.setContentProvider(new ArrayContentProvider()); modeCombo.setLabelProvider(new LabelProvider()); modeCombo.setSorter(new ViewerSorter()); modeCombo.setInput(new String[] { "time", "count" }); GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).indent(0, 10) .hint(AbstractScanParameter.WIDTH_PARAMETER_SHORT, SWT.DEFAULT).applyTo(modeCombo.getCombo()); final Text presetText = getToolkit().createText(parent, ""); // GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(presetText); // GridDataFactory.fillDefaults().grab(true, false).applyTo(presetText); GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).indent(0, 10) .hint(AbstractScanParameter.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(ViewersObservables.observeSingleSelection(modeCombo), BeansObservables.observeValue(command, "scan_mode"), new UpdateValueStrategy(), new UpdateValueStrategy()); bindingContext.bindValue(SWTObservables.observeText(presetText, SWT.Modify), BeansObservables.observeValue(command, "preset"), new UpdateValueStrategy(), new UpdateValueStrategy()); } }); // DropTarget dropTarget = new DropTarget(parameterComposite, DND.DROP_MOVE); // dropTarget.setTransfer(new Transfer[]{LocalSelectionTransfer.getTransfer()}); // dropTarget.addDropListener(new DropTargetAdapter(){ // @Override // public void drop(DropTargetEvent event) { // if (event.data instanceof IStructuredSelection) { // DndTransferData transferData = (DndTransferData) ( // (StructuredSelection) event.data).getFirstElement(); // Object parent = transferData.getParent(); // Object child = transferData.getChild(); // if (parent == command){ // Point relativePoint = parameterComposite.toControl( // new Point(event.x, event.y)); // int index = 0; // for (Control control : parameterComposite.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); // refreshParameterComposite(); // } // } // } // } // }); }
From source file:au.gov.ansto.bragg.kowari.exp.commandView.HmmscanCommandView.java
License:Open Source License
@Override protected void createPartControl(Composite parent, final AbstractScanCommand command) { super.createPartControl(parent, command); GridLayoutFactory.swtDefaults().numColumns(3).applyTo(parent); // Label titleLabel = getToolkit().createLabel(parent, command.getCommandName()); // titleLabel.setFont(new Font(titleLabel.getFont().getDevice(), new FontData[]{new FontData("Courier New", 10, SWT.BOLD)})); // GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).indent(0, 12).applyTo(titleLabel); // GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.TOP).applyTo(titleLabel); parameterComposite = getToolkit().createComposite(parent); GridLayoutFactory.swtDefaults().margins(0, 0).numColumns(3).applyTo(parameterComposite); GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).applyTo(parameterComposite); if (command.getParameterList().size() == 0) { HmmscanParameter parameter = new HmmscanParameter(); // parameter.setScanVariable("sx"); command.insertParameter(parameter); }/*from www .j ava 2 s .c o m*/ // GridLayoutFactory.swtDefaults().spacing(3, 3).applyTo(parameterComposite); for (AbstractScanParameter parameter : command.getParameterList()) { parameter.createParameterUI(parameterComposite, this, getToolkit()); } final ComboViewer modeCombo = new ComboViewer(parent, SWT.READ_ONLY); modeCombo.setContentProvider(new ArrayContentProvider()); modeCombo.setLabelProvider(new LabelProvider()); modeCombo.setSorter(new ViewerSorter()); modeCombo.setInput(new String[] { "time", "count" }); GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).indent(0, 12) .hint(AbstractScanParameter.WIDTH_PARAMETER_SHORT, SWT.DEFAULT).applyTo(modeCombo.getCombo()); final Text presetText = getToolkit().createText(parent, ""); // GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(presetText); // GridDataFactory.fillDefaults().grab(true, false).applyTo(presetText); GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).indent(0, 12) .hint(AbstractScanParameter.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(ViewersObservables.observeSingleSelection(modeCombo), BeansObservables.observeValue(command, "scan_mode"), new UpdateValueStrategy(), new UpdateValueStrategy()); bindingContext.bindValue(SWTObservables.observeText(presetText, SWT.Modify), BeansObservables.observeValue(command, "preset"), new UpdateValueStrategy(), new UpdateValueStrategy()); } }); DropTarget dropTarget = new DropTarget(parameterComposite, DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { LocalSelectionTransfer.getTransfer() }); dropTarget.addDropListener(new DropTargetAdapter() { @Override public void drop(DropTargetEvent event) { if (event.data instanceof StructuredSelection) { Object elementData = ((StructuredSelection) event.data).getFirstElement(); if (elementData instanceof DndTransferData) { DndTransferData transferData = (DndTransferData) elementData; Object parentData = transferData.getParent(); Object childData = transferData.getChild(); if (parentData == command) { Point relativePoint = parameterComposite.toControl(new Point(event.x, event.y)); int index = 0; for (Control control : parameterComposite.getChildren()) { if (control instanceof Group) { if (relativePoint.y < control.getBounds().y + control.getBounds().height) { break; } index++; } } if (childData instanceof HmmscanParameter) { HmmscanParameter parameter = (HmmscanParameter) childData; int currentIndex = command.indexOfParameter(parameter); if (currentIndex == index) { return; } command.removeParameter(parameter); command.insertParameter(index, parameter); refreshParameterComposite(); } } } } } }); }
From source file:au.gov.ansto.bragg.kowari.exp.commandView.ScanNDCommandView.java
License:Open Source License
@Override protected void createPartControl(Composite parent, final AbstractScanCommand command) { super.createPartControl(parent, command); GridLayoutFactory.swtDefaults().margins(6, 8).numColumns(3).applyTo(parent); // Label titleLabel = getToolkit().createLabel(parent, command.getCommandName()); // titleLabel.setFont(new Font(titleLabel.getFont().getDevice(), new FontData[]{new FontData("Courier New", 10, SWT.BOLD)})); // GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP).indent(0, 4).applyTo(titleLabel); // GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.TOP).applyTo(titleLabel); parameterComposite = getToolkit().createComposite(parent); // GridLayoutFactory.swtDefaults().spacing(3, 3).applyTo(parameterComposite); for (AbstractScanParameter parameter : command.getParameterList()) { parameter.createParameterUI(parameterComposite, this, getToolkit()); }/*from ww w . ja v a 2 s . c om*/ final ComboViewer modeCombo = new ComboViewer(parent, SWT.READ_ONLY); modeCombo.setContentProvider(new ArrayContentProvider()); modeCombo.setLabelProvider(new LabelProvider()); modeCombo.setSorter(new ViewerSorter()); modeCombo.setInput(new String[] { "time", "count" }); GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP) .hint(AbstractScanParameter.WIDTH_PARAMETER_SHORT, SWT.DEFAULT).applyTo(modeCombo.getCombo()); final Text presetText = getToolkit().createText(parent, ""); // GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(presetText); // GridDataFactory.fillDefaults().grab(true, false).applyTo(presetText); GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.TOP) .hint(AbstractScanParameter.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(ViewersObservables.observeSingleSelection(modeCombo), BeansObservables.observeValue(command, "scan_mode"), new UpdateValueStrategy(), new UpdateValueStrategy()); bindingContext.bindValue(SWTObservables.observeText(presetText, SWT.Modify), BeansObservables.observeValue(command, "preset"), new UpdateValueStrategy(), new UpdateValueStrategy()); } }); DropTarget dropTarget = new DropTarget(parameterComposite, DND.DROP_MOVE); 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 parent = transferData.getParent(); Object child = transferData.getChild(); if (parent == command) { Point relativePoint = parameterComposite.toControl(new Point(event.x, event.y)); int index = 0; for (Control control : parameterComposite.getChildren()) { if (control instanceof Combo) { if (relativePoint.y < (control.getBounds().y + control.getBounds().height)) { break; } index++; } } if (child instanceof AbstractScanParameter) { AbstractScanParameter parameter = (AbstractScanParameter) child; int currentIndex = command.indexOfParameter(parameter); if (currentIndex == index) { return; } command.removeParameter(parameter); command.insertParameter(index, parameter); refreshParameterComposite(); } } } } }); }