List of usage examples for org.eclipse.jface.viewers TreeViewer getControl
@Override
public Control getControl()
From source file:org.jboss.tools.openshift.express.internal.ui.wizard.application.ApplicationTemplateWizardPage.java
License:Open Source License
private void createNewApplicationControls(Composite parent, SelectObservableValue useExitingApplication, IObservableValue useExistingApplication, DataBindingContext dbc) { // existing app radio Button newApplicationButton = new Button(parent, SWT.RADIO); newApplicationButton.setText("Create a new OpenShift application:"); newApplicationButton.setToolTipText("If selected we will create a new application in OpenShift."); GridDataFactory.fillDefaults().span(2, 1).indent(0, 8).align(SWT.FILL, SWT.CENTER).grab(true, false) .applyTo(newApplicationButton); useExitingApplication.addOption(Boolean.FALSE, WidgetProperties.selection().observe(newApplicationButton)); // new app explanatory label Label existingAppLabel = new Label(parent, SWT.None); existingAppLabel.setText(/*from w ww . j a v a 2 s. c om*/ "You can create an application form scratch or handpick from existing cartridges you need."); existingAppLabel.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND)); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.CENTER).grab(true, false) .applyTo(existingAppLabel); Composite applicationTemplatesTreeComposite = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, true) .applyTo(applicationTemplatesTreeComposite); GridLayoutFactory.fillDefaults().spacing(2, 2).applyTo(applicationTemplatesTreeComposite); // filter text Text templateFilterText = UIUtils.createSearchText(applicationTemplatesTreeComposite); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(templateFilterText); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(templateFilterText)).notUpdatingParticipant() .to(useExistingApplication).converting(new InvertingBooleanConverter()).in(dbc); // application templates tree final TreeViewer applicationTemplatesViewer = createApplicationTemplatesViewer( applicationTemplatesTreeComposite, templateFilterText); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(400, 180) .applyTo(applicationTemplatesViewer.getControl()); ValueBindingBuilder.bind(WidgetProperties.enabled().observe(applicationTemplatesViewer.getControl())) .notUpdatingParticipant().to(useExistingApplication).converting(new InvertingBooleanConverter()) .in(dbc); templateFilterText.addModifyListener(onFilterTextModified(applicationTemplatesViewer)); IObservableValue selectedApplicationTemplateViewerObservable = ViewerProperties.singleSelection() .observe(applicationTemplatesViewer); IObservableValue selectedApplicationTemplateModelObservable = BeanProperties .value(ApplicationTemplateWizardPageModel.PROPERTY_SELECTED_APPLICATION_TEMPLATE) .observe(pageModel); ValueBindingBuilder.bind(selectedApplicationTemplateViewerObservable) .to(selectedApplicationTemplateModelObservable).in(dbc); ApplicationTemplateValidator selectedApplicationTemplateValidator = new ApplicationTemplateValidator( useExitingApplication, selectedApplicationTemplateViewerObservable); dbc.addValidationStatusProvider(selectedApplicationTemplateValidator); ControlDecorationSupport.create(selectedApplicationTemplateValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true)); // selected application template details final Group detailsContainer = new Group(applicationTemplatesTreeComposite, SWT.NONE); detailsContainer.setText("Details"); enableTemplateDetailsControls(detailsContainer, !pageModel.isUseExistingApplication()); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, 106).applyTo(detailsContainer); useExistingApplication.addValueChangeListener(new IValueChangeListener() { @Override public void handleValueChange(final ValueChangeEvent event) { final Boolean enabled = Boolean.FALSE.equals(event.diff.getNewValue()); enableTemplateDetailsControls(detailsContainer, enabled); } }); new ApplicationTemplateDetailViews(selectedApplicationTemplateModelObservable, useExitingApplication, detailsContainer, dbc).createControls(); }
From source file:org.jboss.tools.openshift.express.internal.ui.wizard.application.details.ApplicationDetailsDialog.java
License:Open Source License
private void createContextMenu(TreeViewer viewer) { IMenuManager contextMenu = UIUtils.createContextMenu(viewer.getControl()); contextMenu.add(new CopyPropertyAction(viewer)); }
From source file:org.jboss.tools.openshift.internal.ui.server.ServerSettingsWizardPage.java
License:Open Source License
private void createServiceControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {/*from ww w. j ava 2 s . c om*/ Group servicesGroup = new Group(container, SWT.NONE); servicesGroup.setText("Services"); GridDataFactory.fillDefaults().span(4, 1).align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(servicesGroup); GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(servicesGroup); Label selectorLabel = new Label(servicesGroup, SWT.NONE); selectorLabel.setText("Selector:"); Text selectorText = UIUtils.createSearchText(servicesGroup); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(selectorText); final TreeViewer servicesViewer = createServicesTreeViewer(servicesGroup, model, selectorText); IObservableList serviceItemsObservable = BeanProperties .list(ServerSettingsWizardPageModel.PROPERTY_SERVICE_ITEMS).observe(model); DataBindingUtils.addDisposableListChangeListener(onServiceItemsChanged(servicesViewer), serviceItemsObservable, servicesViewer.getTree()); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).hint(SWT.DEFAULT, 160).grab(true, true) .applyTo(servicesViewer.getControl()); selectorText.addModifyListener(onFilterTextModified(servicesViewer)); IViewerObservableValue selectedServiceTreeItem = ViewerProperties.singleSelection().observe(servicesViewer); ValueBindingBuilder.bind(selectedServiceTreeItem) .converting(new ObservableTreeItem2ModelConverter(IService.class)) .validatingAfterConvert(new IValidator() { @Override public IStatus validate(Object value) { if (!(value instanceof IService)) { return ValidationStatus .cancel("Please select a service that this adapter will be bound to."); } return ValidationStatus.ok(); } }).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_SERVICE).observe(model)) .converting(new Model2ObservableTreeItemConverter( new ServerSettingsWizardPageModel.ServiceTreeItemsFactory())) .in(dbc); // details ExpandableComposite expandable = new ExpandableComposite(servicesGroup, SWT.None); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150) .applyTo(expandable); expandable.setText("Service Details"); expandable.setExpanded(true); GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(0, 0).applyTo(expandable); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150) .applyTo(expandable); Composite detailsContainer = new Composite(expandable, SWT.NONE); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150) .applyTo(detailsContainer); IObservableValue<IResource> selectedService = new WritableValue<IResource>(); ValueBindingBuilder.bind(selectedServiceTreeItem).converting(new ObservableTreeItem2ModelConverter()) .to(selectedService).notUpdatingParticipant().in(dbc); new ServiceDetailViews(selectedService, detailsContainer, dbc).createControls(); expandable.setClient(detailsContainer); expandable.addExpansionListener(new IExpansionListener() { @Override public void expansionStateChanging(ExpansionEvent e) { } @Override public void expansionStateChanged(ExpansionEvent e) { servicesGroup.update(); servicesGroup.layout(true); } }); }
From source file:org.jboss.tools.openshift.internal.ui.wizard.importapp.BuildConfigWizardPage.java
License:Open Source License
@Override protected void doCreateControls(Composite parent, DataBindingContext dbc) { GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(parent); GridLayoutFactory.fillDefaults().applyTo(parent); Group buildConfigsGroup = new Group(parent, SWT.NONE); buildConfigsGroup.setText("Existing Build Configs:"); GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).applyTo(buildConfigsGroup); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(buildConfigsGroup); // build configs tree TreeViewer buildConfigsViewer = createBuildConfigsViewer( new Tree(buildConfigsGroup, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL), model, dbc); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(SWT.DEFAULT, 200).span(1, 2) .applyTo(buildConfigsViewer.getControl()); final IObservableValue selectedItem = BeanProperties.value(IBuildConfigPageModel.PROPERTY_SELECTED_ITEM) .observe(model);/*from w w w.j a v a 2 s . co m*/ Binding selectedBuildConfigBinding = ValueBindingBuilder .bind(ViewerProperties.singleSelection().observe(buildConfigsViewer)) .converting(new ObservableTreeItem2ModelConverter()).to(selectedItem) .converting(new Model2ObservableTreeItemConverter()).in(dbc); dbc.addValidationStatusProvider(new MultiValidator() { @Override protected IStatus validate() { if (!(selectedItem.getValue() instanceof IBuildConfig)) { return ValidationStatus .cancel("Please select the existing build config that you want to import"); } else { return ValidationStatus.ok(); } } }); IObservableValue connectionObservable = BeanProperties.value(IBuildConfigPageModel.PROPERTY_CONNECTION) .observe(model); DataBindingUtils.addDisposableValueChangeListener(onConnectionChanged(buildConfigsViewer, model), connectionObservable, buildConfigsViewer.getTree()); ControlDecorationSupport.create(selectedBuildConfigBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true)); // refresh button Button refreshButton = new Button(buildConfigsGroup, SWT.PUSH); refreshButton.setText("&Refresh"); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(100, SWT.DEFAULT).applyTo(refreshButton); refreshButton.addSelectionListener(onRefresh(buildConfigsViewer, model)); // filler Label fillerLabel = new Label(buildConfigsGroup, SWT.NONE); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, true).applyTo(fillerLabel); // details ExpandableComposite expandable = new ExpandableComposite(buildConfigsGroup, SWT.None); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150) .applyTo(expandable); expandable.setText("Build config Details"); expandable.setExpanded(true); GridLayoutFactory.fillDefaults().numColumns(2).margins(0, 0).spacing(0, 0).applyTo(expandable); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150) .applyTo(expandable); Composite detailsContainer = new Composite(expandable, SWT.NONE); GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false).hint(SWT.DEFAULT, 150) .applyTo(detailsContainer); IObservableValue selectedService = new WritableValue(); ValueBindingBuilder.bind(selectedItem).to(selectedService).notUpdatingParticipant().in(dbc); new BuildConfigDetailViews(selectedService, detailsContainer, dbc).createControls(); expandable.setClient(detailsContainer); expandable.addExpansionListener(new IExpansionListener() { @Override public void expansionStateChanging(ExpansionEvent e) { } @Override public void expansionStateChanged(ExpansionEvent e) { buildConfigsGroup.update(); buildConfigsGroup.layout(true); } }); loadBuildConfigs(model); }
From source file:org.jboss.tools.smooks.configuration.editors.SmooksMasterDetailBlock.java
License:Open Source License
private void createMenuForViewer(TreeViewer smooksTreeViewer2) { MenuManager contextMenu = new MenuManager(); // contextMenu.add(new Separator("additions")); contextMenu.setRemoveAllWhenShown(true); contextMenu.addMenuListener(this); Menu menu = contextMenu.createContextMenu(smooksTreeViewer2.getControl()); smooksTreeViewer2.getControl().setMenu(menu); // formEditor.getSite().registerContextMenu(contextMenu, // new UnwrappingSelectionProvider(smooksTreeViewer2)); }
From source file:org.jkiss.dbeaver.ui.controls.itemlist.ObjectListControl.java
License:Open Source License
public ObjectListControl(Composite parent, int style, IContentProvider contentProvider) { super(parent, style); this.isFitWidth = false; int viewerStyle = getDefaultListStyle(); if ((style & SWT.SHEET) == 0) { viewerStyle |= SWT.BORDER;//from w w w. j ava 2s .c o m } EditorActivationStrategy editorActivationStrategy; final SelectionAdapter enterListener = new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { if (doubleClickHandler != null) { doubleClickHandler.doubleClick(new DoubleClickEvent(itemsViewer, itemsViewer.getSelection())); } } }; if (contentProvider instanceof ITreeContentProvider) { TreeViewer treeViewer = new TreeViewer(this, viewerStyle); final Tree tree = treeViewer.getTree(); tree.setLinesVisible(true); tree.setHeaderVisible(true); itemsViewer = treeViewer; editorActivationStrategy = new EditorActivationStrategy(treeViewer); TreeViewerEditor.create(treeViewer, editorActivationStrategy, ColumnViewerEditor.TABBING_CYCLE_IN_ROW); // We need measure item listener to prevent collapse/expand on double click // Looks like a bug in SWT: http://www.eclipse.org/forums/index.php/t/257325/ treeViewer.getControl().addListener(SWT.MeasureItem, new Listener() { @Override public void handleEvent(Event event) { // Just do nothing } }); tree.addSelectionListener(enterListener); } else { TableViewer tableViewer = new TableViewer(this, viewerStyle); final Table table = tableViewer.getTable(); table.setLinesVisible(true); table.setHeaderVisible(true); itemsViewer = tableViewer; //UIUtils.applyCustomTolTips(table); //itemsEditor = new TableEditor(table); editorActivationStrategy = new EditorActivationStrategy(tableViewer); TableViewerEditor.create(tableViewer, editorActivationStrategy, ColumnViewerEditor.TABBING_CYCLE_IN_ROW); table.addSelectionListener(enterListener); } //editorActivationStrategy.setEnableEditorActivationWithKeyboard(true); renderer = createRenderer(); itemsViewer.getColumnViewerEditor().addEditorActivationListener(new EditorActivationListener()); itemsViewer.setContentProvider(contentProvider); //itemsViewer.setLabelProvider(new ItemLabelProvider()); itemsViewer.getControl().addMouseListener(new MouseAdapter() { @Override public void mouseDoubleClick(MouseEvent e) { if (doubleClickHandler != null) { // Uee provided double click doubleClickHandler.doubleClick(new DoubleClickEvent(itemsViewer, itemsViewer.getSelection())); } } }); itemsViewer.getControl().addListener(SWT.PaintItem, new PaintListener()); GridData gd = new GridData(GridData.FILL_BOTH); itemsViewer.getControl().setLayoutData(gd); //PropertiesContributor.getInstance().addLazyListener(this); // Add selection listener itemsViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.isEmpty()) { setCurListObject(null); } else { setCurListObject((OBJECT_TYPE) selection.getFirstElement()); } String status; if (selection.isEmpty()) { status = ""; //$NON-NLS-1$ } else if (selection.size() == 1) { Object selectedNode = selection.getFirstElement(); status = ObjectViewerRenderer.getCellString(selectedNode, false); } else { status = NLS.bind(CoreMessages.controls_object_list_status_objects, selection.size()); } setInfo(status); } }); }
From source file:org.jkiss.dbeaver.ui.navigator.project.ProjectExplorerView.java
License:Open Source License
private void createColumns(final TreeViewer viewer) { final Color shadowColor = viewer.getControl().getDisplay().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW); final LabelProvider mainLabelProvider = (LabelProvider) viewer.getLabelProvider(); columnController = new ViewerColumnController("projectExplorer", viewer); columnController.addColumn("Name", "Resource name", SWT.LEFT, true, true, new TreeColumnViewerLabelProvider(new LabelProvider() { @Override//from w w w . j a va2s. c om public String getText(Object element) { return mainLabelProvider.getText(element); } @Override public Image getImage(Object element) { return mainLabelProvider.getImage(element); } })); columnController.addColumn("DataSource", "Datasource(s) associated with resource", SWT.LEFT, true, false, new TreeColumnViewerLabelProvider(new LabelProvider() { @Override public String getText(Object element) { DBNNode node = (DBNNode) element; if (node instanceof DBNDatabaseNode) { return ((DBNDatabaseNode) node).getDataSourceContainer().getName(); } else if (node instanceof DBNResource) { Collection<DBPDataSourceContainer> containers = ((DBNResource) node) .getAssociatedDataSources(); if (!CommonUtils.isEmpty(containers)) { StringBuilder text = new StringBuilder(); for (DBPDataSourceContainer container : containers) { if (text.length() > 0) { text.append(", "); } text.append(container.getName()); } return text.toString(); } } return ""; } @Override public Image getImage(Object element) { /* DBNNode node = (DBNNode) element; if (node instanceof DBNDatabaseNode) { return DBeaverIcons.getImage(((DBNDatabaseNode) node).getDataSourceContainer().getDriver().getIcon()); } else if (node instanceof DBNResource) { Collection<DBPDataSourceContainer> containers = ((DBNResource) node).getAssociatedDataSources(); if (containers != null && containers.size() == 1) { return DBeaverIcons.getImage((containers.iterator().next().getDriver().getIcon())); } } */ return null; } })); columnController.addColumn("Preview", "Script content preview", SWT.LEFT, false, false, new LazyLabelProvider(shadowColor) { @Override public String getLazyText(Object element) { return ((DBNNode) element).getNodeDescription(); } }); columnController.addColumn("Size", "File size", SWT.LEFT, false, false, new TreeColumnViewerLabelProvider(new LabelProvider() { @Override public String getText(Object element) { DBNNode node = (DBNNode) element; if (node instanceof DBNResource) { IResource resource = ((DBNResource) node).getResource(); if (resource instanceof IFile) { return String.valueOf(resource.getLocation().toFile().length()); } } return ""; } })); columnController.addColumn("Modified", "Time the file was last modified", SWT.LEFT, false, false, new TreeColumnViewerLabelProvider(new LabelProvider() { private SimpleDateFormat sdf = new SimpleDateFormat(UIUtils.DEFAULT_TIMESTAMP_PATTERN); @Override public String getText(Object element) { DBNNode node = (DBNNode) element; if (node instanceof DBNResource) { IResource resource = ((DBNResource) node).getResource(); if (resource instanceof IFile) { return sdf.format(new Date(resource.getLocation().toFile().lastModified())); } } return ""; } })); columnController.addColumn("Type", "Resource type", SWT.LEFT, false, false, new TreeColumnViewerLabelProvider(new LabelProvider() { @Override public String getText(Object element) { DBNNode node = (DBNNode) element; if (node instanceof DBNResource) { IResource resource = ((DBNResource) node).getResource(); ProgramInfo program = ProgramInfo.getProgram(resource); if (program != null) { return program.getProgram().getName(); } } return ""; } })); columnController.createColumns(); }
From source file:org.jvmmonitor.internal.ui.properties.memory.SWTResourcesPage.java
License:Open Source License
/** * Refreshes the appearance.// w w w . j av a 2 s . co m * * @param force * <tt>true</tt> to force refresh */ protected void refresh(final boolean force) { final boolean isVisible = isVisible(); new RefreshJob(NLS.bind(Messages.refreshMemorySectionJobLabel, section.getJvm().getPid()), toString()) { @Override protected void refreshModel(IProgressMonitor monitor) { try { IActiveJvm jvm = section.getJvm(); if (isVisible && jvm != null && jvm.isConnected() && (!section.isRefreshSuspended() || force) && jvm.getSWTResourceMonitor().isSupported()) { jvm.getSWTResourceMonitor().refreshResourcesCache(); } } catch (JvmCoreException e) { Activator.log(Messages.refreshHeapDataFailedMsg, e); } } @Override protected void refreshUI() { IActiveJvm jvm = section.getJvm(); boolean isConnected = jvm != null && jvm.isConnected(); if (!isDisposed()) { refreshBackground(); } refreshAction.setEnabled(isConnected); clearSWTResourceAction.setEnabled(isConnected); if (!force && section.isRefreshSuspended() || !isVisible) { return; } TreeViewer resourceViewer = resourceFilteredTree.getViewer(); if (!resourceViewer.getControl().isDisposed()) { resourceViewer.refresh(); if (jvm != null) { resourceFilteredTree.updateStatusLine(jvm.getSWTResourceMonitor().getResources()); } // select the first item if no item is selected if (resourceViewer.getSelection().isEmpty()) { TreeItem[] items = resourceViewer.getTree().getItems(); if (items != null && items.length > 0) { resourceViewer.getTree().select(items[0]); stackTraceViewer.setInput(resourceViewer.getSelection()); } else { stackTraceViewer.setInput(null); } } } if (!stackTraceViewer.getControl().isDisposed()) { stackTraceViewer.refresh(); } } }.schedule(); }
From source file:org.kacprzak.eclipse.django_editor.editors.outline.DjangoContentOutlinePage.java
License:Open Source License
/** * Updates the outline page.//from w ww.ja v a 2 s. com */ public void update() { TreeViewer viewer = getTreeViewer(); if (viewer != null) { Control control = viewer.getControl(); if (control != null && !control.isDisposed()) { control.setRedraw(false); viewer.setInput(fEditorInput); viewer.expandAll(); control.setRedraw(true); } } }
From source file:org.kalypso.contribs.eclipse.jface.viewers.ViewerUtilities.java
License:Open Source License
public static void setSelection(final TreeViewer viewer, final ISelection selection, final boolean reveal, final boolean async) { final Runnable runner = new Runnable() { @Override//from ww w. j av a 2 s. c o m public void run() { if (!viewer.getControl().isDisposed()) viewer.setSelection(selection, reveal); } }; execute(viewer, runner, async); }