List of usage examples for org.eclipse.jface.databinding.swt SWTObservables getRealm
@Deprecated public static Realm getRealm(final Display display)
From source file:org.eclipse.core.tests.internal.databinding.beans.BeanObservableValueDecoratorTest.java
License:Open Source License
protected void setUp() throws Exception { super.setUp(); bean = new Bean(); propertyDescriptor = new PropertyDescriptor("value", Bean.class); observableValue = BeansObservables.observeValue(SWTObservables.getRealm(Display.getDefault()), bean, "value"); decorator = new BeanObservableValueDecorator(observableValue, propertyDescriptor); }
From source file:org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableArrayBasedListTest.java
License:Open Source License
protected void setUp() throws Exception { super.setUp(); propertyName = "array"; propertyDescriptor = ((IBeanProperty) BeanProperties.list(Bean.class, propertyName)) .getPropertyDescriptor();// ww w. ja v a2 s .co m bean = new Bean(new Object[0]); list = BeansObservables.observeList(SWTObservables.getRealm(Display.getDefault()), bean, propertyName); beanObservable = (IBeanObservable) list; }
From source file:org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableArrayBasedSetTest.java
License:Open Source License
protected void setUp() throws Exception { super.setUp(); propertyName = "array"; propertyDescriptor = ((IBeanProperty) BeanProperties.set(Bean.class, propertyName)).getPropertyDescriptor(); bean = new Bean(new HashSet()); set = BeansObservables.observeSet(SWTObservables.getRealm(Display.getDefault()), bean, propertyName); beanObservable = (IBeanObservable) set; }
From source file:org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableListTest.java
License:Open Source License
protected void setUp() throws Exception { super.setUp(); propertyName = "list"; propertyDescriptor = ((IBeanProperty) BeanProperties.list(Bean.class, propertyName)) .getPropertyDescriptor();/*from w w w.j av a 2 s . c o m*/ bean = new Bean(new ArrayList()); list = BeansObservables.observeList(SWTObservables.getRealm(Display.getDefault()), bean, propertyName); beanObservable = (IBeanObservable) list; }
From source file:org.eclipse.core.tests.internal.databinding.beans.JavaBeanObservableSetTest.java
License:Open Source License
protected void setUp() throws Exception { super.setUp(); bean = new Bean(); propertyName = "set"; propertyDescriptor = ((IBeanProperty) BeanProperties.set(Bean.class, propertyName)).getPropertyDescriptor(); observableSet = BeansObservables.observeSet(SWTObservables.getRealm(Display.getDefault()), bean, propertyName, Bean.class); beanObservable = (IBeanObservable) observableSet; listener = new SetChangeEventTracker(); }
From source file:org.eclipse.dltk.internal.databinging.RadioButtonListValue.java
License:Open Source License
/** * @param button/* w ww. j av a 2 s. com*/ */ public RadioButtonListValue(Class<V> valueType, Map<Button, V> buttons) { super(SWTObservables.getRealm(buttons.keySet().iterator().next().getDisplay())); this.valueType = valueType; this.buttons = buttons; init(); }
From source file:org.eclipse.e4.demo.e4photo.Library.java
License:Open Source License
@Inject public Library(Composite parent, final IWorkspace workspace) { final Realm realm = SWTObservables.getRealm(parent.getDisplay()); this.workspace = workspace; initializeWorkspace();/*from w w w .j a v a 2s .c om*/ viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); viewer.getTree().setData("org.eclipse.e4.ui.css.id", "library"); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); selectionService .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); } }); IObservableFactory setFactory = new IObservableFactory() { public IObservable createObservable(Object element) { if (element instanceof IContainer && ((IContainer) element).exists()) { IObservableSet observableSet = observableSets.get(element); if (observableSet == null) { observableSet = new WritableSet(realm); try { observableSet.addAll(Arrays.asList(((IContainer) element).members())); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } observableSets.put((IContainer) element, observableSet); } return observableSet; } return Observables.emptyObservableSet(); } }; viewer.setContentProvider(new ObservableSetTreeContentProvider(setFactory, new TreeStructureAdvisor() { public Boolean hasChildren(Object element) { return Boolean.valueOf(element instanceof IContainer); } })); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { if (element instanceof IResource) return ((IResource) element).getName(); return element == null ? "" : element.toString(); } }); viewer.setSorter(new ViewerSorter()); viewer.setInput(workspace.getRoot()); // Button button = new Button(parent, SWT.PUSH); // button.setText("Create Project"); // button.addSelectionListener(new SelectionListener() { // public void widgetSelected(SelectionEvent e) { // String projectName = "Project" + (counter++); // final IProject project = workspace.getRoot().getProject( // projectName); // final IProjectDescription pd = workspace // .newProjectDescription(projectName); // try { // workspace.run(new IWorkspaceRunnable() { // public void run(IProgressMonitor monitor) // throws CoreException { // project.create(pd, monitor); // project.open(monitor); // } // }, new NullProgressMonitor()); // } catch (CoreException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } // } // // public void widgetDefaultSelected(SelectionEvent e) { // } // }); GridLayoutFactory.fillDefaults().generateLayout(parent); }
From source file:org.eclipse.e4.demo.simpleide.navigator.internal.ResourceNavigator.java
License:Open Source License
@Inject public ResourceNavigator(Composite parent, final IEclipseContext context, IWorkspace workspace) { final Realm realm = SWTObservables.getRealm(parent.getDisplay()); this.context = context; parent.setLayout(new FillLayout()); TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); selectionService/*w w w. ja v a 2s .c o m*/ .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); // context.modify(IServiceConstants.ACTIVE_SELECTION, selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); } }); IObservableFactory setFactory = new IObservableFactory() { public IObservable createObservable(Object element) { if (element instanceof IContainer && ((IContainer) element).exists()) { IObservableSet observableSet = observableSets.get(element); if (observableSet == null) { observableSet = new WritableSet(realm); try { observableSet.addAll(Arrays.asList(((IContainer) element).members())); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } observableSets.put((IContainer) element, observableSet); } return observableSet; } return Observables.emptyObservableSet(); } }; viewer.setContentProvider(new ObservableSetTreeContentProvider(setFactory, new TreeStructureAdvisor() { public Boolean hasChildren(Object element) { return Boolean.valueOf(element instanceof IContainer); } })); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { if (element instanceof IResource) return ((IResource) element).getName(); return element == null ? "" : element.toString(); } }); viewer.setSorter(new ViewerSorter()); viewer.setInput(workspace.getRoot()); viewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { MSimpleIDEApplication app = (MSimpleIDEApplication) application; IStructuredSelection s = (IStructuredSelection) event.getSelection(); for (Object o : s.toArray()) { if (o instanceof IFile) { IFile f = (IFile) o; context.set(IFile.class, f); String fExt = f.getFileExtension(); EDITOR: for (MEditorPartDescriptor desc : app.getEditorPartDescriptors()) { for (String ext : desc.getFileextensions()) { if (ext.equals(fExt)) { context.set(MEditorPartDescriptor.class, desc); System.err.println("Opening with: " + desc); Command cmd = commandService.getCommand("simpleide.command.openeditor"); ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(cmd, null); handlerService.executeHandler(pCmd); break EDITOR; } } } } } } }); setupContextMenu(viewer, parent.getShell()); workspace.addResourceChangeListener(listener); }
From source file:org.eclipse.e4.tools.ui.designer.E4WorkbenchProxy.java
License:Open Source License
public void createAndRunUI() { final Display display = Display.getDefault(); Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { public void run() { initializeStyling(display, appContext); // Register an SWT resource handler appContext.set(IResourceUtilities.class.getName(), new ResourceUtility()); // Has someone already created one ? renderer = (IPresentationEngine) appContext.get(IPresentationEngine.class.getName()); if (renderer == null) { String presentationURI = (String) appContext.get(E4Workbench.PRESENTATION_URI_ARG); if (presentationURI != null) { IContributionFactory factory = (IContributionFactory) appContext .get(IContributionFactory.class.getName()); renderer = (IPresentationEngine) factory.create(presentationURI, appContext); appContext.set(IPresentationEngine.class.getName(), renderer); }/* w w w .ja v a2 s .c o m*/ if (renderer == null) { Logger logger = (Logger) appContext.get(Logger.class.getName()); logger.error("Failed to create the presentation engine for URI: " + presentationURI); //$NON-NLS-1$ } } // String cssURI = (String) appContext // .get(E4Workbench.CSS_URI_ARG); // if (cssURI != null) { // String cssResourcesURI = (String) appContext // .get(E4Workbench.CSS_RESOURCE_URI_ARG); // PartRenderingEngine.initializeStyling(display, appContext); // } else { // initializeNullStyling(appContext); // } // Register an SWT resource handler // appContext.set(IResourceUtilities.class.getName(), new // ResourceUtility(Activator.getDefault() // .getBundleAdmin())); // set up the keybinding manager KeyBindingDispatcher dispatcher = (KeyBindingDispatcher) ContextInjectionFactory .make(KeyBindingDispatcher.class, appContext); keyListener = dispatcher.getKeyDownFilter(); display.addFilter(SWT.KeyDown, keyListener); display.addFilter(SWT.Traverse, keyListener); // if (device == null || device.isDisposed()) { // device = new Shell(display, SWT.NO_TRIM); // } // device.setSize(0, 0); // device.setVisible(true); // device.open(); int x = 0, y = 0, width = 500, height = 500; if (renderer != null) { if (uiRoot instanceof MApplication) { List<MWindow> children = ((MApplication) uiRoot).getChildren(); for (MWindow mWindow : children) { root = renderer.createGui(mWindow); x = mWindow.getX(); y = mWindow.getY(); // width = mWindow.getWidth(); // height = mWindow.getHeight(); } } } if (root != null && root instanceof Shell) { Shell shell = ((Shell) root); if (x < 0) { x = 0; } if (y < 0) { y = 0; } shell.setLocation(x, y); if (width > 0 && height > 0) { shell.setSize(width, height); } shell.moveBelow(null); shell.setVisible(false); } } }); }
From source file:org.eclipse.e4.ui.internal.workbench.swt.E4Application.java
License:Open Source License
public E4Workbench createE4Workbench(IApplicationContext applicationContext, final Display display) { args = (String[]) applicationContext.getArguments().get(IApplicationContext.APPLICATION_ARGS); IEclipseContext appContext = createDefaultContext(); appContext.set(Realm.class, SWTObservables.getRealm(display)); appContext.set(UISynchronize.class, new UISynchronize() { public void syncExec(Runnable runnable) { display.syncExec(runnable);//from w ww . j av a 2 s . com } public void asyncExec(Runnable runnable) { display.asyncExec(runnable); } }); appContext.set(IApplicationContext.class, applicationContext); // Check if DS is running if (!appContext.containsKey("org.eclipse.e4.ui.workbench.modeling.EPartService")) { throw new IllegalStateException( "Core services not available. Please make sure that a declarative service implementation (such as the bundle 'org.eclipse.equinox.ds') is available!"); } // Get the factory to create DI instances with IContributionFactory factory = (IContributionFactory) appContext.get(IContributionFactory.class.getName()); // Install the life-cycle manager for this session if there's one // defined String lifeCycleURI = getArgValue(IWorkbench.LIFE_CYCLE_URI_ARG, applicationContext, false); if (lifeCycleURI != null) { lcManager = factory.create(lifeCycleURI, appContext); if (lcManager != null) { // Let the manager manipulate the appContext if desired ContextInjectionFactory.invoke(lcManager, PostContextCreate.class, appContext, null); } } // Create the app model and its context MApplication appModel = loadApplicationModel(applicationContext, appContext); appModel.setContext(appContext); boolean isRtl = ((Window.getDefaultOrientation() & SWT.RIGHT_TO_LEFT) != 0); appModel.getTransientData().put(E4Workbench.RTL_MODE, isRtl); // for compatibility layer: set the application in the OSGi service // context (see Workbench#getInstance()) if (!E4Workbench.getServiceContext().containsKey(MApplication.class.getName())) { // first one wins. E4Workbench.getServiceContext().set(MApplication.class.getName(), appModel); } // Set the app's context after adding itself appContext.set(MApplication.class.getName(), appModel); // This context will be used by the injector for its // extended data suppliers ContextInjectionFactory.setDefault(appContext); // adds basic services to the contexts initializeServices(appModel); // let the life cycle manager add to the model if (lcManager != null) { ContextInjectionFactory.invoke(lcManager, ProcessAdditions.class, appContext, null); ContextInjectionFactory.invoke(lcManager, ProcessRemovals.class, appContext, null); } // Create the addons IEclipseContext addonStaticContext = EclipseContextFactory.create(); for (MAddon addon : appModel.getAddons()) { addonStaticContext.set(MAddon.class, addon); Object obj = factory.create(addon.getContributionURI(), appContext, addonStaticContext); addon.setObject(obj); } // Parse out parameters from both the command line and/or the product // definition (if any) and put them in the context String xmiURI = getArgValue(IWorkbench.XMI_URI_ARG, applicationContext, false); appContext.set(IWorkbench.XMI_URI_ARG, xmiURI); String themeId = getArgValue(E4Application.THEME_ID, applicationContext, false); appContext.set(E4Application.THEME_ID, themeId); String cssURI = getArgValue(IWorkbench.CSS_URI_ARG, applicationContext, false); if (cssURI != null) { appContext.set(IWorkbench.CSS_URI_ARG, cssURI); } // Temporary to support old property as well if (cssURI != null && !cssURI.startsWith("platform:")) { System.err.println( "Warning " + cssURI + " changed its meaning it is used now to run without theme support"); appContext.set(E4Application.THEME_ID, cssURI); } String cssResourcesURI = getArgValue(IWorkbench.CSS_RESOURCE_URI_ARG, applicationContext, false); appContext.set(IWorkbench.CSS_RESOURCE_URI_ARG, cssResourcesURI); appContext.set(E4Workbench.RENDERER_FACTORY_URI, getArgValue(E4Workbench.RENDERER_FACTORY_URI, applicationContext, false)); // This is a default arg, if missing we use the default rendering engine String presentationURI = getArgValue(IWorkbench.PRESENTATION_URI_ARG, applicationContext, false); if (presentationURI == null) { presentationURI = PartRenderingEngine.engineURI; } appContext.set(IWorkbench.PRESENTATION_URI_ARG, presentationURI); // Instantiate the Workbench (which is responsible for // 'running' the UI (if any)... return workbench = new E4Workbench(appModel, appContext); }