List of usage examples for org.eclipse.jface.databinding.swt SWTObservables getRealm
@Deprecated public static Realm getRealm(final Display display)
From source file:main.java.miro.browser.conf.entrypoints.MainEntryPoint.java
License:Open Source License
/** * @wbp.parser.entryPoint//from ww w .j a v a2s .c o m */ protected void createContents(Composite parent) { Realm.runWithDefault(SWTObservables.getRealm(parent.getDisplay()), new MainRunnable(parent)); }
From source file:mlm.eclipse.ide.jsworkingset.internal.ImportWizardPage.java
License:Open Source License
@Override public void createControl(final Composite pParent) { mDataBindingContext = new DataBindingContext(SWTObservables.getRealm(pParent.getDisplay())); final Composite composite = new Composite(pParent, SWT.NONE); composite.setLayout(GridLayoutFactory.fillDefaults() // .numColumns(3) // .create());/* w w w . j av a 2s .co m*/ setControl(composite); final Label label = new Label(composite, SWT.WRAP); label.setText("Script:"); final Text text = new Text(composite, SWT.BORDER | SWT.SINGLE); text.setToolTipText("Enter a workspace file."); text.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(true, false) // .create()); // TODO history or path completion for script? final Button button = new Button(composite, SWT.PUSH); button.setText("Browse..."); //$NON-NLS-1$ button.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(false, false) // .create()); button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent pEvent) { final Shell shell = button.getShell(); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final ResourceListSelectionDialog dialog = new ResourceListSelectionDialog(shell, root, IResource.FILE); dialog.setTitle("Select a JavaScript file"); if (dialog.open() == Window.OK) { final Object[] objects = dialog.getResult(); if (objects.length == 1) { final IResource resource = (IResource) objects[0]; final IPath path = resource.getFullPath(); text.setText(path.toString()); } else { text.setText(""); //$NON-NLS-1$ } } } }); // TODO table to display found working sets }
From source file:mlm.eclipse.ide.jsworkingset.internal.JSWorkingSetPage.java
License:Open Source License
@Override public void createControl(final Composite pParent) { mDataBindingContext = new DataBindingContext(SWTObservables.getRealm(pParent.getDisplay())); final Composite composite = new Composite(pParent, SWT.NONE); composite.setLayout(GridLayoutFactory.fillDefaults() // .numColumns(3) // .create());/*w w w .ja v a 2 s . c o m*/ setControl(composite); // working set label { final String workingSetLabel = mWorkingSet != null ? mWorkingSet.getLabel() : ""; //$NON-NLS-1$ mWorkingSetLabel = WritableValue.withValueType(String.class); mWorkingSetLabel.setValue(workingSetLabel); final Label label = new Label(composite, SWT.WRAP); label.setText("Label:"); final Text text = new Text(composite, SWT.BORDER | SWT.SINGLE); text.setToolTipText("The label for the working set."); text.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(true, false) // .span(2, 1) // .create()); final IValidator validator = (v) -> { final String value = (String) v; if (value == null || value.trim().isEmpty()) { return ValidationStatus.ok(); } return ValidationStatus.info("This may likely be overridden by the script."); }; final UpdateValueStrategy targetToModel = new UpdateValueStrategy() // .setAfterConvertValidator(validator) // ; final ISWTObservableValue target = WidgetProperties.text(SWT.Modify) // .observe(text) // ; final Binding binding = mDataBindingContext.bindValue(target, mWorkingSetLabel, targetToModel, null); binding.getValidationStatus().setValue(ValidationStatus.ok()); ControlDecorationSupport.create(binding, SWT.LEFT | SWT.TOP); } // working set name { final String workingSetName = JSWorkingSetPrefs.getName(mWorkingSet); mWorkingSetName = WritableValue.withValueType(String.class); mWorkingSetName.setValue(workingSetName); final Label label = new Label(composite, SWT.WRAP); label.setText("Name:"); final Text text = new Text(composite, SWT.BORDER | SWT.SINGLE); text.setToolTipText("The name for the working set."); text.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(true, false) // .span(2, 1) // .create()); text.setFocus(); final IValidator validator = (v) -> { final String value = (String) v; if (value == null || value.trim().isEmpty()) { return ValidationStatus.error("Please provide a name!"); } return ValidationStatus.ok(); }; final UpdateValueStrategy targetToModel = new UpdateValueStrategy() // .setAfterConvertValidator(validator) // ; final ISWTObservableValue target = WidgetProperties.text(SWT.Modify) // .observe(text) // ; final Binding binding = mDataBindingContext.bindValue(target, mWorkingSetName, targetToModel, null); ControlDecorationSupport.create(binding, SWT.LEFT | SWT.TOP); } // script { final String workingSetScript = JSWorkingSetPrefs.getScript(mWorkingSet); mWorkingSetScript = WritableValue.withValueType(String.class); mWorkingSetScript.setValue(workingSetScript); final String linkText = String.format("<a href=\"native\">%s</a>", "Script:"); //$NON-NLS-1$ final Link link = new Link(composite, SWT.NONE); link.setText(linkText); final Text text = new Text(composite, SWT.BORDER | SWT.SINGLE); text.setToolTipText("Enter a workspace file."); text.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(true, false) // .create()); link.addListener(SWT.Selection, (e) -> { final String filename = text.getText(); if (filename.isEmpty()) { return; } final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final IResource resource = root.findMember(filename); if (resource == null || !resource.isAccessible() || resource.getType() != IResource.FILE) { return; } final IWorkbench workbench = PlatformUI.getWorkbench(); final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); if (window == null) { return; } final IWorkbenchPage page = window.getActivePage(); if (page == null) { return; } try { final FileEditorInput input = new FileEditorInput((IFile) resource); final IEditorDescriptor editor = workbench.getEditorRegistry() .getDefaultEditor(resource.getName()); final String editorId = editor != null ? editor.getId() : EditorsUI.DEFAULT_TEXT_EDITOR_ID; page.openEditor(input, editorId); } catch (final PartInitException ex) { Activator.log(IStatus.ERROR, String.format("Failed to open editor for '%s'!", filename), ex); //$NON-NLS-1$ } }); // TODO history or path completion for script? final Button button = new Button(composite, SWT.PUSH); button.setText("Browse..."); //$NON-NLS-1$ button.setLayoutData(GridDataFactory.swtDefaults() // .align(SWT.FILL, SWT.CENTER) // .grab(false, false) // .create()); button.addListener(SWT.Selection, (e) -> { final Shell shell = button.getShell(); final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); final SelectionDialog dialog = new ResourceListSelectionDialog(shell, root, IResource.FILE); dialog.setTitle("Select a JavaScript file"); if (dialog.open() == Window.OK) { final Object[] objects = dialog.getResult(); if (objects.length == 1) { final IResource resource = (IResource) objects[0]; final IPath path = resource.getFullPath(); text.setText(path.toString()); } else { text.setText(""); //$NON-NLS-1$ } } }); final IValidator validator = (v) -> { final String value = (String) v; if (value == null || value.trim().isEmpty()) { return ValidationStatus.error("Please provide a script!"); } final IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(value); if (member == null || !member.exists()) { return ValidationStatus.error("The provided script does not exist in the workspace!"); } return ValidationStatus.ok(); }; final UpdateValueStrategy targetToModel = new UpdateValueStrategy() // .setAfterConvertValidator(validator) // ; final ISWTObservableValue target = WidgetProperties.text(SWT.Modify) // .observe(text) // ; final Binding binding = mDataBindingContext.bindValue(target, mWorkingSetScript, targetToModel, null); ControlDecorationSupport.create(binding, SWT.LEFT | SWT.TOP); } final WizardPageSupport wizardPageSupport = WizardPageSupport.create(this, mDataBindingContext); wizardPageSupport.setValidationMessageProvider(new ValidationMessageProvider() { @Override public String getMessage(final ValidationStatusProvider pStatusProvider) { final String message = super.getMessage(pStatusProvider); if (message != null) { return message; } return "Enter a working set label and name and select the script that makes up the content of the working set."; } }); // provide a clean start setErrorMessage(null); setMessage( "Enter a working set label and name and select the script that makes up the content of the working set."); }
From source file:net.efano.sandbox.jface.snippets.HelloWorld.java
License:Open Source License
public static void main(String[] args) { Display display = new Display(); final ViewModel viewModel = new ViewModel(); Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { public void run() { final Shell shell = new View(viewModel).createShell(); // The SWT event loop Display display = Display.getCurrent(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep();//from w w w . j a v a2 s . co m } } } }); // Print the results System.out.println("person.getName() = " + viewModel.getPerson().getName()); }
From source file:net.efano.sandbox.jface.snippets.SpreadSheet.java
License:Open Source License
public static void main(String[] args) { final Display display = new Display(); Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { public void run() { Shell shell = new Shell(display); shell.setText("Data Binding Snippet 006"); final Table table = new Table(shell, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL); table.setLinesVisible(true); table.setHeaderVisible(true); for (int i = 0; i < NUM_COLUMNS; i++) { TableColumn tableColumn = new TableColumn(table, SWT.NONE); tableColumn.setText(Character.toString((char) ('A' + i))); tableColumn.setWidth(60); }// www.j a va2 s . c o m WritableList list = new WritableList(); for (int i = 0; i < NUM_ROWS; i++) { list.add(new Object()); for (int j = 0; j < NUM_COLUMNS; j++) { cellFormulas[i][j] = new WritableValue(); cellValues[i][j] = new ComputedCellValue(cellFormulas[i][j]); if (!FUNKY_FORMULAS || i == 0 || j == 0) { cellFormulas[i][j].setValue(""); } else { cellFormulas[i][j] .setValue("=" + cellReference(i - 1, j) + "+" + cellReference(i, j - 1)); } } } new TableUpdater(table, list) { protected void updateItem(int rowIndex, TableItem item, Object element) { if (DEBUG_LEVEL >= 1) { System.out.println("updating row " + rowIndex); } for (int j = 0; j < NUM_COLUMNS; j++) { item.setText(j, (String) cellValues[rowIndex][j].getValue()); } } }; if (FUNKY_COUNTER) { // counter in A1 display.asyncExec(new Runnable() { public void run() { cellFormulas[0][1].setValue("" + counter++); display.timerExec(COUNTER_UPDATE_DELAY, this); } }); } // create a TableCursor to navigate around the table final TableCursor cursor = new TableCursor(table, SWT.NONE); // create an editor to edit the cell when the user hits "ENTER" // while over a cell in the table final ControlEditor editor = new ControlEditor(cursor); editor.grabHorizontal = true; editor.grabVertical = true; cursor.addSelectionListener(new SelectionAdapter() { // when the TableEditor is over a cell, select the // corresponding row // in // the table public void widgetSelected(SelectionEvent e) { table.setSelection(new TableItem[] { cursor.getRow() }); } // when the user hits "ENTER" in the TableCursor, pop up a // text // editor so that // they can change the text of the cell public void widgetDefaultSelected(SelectionEvent e) { final Text text = new Text(cursor, SWT.NONE); TableItem row = cursor.getRow(); int rowIndex = table.indexOf(row); int columnIndex = cursor.getColumn(); text.setText((String) cellFormulas[rowIndex][columnIndex].getValue()); text.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { // close the text editor and copy the data over // when the user hits "ENTER" if (e.character == SWT.CR) { TableItem row = cursor.getRow(); int rowIndex = table.indexOf(row); int columnIndex = cursor.getColumn(); cellFormulas[rowIndex][columnIndex].setValue(text.getText()); text.dispose(); } // close the text editor when the user hits // "ESC" if (e.character == SWT.ESC) { text.dispose(); } } }); editor.setEditor(text); text.setFocus(); } }); // Hide the TableCursor when the user hits the "MOD1" or "MOD2" // key. // This alows the user to select multiple items in the table. cursor.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.MOD1 || e.keyCode == SWT.MOD2 || (e.stateMask & SWT.MOD1) != 0 || (e.stateMask & SWT.MOD2) != 0) { cursor.setVisible(false); } } }); // Show the TableCursor when the user releases the "MOD2" or // "MOD1" key. // This signals the end of the multiple selection task. table.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.keyCode == SWT.MOD1 && (e.stateMask & SWT.MOD2) != 0) return; if (e.keyCode == SWT.MOD2 && (e.stateMask & SWT.MOD1) != 0) return; if (e.keyCode != SWT.MOD1 && (e.stateMask & SWT.MOD1) != 0) return; if (e.keyCode != SWT.MOD2 && (e.stateMask & SWT.MOD2) != 0) return; TableItem[] selection = table.getSelection(); TableItem row = (selection.length == 0) ? table.getItem(table.getTopIndex()) : selection[0]; table.showItem(row); cursor.setSelection(row, 0); cursor.setVisible(true); cursor.setFocus(); } }); GridLayoutFactory.fillDefaults().generateLayout(shell); shell.setSize(400, 300); shell.open(); // The SWT event loop while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } }); display.dispose(); }
From source file:net.efano.sandbox.jface.snippets.TableViewerCollectionBinding.java
License:Open Source License
public static void main(String[] args) { final Display display = Display.getDefault(); // In an RCP application, the threading Realm will be set for you // automatically by the Workbench. In an SWT application, you can do // this once, wrapping your binding method call. Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { @Override/*from w ww . j a v a 2 s . c o m*/ public void run() { ViewModel viewModel = new ViewModel(); Shell shell = new View(viewModel).createShell(); // The SWT event loop while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } }); }
From source file:net.efano.sandbox.jface.snippets.TableViewerColors.java
License:Open Source License
/** * @param args/* w w w .j av a2 s. c om*/ */ public static void main(String[] args) { final List<Person> persons = new ArrayList<Person>(); persons.add(new Person("Fiona Apple", Person.FEMALE)); persons.add(new Person("Elliot Smith", Person.MALE)); persons.add(new Person("Diana Krall", Person.FEMALE)); persons.add(new Person("David Gilmour", Person.MALE)); final Display display = new Display(); Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { public void run() { Shell shell = new Shell(display); shell.setText("Gender Bender"); shell.setLayout(new GridLayout()); Table table = new Table(shell, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, false); gd_table.heightHint = 352; table.setLayoutData(gd_table); table.setHeaderVisible(true); table.setLinesVisible(true); TableColumn column = new TableColumn(table, SWT.NONE); column.setText("No"); column.setWidth(20); column = new TableColumn(table, SWT.NONE); column.setText("Name"); column.setWidth(100); final TableViewer viewer = new TableViewer(table); IObservableList observableList = Observables.staticObservableList(persons); ObservableListContentProvider contentProvider = new ObservableListContentProvider(); viewer.setContentProvider(contentProvider); // this does not have to correspond to the columns in the table, // we just list all attributes that affect the table content. IObservableSet oset = contentProvider.getKnownElements(); IObservableMap[] attributes = BeansObservables.observeMaps(contentProvider.getKnownElements(), Person.class, new String[] { "name", "gender" }); class ColorLabelProvider extends ObservableMapLabelProvider implements ITableColorProvider { Color male = display.getSystemColor(SWT.COLOR_BLUE); Color female = new Color(display, 255, 192, 203); ColorLabelProvider(IObservableMap[] attributes) { super(attributes); } // to drive home the point that attributes does not have to // match // the columns // in the table, we change the column text as follows: @Override public String getColumnText(Object element, int index) { if (index == 0) { return Integer.toString(persons.indexOf(element) + 1); } return ((Person) element).getName(); } @Override public Color getBackground(Object element, int index) { return null; } @Override public Color getForeground(Object element, int index) { if (index == 0) return null; Person person = (Person) element; return (person.getGender() == Person.MALE) ? male : female; } @Override public void dispose() { super.dispose(); female.dispose(); } } viewer.setLabelProvider(new ColorLabelProvider(attributes)); viewer.setInput(observableList); table.getColumn(0).pack(); Button button = new Button(shell, SWT.PUSH); button.setText("Toggle Gender"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent arg0) { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); if (selection != null && !selection.isEmpty()) { Person person = (Person) selection.getFirstElement(); person.setGender((person.getGender() == Person.MALE) ? Person.FEMALE : Person.MALE); } } }); shell.setSize(380, 713); Button btnAddRow = new Button(shell, SWT.NONE); btnAddRow.setText("Add Row"); newRowNameText = new Text(shell, SWT.BORDER); newRowNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); Composite composite = new Composite(shell, SWT.NONE); composite.setLayout(new FillLayout(SWT.HORIZONTAL)); GridData gd_composite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); gd_composite.widthHint = 129; gd_composite.heightHint = 26; composite.setLayoutData(gd_composite); Button maleRadioButton = new Button(composite, SWT.RADIO); maleRadioButton.setText("Male"); Button femaleRadioButton = new Button(composite, SWT.RADIO); femaleRadioButton.setText("Female"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } } }); display.dispose(); }
From source file:net.efano.sandbox.jface.ViewDomainAttempt.java
License:Open Source License
/** * @wbp.parser.entryPoint//from w w w. j ava 2 s. c o m */ public static void main(String[] args) { final Display display = Display.getDefault(); // In an RCP application, the threading Realm will be set for you // automatically by the Workbench. In an SWT application, you can do // this once, wrapping your binding method call. Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { @Override public void run() { ViewModel viewModel = new ViewModel(); Shell shell = new View(viewModel).createShell(); // The SWT event loop while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } } }); }
From source file:net.geoprism.shapefile.GISManagerLauncher.java
License:Open Source License
public static void main(String[] args) throws Exception { Arguments arguments = new Arguments(args); Localizer.setInstance("messages", arguments.getLocale()); final Display display = Display.getDefault(); class WindowRunner implements Runnable, Reloadable { public void run() { try { Class<?> clazz = LoaderDecorator.load("net.geoprism.shapefile.GISManagerWindow"); Constructor<?> constructor = clazz.getConstructor(); Object instance = constructor.newInstance(); clazz.getMethod("run").invoke(instance); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); }/* w w w.j a v a 2 s . c om*/ } } Realm.runWithDefault(SWTObservables.getRealm(display), new WindowRunner()); }
From source file:net.geoprism.shapefile.locatedIn.LocatedInPage.java
License:Open Source License
public LocatedInPage(LocatedInBean bean) { super(PAGE_NAME); setTitle(Localizer.getMessage("LOCATED_IN_WIZARD")); setDescription(Localizer.getMessage("LOCATED_IN_WIZARD_OPTIONS")); this.bean = bean; this.bean.addPropertyChangeListener("option", this); this.bindingContext = new DataBindingContext(SWTObservables.getRealm(Display.getDefault())); setPageComplete(bean.getOption() != null); }