org.eclipse.jface.viewers.ITreeSelection Java Examples

The following examples show how to use org.eclipse.jface.viewers.ITreeSelection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReferenceSearchViewPageActions.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	TreeViewer viewer = page.getViewer();
	ITreeSelection selection = viewer.getStructuredSelection();
	ReferenceSearchViewTreeNode[] removedNodes = Iterables.toArray(
			Iterables.filter(selection.toList(), ReferenceSearchViewTreeNode.class),
			ReferenceSearchViewTreeNode.class);
	page.getContentProvider().remove(removedNodes);
	
	if (searchResult instanceof ReferenceSearchResult) {
		List<IReferenceDescription> descriptions = new ArrayList<IReferenceDescription>();
		IAcceptor<IReferenceDescription> acceptor = CollectionBasedAcceptor.of(descriptions);
		for (ReferenceSearchViewTreeNode removedNode : removedNodes) {
			removedNode.collectReferenceDescriptions(acceptor);
		}
		IReferenceDescription[] descriptionsArray = descriptions.toArray(new IReferenceDescription[descriptions.size()]);
		((ReferenceSearchResult) searchResult).remove(descriptionsArray);
	}
	viewer.refresh();
}
 
Example #2
Source File: LogContent.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void copyTreeSelectionToClipboard() {
  ITreeSelection selection = (ITreeSelection) treeViewer.getSelection();
  TreePath[] paths = selection.getPaths();

  StringBuffer buf = new StringBuffer();

  for (TreePath path : paths) {
    LogEntry<?> entry = (LogEntry<?>) path.getLastSegment();
    buf.append(createTabString(path.getSegmentCount() - 1));
    buf.append(entry.toString());
    buf.append("\n");
  }

  if (buf.length() > 0) {
    buf.deleteCharAt(buf.length() - 1); // take off last \n
  }

  copyToClipboard(buf.toString());
}
 
Example #3
Source File: QuickOutline.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
protected void handleSelection() {
    ITreeSelection selection = (ITreeSelection) treeViewer.getSelection();

    if (selection != null) {
        Object element = selection.getFirstElement();

        if (element instanceof AbstractNode) {
            Model model = ((AbstractNode) element).getModel();

            if (model.getPath() != null) {
                DocumentUtils.openAndReveal(model.getPath(), selection);
            } else {
                editor.show(new ShowInContext(null, selection));
            }
        }
    }
}
 
Example #4
Source File: ThrowEventSection.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 *
 */
private void updateButtons() {
    final ITreeSelection selection = (ITreeSelection)filteredTree.getViewer().getSelection();
    if(!removeEventButton.isDisposed()) {
        removeEventButton.setEnabled(selection.size() > 0);
    }

    if(!updateEventButton.isDisposed()) {
        updateEventButton.setEnabled(selection.size() == 1);
    }

    if(eObject instanceof SendTask){
        if(!addEventButton.isDisposed()) {
            addEventButton.setEnabled(((SendTask) eObject).getEvents().isEmpty());
        }
    }

}
 
Example #5
Source File: WorkingSetDropAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void performElementRearrange(int eventDetail) {
	// only move if target isn't the other working set. If this is the case
	// the move will happenn automatically by refreshing the other working set
	if (!isOthersWorkingSet(fWorkingSet)) {
		List<Object> elements= new ArrayList<Object>(Arrays.asList(fWorkingSet.getElements()));
		elements.addAll(Arrays.asList(fElementsToAdds));
		fWorkingSet.setElements(elements.toArray(new IAdaptable[elements.size()]));
	}
	if (eventDetail == DND.DROP_MOVE) {
		ITreeSelection treeSelection= (ITreeSelection)fSelection;
		Map<IWorkingSet, List<Object>> workingSets= groupByWorkingSets(treeSelection.getPaths());
		for (Iterator<IWorkingSet> iter= workingSets.keySet().iterator(); iter.hasNext();) {
			IWorkingSet ws= iter.next();
			List<Object> toRemove= workingSets.get(ws);
			List<IAdaptable> currentElements= new ArrayList<IAdaptable>(Arrays.asList(ws.getElements()));
			currentElements.removeAll(toRemove);
			ws.setElements(currentElements.toArray(new IAdaptable[currentElements.size()]));
		}
	}
}
 
