List of usage examples for org.eclipse.jface.viewers TreeSelection isEmpty
@Override
public boolean isEmpty()
From source file:com.abstratt.mdd.internal.ui.editors.source.SourceContentOutlinePage.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); viewer = getTreeViewer();//from ww w .ja v a 2s. c o m contentProvider = new TreeNodeContentProvider(); viewer.setContentProvider(contentProvider); labelProvider = new TextUMLLabelProvider(); viewer.setLabelProvider(labelProvider); // disabled: used to make elements to show sorted by type // viewer.setComparator(new UIModelObjectViewerComparator()); viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); // tracks selections in the outline and reflects them in the editor viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { TreeSelection selection = (TreeSelection) event.getSelection(); if (!selection.isEmpty()) { TreeNode treeNode = (TreeNode) selection.getFirstElement(); UIModelObject model = (UIModelObject) treeNode.getValue(); selectInEditor(model.getToken()); } } }); refresh(); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.properties.PropertySheetPage.java
License:Open Source License
@Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (selection instanceof TreeSelection && mPropertyTable != null && !mPropertyTable.isDisposed()) { TreeSelection treeSelection = (TreeSelection) selection; // We get a lot of repeated selection requests for the same selection // as before, so try to eliminate these if (mSelection != null) { if (mSelection.isEmpty()) { if (treeSelection.isEmpty()) { return; }/* ww w. j ava2 s.c o m*/ } else { int selectionCount = treeSelection.size(); if (selectionCount == mSelection.size()) { boolean same = true; Iterator<?> iterator = treeSelection.iterator(); for (int i = 0, n = selectionCount; i < n && iterator.hasNext(); i++) { Object next = iterator.next(); if (next instanceof CanvasViewInfo) { CanvasViewInfo info = (CanvasViewInfo) next; if (info != mSelection.get(i)) { same = false; break; } } else { same = false; break; } } if (same) { return; } } } } stopTrackingSelection(); if (treeSelection.isEmpty()) { mSelection = Collections.emptyList(); } else { int selectionCount = treeSelection.size(); List<CanvasViewInfo> newSelection = new ArrayList<CanvasViewInfo>(selectionCount); Iterator<?> iterator = treeSelection.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next instanceof CanvasViewInfo) { CanvasViewInfo info = (CanvasViewInfo) next; newSelection.add(info); } } mSelection = newSelection; } startTrackingSelection(); refreshProperties(); } }
From source file:com.atlassian.connector.eclipse.internal.crucible.ui.wizards.SelectChangesetsFromCruciblePage.java
License:Open Source License
private void updateButtonEnablement() { // right viewer TreeSelection selection = validateTreeSelection(selectedTreeViewer); removeButton.setEnabled(selection != null && !selection.isEmpty()); removeChangesetMenuItem.setEnabled(selection != null && !selection.isEmpty()); // left viewer selection = validateTreeSelection(availableTreeViewer); boolean changesetsOnly = hasChangesetsOnly(selection); addButton.setEnabled(selection != null && !selection.isEmpty() && !hasAlreadyChosenChangesetSelected(selection) && changesetsOnly); addChangesetMenuItem.setEnabled(selection != null && !selection.isEmpty() && !hasAlreadyChosenChangesetSelected(selection) && changesetsOnly); getNextRevisionsMenuItem.setEnabled(selection != null && !selection.isEmpty()); }
From source file:com.atlassian.connector.eclipse.internal.crucible.ui.wizards.SelectScmChangesetsPage.java
License:Open Source License
private void updateButtonEnablement() { //right viewer TreeSelection selection = validateTreeSelection(selectedTreeViewer, false); removeButton.setEnabled(selection != null && !selection.isEmpty()); removeChangesetMenuItem.setEnabled(selection != null && !selection.isEmpty()); //left viewer selection = validateTreeSelection(availableTreeViewer, true); boolean changesetsOnly = hasChangesetsOnly(selection); addButton.setEnabled(selection != null && !selection.isEmpty() && !hasAlreadyChosenChangesetSelected(selection) && changesetsOnly); addChangesetMenuItem.setEnabled(selection != null && !selection.isEmpty() && !hasAlreadyChosenChangesetSelected(selection) && changesetsOnly); getNextRevisionsMenuItem.setEnabled(selection != null && !selection.isEmpty()); }
From source file:com.nokia.carbide.internal.api.templatewizard.ui.ChooseTemplatePage.java
License:Open Source License
private void handleTemplateSelectionChanged() { ISelection selection = templateTreeViewer.getSelection(); if (selection instanceof TreeSelection) { TreeSelection treeSelection = (TreeSelection) selection; TreeNode treeNode = (TreeNode) treeSelection.getFirstElement(); if (!treeSelection.isEmpty()) { Object value = treeNode.getValue(); if (value instanceof ITemplate) { if (selectedTemplateUI != null) { selectedTemplateUI.dispose(); }/* ww w. j a v a 2 s.com*/ try { selectedTemplate = ((ITemplate) value).getLoadedTemplate(); String description = TextUtils.catenateBrokenLines(selectedTemplate.getDescription()); description = selectedTemplate.getTemplate().getLocalizedString(description); templateDescriptionText.setText(description); setSelectedNode(new TemplatePagesNode((TemplateWizard) getWizard())); // create the UI for the template and initialize its settings selectedTemplateUI = selectedTemplate.createLoadedTemplateUI(); selectedTemplate.getTemplate().getTemplateValues().clear(); selectedTemplateUI .loadSettings(((TemplateWizard) getWizard()).getPersistedSettingsStorage()); ((TemplateWizard) getWizard()).notifyTemplateChanged(); } catch (CoreException e) { selectedTemplate = null; selectedTemplateUI = null; Logging.log(null, Logging.newStatus(TemplateWizardPlugin.getDefault(), IStatus.ERROR, Messages.getString("ChooseTemplatePage.FailedToLoadTemplate"), e)); //$NON-NLS-1$ templateDescriptionText.setText(MessageFormat.format( Messages.getString("ChooseTemplatePage.FailedToLoadTemplateError"), //$NON-NLS-1$ e.getMessage())); } return; } } } templateDescriptionText.setText(""); //$NON-NLS-1$ setSelectedNode(null); selectedTemplate = null; ((TemplateWizard) getWizard()).notifyTemplateChanged(); }
From source file:com.sonatype.buildserver.eclipse.ui.job.view.ScmChangesPage.java
License:Open Source License
protected void populateContextMenu(IMenuManager menuManager) { TreeSelection selection = (TreeSelection) treeViewer.getSelection(); if (selection.isEmpty() || selection.size() > 1) { menuManager.add(openRecent);/*from ww w .j av a 2 s. c o m*/ } else { if (selection.getFirstElement() instanceof ChangeFileDTO) { menuManager.add(openAction); } if (selection.getFirstElement() instanceof BuildDTO) { menuManager.add(openBuildAction); } if (selection.getFirstElement() instanceof ChangeEntryDTO) { menuManager.add(openEntryAction); } } // drillDownAdapter.addNavigationActions( menuManager ); menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); }
From source file:de.defmacro.dandelion.internal.ui.editor.LispEditor.java
License:Open Source License
/** * Listener Implementierung. Nicht aufrufen. *//* w w w . j a v a 2 s . c om*/ public synchronized void selectionChanged(final SelectionChangedEvent event) { //Benutzer hat Knoten in der OutlineView gewaehlt if (event.getSource() == fOutlinePage) { TreeSelection selection = (TreeSelection) event.getSelection(); if (!selection.isEmpty()) { SExpression sexp = (SExpression) selection.getFirstElement(); Position pos = sexp.typeSwitch(HighlightSelectedTypeCase.instanceOf()); if (pos != null) { selectAndReveal(pos.getOffset(), pos.getLength()); } } } }
From source file:ilg.gnuarmeclipse.packs.ui.views.PacksView.java
License:Open Source License
private void makeActions() { fUpdateAction = new Action() { public void run() { // Obtain IServiceLocator implementer, e.g. from // PlatformUI.getWorkbench(): // IServiceLocator serviceLocator = PlatformUI.getWorkbench(); // or a site from within a editor or view: IServiceLocator serviceLocator = getSite(); ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class); try { // Lookup commmand with its ID Command command = commandService.getCommand("ilg.gnuarmeclipse.packs.commands.updateCommand"); // Optionally pass a ExecutionEvent instance, default // no-param arg creates blank event command.executeWithChecks(new ExecutionEvent()); } catch (Exception e) { Activator.log(e); }/*w w w. jav a 2s . c o m*/ } }; fUpdateAction.setText(Messages.PacksView_UpdateAction_text); fUpdateAction.setToolTipText(Messages.PacksView_UpdateAction_toolTipText); fUpdateAction.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/refresh_nav.gif")); // ----- fInstallAction = new Action() { public void run() { // System.out.println("m_installAction.run();"); TreeSelection selection = (TreeSelection) fViewer.getSelection(); if (Activator.getInstance().isDebugging()) { System.out.println(selection); } Job job = new InstallJob("Install Packs", selection); job.schedule(); } }; fInstallAction.setText(Messages.PacksView_InstallAction_text); fInstallAction.setToolTipText(Messages.PacksView_InstallAction_toolTipText); fInstallAction.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/package_mode.png")); fInstallAction.setEnabled(false); // ----- fRemoveAction = new Action() { public void run() { // System.out.println("m_removeAction.run();"); TreeSelection selection = (TreeSelection) fViewer.getSelection(); // System.out.println(selection); Job job = new RemoveJob("Remove Packs", selection); job.schedule(); } }; fRemoveAction.setText(Messages.PacksView_RemoveAction_text); fRemoveAction.setToolTipText(Messages.PacksView_RemoveAction_toolTipText); fRemoveAction.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/removeall.png")); fRemoveAction.setEnabled(false); // ----- fCopyExampleAction = new Action() { public void run() { TreeSelection selection = (TreeSelection) fViewer.getSelection(); if (!selection.isEmpty()) { CopyExampleDialog dlg = new CopyExampleDialog(fComposite.getShell(), selection); if (dlg.open() == Dialog.OK) { String out[] = dlg.getData(); if (checkCopyDestinationFolders(selection, out)) { Job job = new CopyExampleJob("Copy example", selection, out); job.schedule(); } } } } }; fCopyExampleAction.setText("Copy to folder"); // ----- fExpandAll = new Action() { public void run() { fViewer.expandAll(); } }; fExpandAll.setText(Messages.PacksView_ExpandAll_text); fExpandAll.setToolTipText(Messages.PacksView_ExpandAll_toolTipText); fExpandAll.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/expandall.png")); fCollapseAll = new Action() { public void run() { fViewer.collapseAll(); } }; fCollapseAll.setText(Messages.PacksView_CollapseAll_text); fCollapseAll.setToolTipText(Messages.PacksView_CollapseAll_toolTipText); fCollapseAll.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/collapseall.png")); }
From source file:ilg.gnumcueclipse.packs.ui.views.PacksView.java
License:Open Source License
private void makeActions() { fUpdateAction = new Action() { public void run() { // Obtain IServiceLocator implementer, e.g. from // PlatformUI.getWorkbench(): // IServiceLocator serviceLocator = PlatformUI.getWorkbench(); // or a site from within a editor or view: IServiceLocator serviceLocator = getSite(); ICommandService commandService = (ICommandService) serviceLocator.getService(ICommandService.class); try { // Lookup commmand with its ID Command command = commandService.getCommand("ilg.gnumcueclipse.packs.commands.updateCommand"); // Optionally pass a ExecutionEvent instance, default // no-param arg creates blank event command.executeWithChecks(new ExecutionEvent()); } catch (Exception e) { Activator.log(e); }//from www . java 2s. c om } }; fUpdateAction.setText(Messages.PacksView_UpdateAction_text); fUpdateAction.setToolTipText(Messages.PacksView_UpdateAction_toolTipText); fUpdateAction.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/refresh_nav.gif")); // ----- fInstallAction = new Action() { public void run() { // System.out.println("m_installAction.run();"); TreeSelection selection = (TreeSelection) fViewer.getSelection(); if (Activator.getInstance().isDebugging()) { System.out.println(selection); } Job job = new InstallJob("Install Packs", selection); job.schedule(); } }; fInstallAction.setText(Messages.PacksView_InstallAction_text); fInstallAction.setToolTipText(Messages.PacksView_InstallAction_toolTipText); fInstallAction.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/package_mode.png")); fInstallAction.setEnabled(false); // ----- fRemoveAction = new Action() { public void run() { // System.out.println("m_removeAction.run();"); TreeSelection selection = (TreeSelection) fViewer.getSelection(); // System.out.println(selection); Job job = new RemoveJob("Remove Packs", selection); job.schedule(); } }; fRemoveAction.setText(Messages.PacksView_RemoveAction_text); fRemoveAction.setToolTipText(Messages.PacksView_RemoveAction_toolTipText); fRemoveAction.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/removeall.png")); fRemoveAction.setEnabled(false); // ----- fCopyExampleAction = new Action() { public void run() { TreeSelection selection = (TreeSelection) fViewer.getSelection(); if (!selection.isEmpty()) { CopyExampleDialog dlg = new CopyExampleDialog(fComposite.getShell(), selection); if (dlg.open() == Dialog.OK) { String out[] = dlg.getData(); if (checkCopyDestinationFolders(selection, out)) { Job job = new CopyExampleJob("Copy example", selection, out); job.schedule(); } } } } }; fCopyExampleAction.setText("Copy to folder"); // ----- fExpandAll = new Action() { public void run() { fViewer.expandAll(); } }; fExpandAll.setText(Messages.PacksView_ExpandAll_text); fExpandAll.setToolTipText(Messages.PacksView_ExpandAll_toolTipText); fExpandAll.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/expandall.png")); fCollapseAll = new Action() { public void run() { fViewer.collapseAll(); } }; fCollapseAll.setText(Messages.PacksView_CollapseAll_text); fCollapseAll.setToolTipText(Messages.PacksView_CollapseAll_toolTipText); fCollapseAll.setImageDescriptor( Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/collapseall.png")); }
From source file:org.activiti.designer.kickstart.process.dialog.KickstartFormReferenceSelect.java
License:Apache License
@Override protected Control createDialogArea(Composite parent) { Composite area = (Composite) super.createDialogArea(parent); Composite container = new Composite(area, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); GridLayout layout = new GridLayout(1, false); layout.verticalSpacing = 0;/*from w w w. j a v a 2 s .co m*/ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); container.setLayout(layout); Composite topComposite = new Composite(container, SWT.NONE); GridLayout topLayout = new GridLayout(2, false); topLayout.marginTop = 0; topLayout.marginBottom = 0; topComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); topComposite.setLayout(topLayout); Label helpText = new Label(topComposite, SWT.NONE); helpText.setText("Available forms:"); helpText.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); // Create add form button Button addNewFormButton = new Button(topComposite, SWT.PUSH); addNewFormButton.setText("Create new form"); addNewFormButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); // Project tree viewer treeViewer = new TreeViewer(container, SWT.SINGLE | SWT.BORDER); treeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); treeViewer.setContentProvider(new KickstartFormsTreeContentProvider(project)); treeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider()); treeViewer.setInput(ResourcesPlugin.getWorkspace()); // Selection listener for folders treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { TreeSelection selection = (TreeSelection) event.getSelection(); Object[] selectedElements = selection.toArray(); if (selectedElements != null && selectedElements.length > 0) { updateSelection(selectedElements[0]); } } }); treeViewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection != null && !selection.isEmpty()) { updateSelection(selection.getFirstElement()); if (selectedFormFile != null) { okPressed(); } } } }); // Add listener to open wizard to create new form addNewFormButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { IWizardDescriptor descriptor = PlatformUI.getWorkbench().getNewWizardRegistry() .findWizard(NEW_FORM_WIZARD_ID); if (descriptor != null) { try { final INewWizard createWizard = (INewWizard) descriptor.createWizard(); IStructuredSelection structuredSelection = null; if (selectedParent != null) { structuredSelection = new StructuredSelection(selectedParent); } else { structuredSelection = new StructuredSelection(); } // Initialize with the selected folder in the tree, if any createWizard.init(PlatformUI.getWorkbench(), structuredSelection); WizardDialog dialog = new WizardDialog(getShell(), createWizard); dialog.setBlockOnOpen(true); dialog.open(); IFile file = null; if (createWizard instanceof IAdaptable) { file = (IFile) ((IAdaptable) createWizard).getAdapter(IFile.class); } if (file != null) { updateSelection(file); okPressed(); } else { // Best effort to show location of newly created file if (selectedParent != null) { treeViewer.refresh(selectedParent); treeViewer.setSelection(new StructuredSelection(selectedFormFile), true); } else { treeViewer.refresh(); } } } catch (CoreException ce) { Logger.logError("Error while creating new form", ce); } } } }); // Initialize selection, in case a form is already known if (selectedFormFile != null) { treeViewer.setSelection(new StructuredSelection(selectedFormFile)); } return area; }