Example #6
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
private static IWorkingSet[] getSelectedWorkingSet(ITreeSelection treeSelection) {
	assert !treeSelection.isEmpty();
	final List<?> elements = treeSelection.toList();
	if (elements.size() == 1) {
		final Object element = elements.get(0);
		final TreePath[] paths = treeSelection.getPathsFor(element);
		if (paths.length == 1
				&& paths[0].getSegmentCount() != 0) {
			final Object candidate = paths[0].getSegment(0);
			if (candidate instanceof IWorkingSet
					&& isValidWorkingSet((IWorkingSet) candidate)) {
				return new IWorkingSet[] {(IWorkingSet) candidate};
			}
		}
	} else {
		final List<IWorkingSet> result = new ArrayList<>();
		for (Iterator<?> iterator = elements.iterator(); iterator.hasNext();) {
			final Object element = iterator.next();
			if (element instanceof IWorkingSet && isValidWorkingSet((IWorkingSet) element)) {
				result.add((IWorkingSet) element);
			}
		}
		return result.toArray(new IWorkingSet[result.size()]);
	}
	return EMPTY_WORKING_SET_ARRAY;
}
 
Example #7
Source File: ICEMeshPage.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This operation overrides the default/abstract implementation of
 * ISelectionListener.selectionChanged to capture selections made in the
 * MeshElementTreeView and highlight the corresponding element in the jME3
 * canvas.
 * 
 * @param part
 *            The IWorkbenchPart that called this function.
 * @param selection
 *            The ISelection chosen in the part parameter.
 */
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {

	// Get the selection made in the MeshElementTreeView.
	if (part.getSite().getId().equals(MeshElementTreeView.ID)
			&& canvas != null) {

		// Get the array of all selections in the Mesh Elements view
		Object[] treeSelections = ((ITreeSelection) selection).toArray();

		// Set the canvas's selection to match the selection from the tree
		canvas.setSelection(treeSelections);
	}

	return;
}
 
Example #8
Source File: ActorMappingConfigurationWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void doubleClick(final DoubleClickEvent event) {
    final TreePath treePath = ((ITreeSelection) event.getSelection()).getPaths()[0];
    for (int i = treePath.getSegmentCount() - 1; i >= 0; i--) {
        final Object selection = treePath.getSegment(i);
        if (selection instanceof Users) {
            userAction();
        } else if (selection instanceof Membership) {
            membershipAction();
        } else if (selection instanceof Groups) {
            groupAction();
        } else if (selection instanceof Roles) {
            roleAction();
        }

    }
}
 
Example #9
Source File: ServerView.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * Return the currently selected server (null if there is no selection or
 * if the selection is not a server)
 * 
 * @return the currently selected server entry
 */
public HadoopServer getSelectedServer() {
  ITreeSelection selection = (ITreeSelection) viewer.getSelection();
  Object first = selection.getFirstElement();
  if (first instanceof HadoopServer) {
    return (HadoopServer) first;
  }
  return null;
}
 
Example #10
Source File: ReferenceSearchViewPageActions.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run() {
	TreeViewer viewer = page.getViewer();
	Clipboard clipboard = new Clipboard(viewer.getControl().getDisplay());
	
	ITreeSelection selection = page.getViewer().getStructuredSelection();
	@SuppressWarnings("unchecked")
	Object data = selection.toList().stream()
		.map(sel -> page.getLabelProvider().getText(sel))
		.collect(joining(System.lineSeparator()));
	clipboard.setContents(new Object[] {data}, new Transfer[]{TextTransfer.getInstance()});
	clipboard.dispose();
}
 
Example #11
Source File: JavaSetterOperatorEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean isSetterOrDataSelected(final ITreeSelection selection) {
    if (selection.getFirstElement() instanceof IMethod) {
        final IMethod method = (IMethod) selection.getFirstElement();
        try {
            return method.getParameterNames().length == 1;
        } catch (final Exception ex) {
            BonitaStudioLog.error(ex);
            return false;
        }
    } else if (selection.getFirstElement() instanceof String) {
        return true;
    } else {
        return false;
    }
}
 
Example #12
Source File: JavaSetterOperatorEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected String generateJavaAdditionalPath(final ITreeSelection selection) {
    if (selection == null) {
        return "";
    }
    final TreePath path = selection.getPaths()[0];
    if (path.getSegmentCount() == 1) {
        return "";
    }
    final StringBuilder res = new StringBuilder();
    final Object item = path.getSegment(path.getSegmentCount() - 1);
    res.append(((IJavaElement) item).getElementName());
    return res.toString();
}
 
Example #13
Source File: ThrowEventSection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 *
 */
private void updateEventAction() {
    final ITreeSelection selection = (ITreeSelection)filteredTree.getViewer().getSelection();
    if (selection.size() == 1) {
        new WizardDialog(Display.getCurrent().getActiveShell(),
                createMessageEventWizard(ModelHelper.getMainProcess(getEObject()),(Message)selection.getFirstElement())).open();
        refresh();


    }
}
 
Example #14
Source File: XPathExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static String computeXPath(final ITreeSelection selection, final boolean useQualifiedName) {
    if (selection.getPaths().length == 0) {
        return "";
    }

    final TreePath path = selection.getPaths()[0];
    return computeXPath(path, useQualifiedName);
}
 
Example #15
Source File: XPathOperatorEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected String computeXPath(ITreeSelection selection, boolean useQualifiedName) {
    if (selection.getPaths().length == 0) {
        return "";
    }

    TreePath path = selection.getPaths()[0];
    return computeXPath(path, useQualifiedName);
}
 
Example #16
Source File: SelectPathDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param selection
 * @param useQualifiedName TODO
 * @return
 */
public static String computeXPath(ITreeSelection selection, boolean useQualifiedName) {
	if (selection.getPaths().length == 0) {
		return "";
	}
	
	TreePath path = selection.getPaths()[0];
	return computeXPath(path, useQualifiedName);
}
 
Example #17
Source File: ProjectResourceControl.java    From depan with Apache License 2.0 5 votes vote down vote up
public IContainer getSelectedContainer() {
  ITreeSelection blix = containerViewer.getStructuredSelection();
  Object item = blix.getFirstElement();
  if (item instanceof IContainer) {
    return (IContainer) item;
  }
  return null;
}
 
Example #18
Source File: ServerView.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Return the currently selected server (null if there is no selection or
 * if the selection is not a server)
 * 
 * @return the currently selected server entry
 */
public HadoopServer getSelectedServer() {
  ITreeSelection selection = (ITreeSelection) viewer.getSelection();
  Object first = selection.getFirstElement();
  if (first instanceof HadoopServer) {
    return (HadoopServer) first;
  }
  return null;
}
 
Example #19
Source File: ProjectResourceControl.java    From depan with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public T getSelectedResource() {
  ITreeSelection blix = containerViewer.getStructuredSelection();
  Object item = blix.getFirstElement();
  if (item instanceof PropertyDocument<?>) {
    return (T) item;
  }
  return null;
}
 
Example #20
Source File: ProjectResourceControl.java    From depan with Apache License 2.0 5 votes vote down vote up
public IFile getSelectedDocument() {
  ITreeSelection blix = containerViewer.getStructuredSelection();
  Object item = blix.getFirstElement();
  if (item instanceof IFile) {
    return (IFile) item;
  }
  return null;
}
 
Example #21
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static IWorkingSet[] getSelectedWorkingSet(IStructuredSelection selection) {
	IWorkingSet[] workingSet = EMPTY_WORKING_SET_ARRAY;

	if (selection instanceof ITreeSelection) {
		final ITreeSelection treeSelection = (ITreeSelection) selection;
		if (!treeSelection.isEmpty()) {
			workingSet = getSelectedWorkingSet(treeSelection);
		}
	}
	return workingSet;
}
 
Example #22
Source File: TreeNavigationView.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public TreeNavigationView(Composite parent, int style) {
  super(parent, style);
  setLayout(new FillLayout(SWT.VERTICAL));

  sashForm = new SashForm(this, SWT.HORIZONTAL);
  contentTypes = new TreeViewer(sashForm);
  contentTypes.addSelectionChangedListener(new ISelectionChangedListener() {
    public void selectionChanged(SelectionChangedEvent event) {
      fireSelectionChangedEvent(event);
      
      Object contentPanelSelection = null;
      ISelection selection = contentTypes.getSelection();
      if (selection != null && !selection.isEmpty()) {
        contentPanelSelection = ((ITreeSelection) selection).getFirstElement();
      }
      
      contentPanel.setSelection(contentPanelSelection);
    }
  });
  
  contentPanel = new ContentPanel(sashForm, SWT.NONE);

  contentTypes.setComparator(new ModelNodeViewerComparator());
  sashForm.setWeights(new int[] {20, 80});
  contentTypes.setLabelProvider(new ModelLabelProvider());
  contentTypes.setContentProvider(new TreeContentProvider());
  contentTypes.getTree().addKeyListener(
      new EnterKeyTreeToggleKeyAdapter(contentTypes));
}
 
Example #23
Source File: PackageExplorerActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
void handleDoubleClick(DoubleClickEvent event) {
	TreeViewer viewer= fPart.getTreeViewer();
	IStructuredSelection selection= (IStructuredSelection)event.getSelection();
	Object element= selection.getFirstElement();
	if (viewer.isExpandable(element)) {
		if (doubleClickGoesInto()) {
			// don't zoom into compilation units and class files
			if (element instanceof ICompilationUnit || element instanceof IClassFile)
				return;
			if (element instanceof IOpenable || element instanceof IContainer || element instanceof IWorkingSet) {
				fZoomInAction.run();
			}
		} else {
			IAction openAction= fNavigateActionGroup.getOpenAction();
			if (openAction != null && openAction.isEnabled() && OpenStrategy.getOpenMethod() == OpenStrategy.DOUBLE_CLICK)
				return;
			if (selection instanceof ITreeSelection) {
				TreePath[] paths= ((ITreeSelection)selection).getPathsFor(element);
				for (int i= 0; i < paths.length; i++) {
					viewer.setExpandedState(paths[i], !viewer.getExpandedState(paths[i]));
				}
			} else {
				viewer.setExpandedState(element, !viewer.getExpandedState(element));
			}
		}
	} else if (element instanceof IProject && !((IProject) element).isOpen()) {
		OpenProjectAction openProjectAction= fProjectActionGroup.getOpenProjectAction();
		if (openProjectAction.isEnabled()) {
			openProjectAction.run();
		}
	}
}
 
Example #24
Source File: UserLibraryPreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private IPath getWorkbenchWindowSelection() {
	IWorkbenchWindow window= fWorkbench.getActiveWorkbenchWindow();
	if (window != null) {
		ISelection selection= window.getSelectionService().getSelection();
		if (selection instanceof IStructuredSelection) {
			IStructuredSelection structuredSelection= (IStructuredSelection) selection;
			Object element= structuredSelection.getFirstElement();
			if (element != null) {
				Object resource= Platform.getAdapterManager().getAdapter(element, IResource.class);
				if (resource != null) {
					return ((IResource) resource).getFullPath();
				}
				if (structuredSelection instanceof ITreeSelection) {
					TreePath treePath= ((ITreeSelection) structuredSelection).getPaths()[0];
					while ((treePath = treePath.getParentPath()) != null) {
						element= treePath.getLastSegment();
						resource= Platform.getAdapterManager().getAdapter(element, IResource.class);
						if (resource != null) {
							return ((IResource) resource).getFullPath();
						}
					}
				}
			}
			
		}
	}
	return null;
}
 
Example #25
Source File: ActorMappingConfigurationWizardPage.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private ActorMapping getSelectedActor() {
    final TreePath treePath = ((ITreeSelection) mappingTree.getSelection()).getPaths()[0];
    return (ActorMapping) treePath.getFirstSegment();
}
 
Example #26
Source File: JavaSetterOperatorEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean canFinish() {
    return isSetterOrDataSelected((ITreeSelection) javaTreeviewer.getSelection());
}
 
Example #27
Source File: JavaExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected void createBrowseJavaObjectForReadExpression(final Composite composite) {
    final Composite res = new Composite(composite, SWT.NONE);
    res.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    res.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).spacing(LayoutConstants.getSpacing().x, 0).create());

    final Label label = new Label(res, SWT.NONE);
    label.setText(Messages.browseJava);
    javaTreeviewer = new TreeViewer(res, SWT.SINGLE | SWT.BORDER);
    javaTreeviewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    javaTreeviewer.setLabelProvider(new JavaUILabelProvider() {

        @Override
        public String getText(final Object item) {
            if (item instanceof IMethod) {
                try {
                    return super.getText(item) + " - " + toQualifiedName(item);
                } catch (final JavaModelException e) {
                    BonitaStudioLog.error(e);
                    return null;
                }
            } else {
                return super.getText(item);
            }
        }

    });

    javaTreeviewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ITreeSelection selection = (ITreeSelection) event.getSelection();
            if (!selection.isEmpty()) {
                JavaExpressionEditor.this.fireSelectionChanged();
                javaTreeviewer.getTree().setFocus();
            }
        }

    });

    javaTreeviewer.getTree().setEnabled(false);
}
 
Example #28
Source File: BrowseWriteToJavaDialog.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Control createDialogArea(Composite parent) {
	Composite res = (Composite) super.createDialogArea(parent);
	
	if (type == null) {
		try {
			type = RepositoryManager.getInstance().getCurrentRepository().getJavaProject().findType(className);
		} catch (JavaModelException e1) {
			BonitaStudioLog.error(e1) ;
		}
	}
	
	Label label = new Label(res, SWT.NONE);
	label.setText(Messages.browseJava);
	viewer = new TreeViewer(res, SWT.SINGLE | SWT.BORDER);
	viewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 300).create());
	//provider = new PojoWriteBrowserContentProvider();
//	viewer.setContentProvider(provider);
	viewer.setLabelProvider(new JavaUILabelProvider() {
		@Override
		public String getText(Object item) {
			if (item instanceof String) {
				return (String)item;
			} else {
				return super.getText(item);
			}
		}
	});
	viewer.addSelectionChangedListener(new ISelectionChangedListener() {
		public void selectionChanged(SelectionChangedEvent event) {
			selection = (ITreeSelection) event.getSelection();
			if (getButton(OK) != null) {
				getButton(OK).setEnabled(isSetterOrDataSelected());
			}
		}

	});
	viewer.setInput(new Object());
//	viewer.setSelection(new StructuredSelection(provider.getElements(new Object()))) ;
	return res;
}
 
Example #29
Source File: XPathExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void createXPathChooser(final Composite parent) {
    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    final GridLayout gl = new GridLayout(1, false);
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    composite.setLayout(gl);
    final Label label = new Label(composite, SWT.WRAP);
    label.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 30).create());
    label.setText(Messages.selectElementLabel);

    xsdViewer = new TreeViewer(composite);
    provider = new XSDContentProvider(true);
    xsdViewer.setComparer(new IElementComparer() {

        @Override
        public int hashCode(final Object element) {
            return element.hashCode();
        }

        @Override
        public boolean equals(final Object a, final Object b) {
            if (a instanceof XSDFeature && b instanceof XSDFeature) {
                final String aName = ((XSDFeature) a).getName();
                final String bName = ((XSDFeature) b).getName();
                if (aName.equals(bName)) {
                    return EcoreUtil.equals(((XSDFeature) a).getType(), ((XSDFeature) b).getType());
                }
            }
            return a.equals(b);
        }
    });
    xsdViewer.setContentProvider(provider);
    final XSDLabelProvider labelProvider = new XSDLabelProvider();
    xsdViewer.setLabelProvider(new DecoratingLabelProvider(labelProvider, labelProvider));
    final GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.minimumHeight = 100;
    xsdViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 150).create());
    xsdViewer.setInput(new Object());

    text = new Text(composite, SWT.WRAP | SWT.BORDER);
    text.setLayoutData(GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 40).create());

    xsdViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ITreeSelection selection = (ITreeSelection) xsdViewer.getSelection();
            //                final String xpath = computeXPath(selection, false);
            //                if (dataName != null) {
            //                    if (xpath == null || xpath.isEmpty()) {
            //                        text.setText(dataName);
            //                    } else {
            //                        text.setText(xpath);
            //                    }
            //                }
            text.redraw();
            //                typeCombo.setSelection(new StructuredSelection(XPathReturnType.getType(selection.getFirstElement())));
            XPathExpressionEditor.this.fireSelectionChanged();
        }
    });

}
 
Example #30
Source File: XPathOperatorEditor.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected String computeXPath(ITreeSelection selection) {
    return computeXPath(selection, false);
}