Java Code Examples for org.eclipse.jface.viewers.IStructuredSelection

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Archimedes, under directory /br.org.archimedes.core/src/br/org/archimedes/gui/rca/.

Source file: InterpreterView.java

  23 
vote

/** 
 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart,org.eclipse.jface.viewers.ISelection)
 */
public void selectionChanged(IWorkbenchPart part,ISelection selection){
  if (StructuredSelection.class.isAssignableFrom(selection.getClass())) {
    IStructuredSelection structuredSelection=(IStructuredSelection)selection;
    try {
      br.org.archimedes.Utils.getInputController().setDrawing((Drawing)structuredSelection.getFirstElement());
    }
 catch (    ClassCastException e) {
    }
  }
}
 

Example 2

From project aws-toolkit-for-eclipse, under directory /com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/explorer/s3/dnd/.

Source file: DownloadDropAssistant.java

  22 
vote

@Override public IStatus handleDrop(CommonDropAdapter aDropAdapter,final DropTargetEvent aDropTargetEvent,Object aTarget){
  if (aDropTargetEvent.data instanceof StructuredSelection) {
    IStructuredSelection s3ObjectSelection=(StructuredSelection)aDropTargetEvent.data;
    return doDrop(aTarget,s3ObjectSelection);
  }
  return Status.OK_STATUS;
}
 

Example 3

From project BHT-FPA, under directory /patterns-codebeispiele/de.bht.fpa.examples.icashbox/src/de/bht/fpa/icashbox/ui/orders/.

Source file: AddProductBtnSelection.java

  22 
vote

@SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e){
  IStructuredSelection selection=(IStructuredSelection)orderView.getProductsComboViewer().getSelection();
  Class<Product> p=(Class<Product>)selection.getFirstElement();
  if (p.equals(Coffee.class)) {
    model.addProduct(new Coffee());
  }
 else   if (p.equals(Tea.class)) {
    model.addProduct(new Tea());
  }
  orderView.getOrderTreeViewer().setInput(model);
}
 

Example 4

From project Bio-PEPA, under directory /uk.ac.ed.inf.common.ui.plotview/src/uk/ac/ed/inf/common/ui/plotview/views/.

Source file: PlotView.java

  22 
vote

public void setSelection(ISelection selection){
  if (selection == null || !(selection instanceof IStructuredSelection) || selection.isEmpty())   return;
  IStructuredSelection structuredSelection=(IStructuredSelection)selection;
  Object chart=structuredSelection.getFirstElement();
  if (!(chart instanceof IChart))   return;
  IChart newSelection=(IChart)chart;
  TabItem item=getTab(newSelection);
  if (item != null) {
    folder.setSelection(item);
    notify(structuredSelection);
  }
}
 

Example 5

From project bioclipse.seneca, under directory /plugins/net.bioclipse.seneca/src/net/bioclipse/seneca/editor/.

Source file: SenecaJobEditor.java

  22 
vote

private void saveSDFile(List<IMolecule> mols,String jobTitle) throws BioclipseException, InvocationTargetException {
  IStructuredSelection virtualselection=new StructuredSelection(net.bioclipse.core.Activator.getVirtualProject());
  String filename=WizardHelper.findUnusedFileName(virtualselection,"Seneca_" + jobTitle,".sdf");
  final IFile sdfile=net.bioclipse.core.Activator.getVirtualProject().getFile(filename);
  net.bioclipse.cdk.business.Activator.getDefault().getJavaCDKManager().saveSDFile(sdfile,mols,new BioclipseUIJob<Void>(){
    @Override public void runInUI(){
      net.bioclipse.ui.business.Activator.getDefault().getUIManager().open(sdfile);
    }
  }
);
}
 

Example 6

From project bndtools, under directory /bndtools.core/src/bndtools/editor/contents/.

Source file: TestSuitesPart.java

  22 
vote

void doRemove(){
  IStructuredSelection sel=(IStructuredSelection)viewer.getSelection();
  if (!sel.isEmpty()) {
    testSuites.removeAll(sel.toList());
    viewer.remove(sel.toArray());
    markDirty();
    validate();
  }
}
 

Example 7

From project bpelunit, under directory /tycho/net.bpelunit.framework.client.eclipse/src/net/bpelunit/framework/client/eclipse/dialog/field/.

Source file: ListField.java

  22 
vote

private String extractSelection(){
  if (fViewer.getSelection() instanceof IStructuredSelection) {
    IStructuredSelection struct=(IStructuredSelection)fViewer.getSelection();
    Object first=struct.getFirstElement();
    if (first != null && first instanceof String)     return (String)first;
  }
  return null;
}
 

Example 8

From project BPMN2-Editor-for-Eclipse, under directory /org.eclipse.bpmn2.modeler.ui/src/org/eclipse/bpmn2/modeler/ui/views/.

Source file: BPMN2ModelView.java

  22 
vote

@Override public void dragStart(DragSourceEvent event){
  if (((IStructuredSelection)viewer.getSelection()).getFirstElement() instanceof TreeObject) {
    IStructuredSelection iStructuredSelection=(IStructuredSelection)viewer.getSelection();
    TreeObject treeObject=(TreeObject)iStructuredSelection.getFirstElement();
    BaseElement baseElement=treeObject.getBaseElement();
    LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(baseElement));
  }
}
 

Example 9

From project bundlemaker, under directory /main/org.bundlemaker.core.ui/src/org/bundlemaker/core/ui/handler/.

Source file: AbstractBundleMakerHandler.java

  22 
vote

/** 
 * Returns all elements in the given  {@link ISelection} that are of the specified type<p> Selected objects in the specified selection that are <em>not</em> instances of the specified type are ignored.
 * @param < T >
 * @param selection The object containing selected objects
 * @param type the expected type of the result objects
 * @return
 */
@SuppressWarnings({"unchecked","rawtypes"}) public static <T>List<T> getSelectedObject(ISelection selection,Class<T> type){
  final List<T> result=new LinkedList<T>();
  if (selection instanceof IStructuredSelection) {
    IStructuredSelection structuredSelection=(IStructuredSelection)selection;
    Iterator iterator=structuredSelection.iterator();
    while (iterator.hasNext()) {
      Object element=iterator.next();
      if (type.isInstance(element)) {
        result.add((T)element);
      }
    }
  }
  return result;
}
 

Example 10

From project ccw, under directory /ccw.core/src/java/ccw/editors/outline/.

Source file: ClojureOutlinePage.java

  22 
vote

private void selectInEditor(ISelection selection){
  IStructuredSelection sel=(IStructuredSelection)selection;
  if (sel.size() == 0)   return;
  Obj obj=(Obj)sel.getFirstElement();
  int lineNr=getLineNr(obj);
  if (lineNr >= 0) {
    ClojureCore.gotoEditorLine(editor,lineNr);
  }
}
 

Example 11

From project ceylon-ide-eclipse, under directory /plugins/com.redhat.ceylon.eclipse.ui/src/com/redhat/ceylon/eclipse/code/explorer/.

Source file: GotoRequiredProjectAction.java

  22 
vote

@Override public void run(){
  IStructuredSelection selection=(IStructuredSelection)fPackageExplorer.getSite().getSelectionProvider().getSelection();
  Object element=selection.getFirstElement();
  if (element instanceof ClassPathContainer.RequiredProjectWrapper) {
    ClassPathContainer.RequiredProjectWrapper wrapper=(ClassPathContainer.RequiredProjectWrapper)element;
    fPackageExplorer.tryToReveal(wrapper.getProject());
  }
}
 

Example 12

From project dawn-common, under directory /org.dawb.common.ui/src/org/dawb/common/ui/project/.

Source file: FolderImportHandler.java

  22 
vote

private void openWizard(){
  final IImportWizard wizard=new FolderLinkWizard();
  final IWorkbench workbench=PlatformUI.getWorkbench();
  final ISelectionService service=workbench.getActiveWorkbenchWindow().getSelectionService();
  final ISelection selection=service.getSelection();
  final IStructuredSelection sel=selection instanceof IStructuredSelection ? (IStructuredSelection)selection : null;
  wizard.init(workbench,sel);
  WizardDialog dialog=new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(),wizard);
  dialog.setBlockOnOpen(true);
  dialog.open();
}
 

Example 13

From project adt-cdt, under directory /com.android.ide.eclipse.adt.cdt/src/com/android/ide/eclipse/adt/cdt/internal/actions/.

Source file: AddNativeAction.java

  21 
vote

@Override public void run(IAction action){
  IProject project=null;
  if (selection != null && selection instanceof IStructuredSelection) {
    IStructuredSelection ss=(IStructuredSelection)selection;
    if (ss.size() == 1) {
      Object obj=ss.getFirstElement();
      if (obj instanceof IProject) {
        project=(IProject)obj;
      }
 else       if (obj instanceof PlatformObject) {
        project=(IProject)((PlatformObject)obj).getAdapter(IProject.class);
      }
    }
  }
  if (project != null) {
    AddNativeWizard wizard=new AddNativeWizard(project,part.getSite().getWorkbenchWindow());
    WizardDialog dialog=new WizardDialog(part.getSite().getShell(),wizard);
    dialog.open();
  }
}
 

Example 14

From project bel-editor, under directory /org.openbel.editor.ui/src/org/openbel/editor/ui/commands/.

Source file: AbstractProjectHandler.java

  21 
vote

@Override public Object execute(ExecutionEvent event) throws ExecutionException {
  IStructuredSelection selection=(IStructuredSelection)HandlerUtil.getCurrentSelection(event);
  Iterator<?> iterator=selection.iterator();
  while (iterator.hasNext()) {
    Object element=iterator.next();
    IProject project=null;
    if (element instanceof IProject) {
      project=(IProject)element;
    }
 else     if (element instanceof IAdaptable) {
      project=(IProject)((IAdaptable)element).getAdapter(IProject.class);
    }
    if (project != null) {
      fettleProject(project);
    }
  }
  return null;
}
 

Example 15

From project bioclipse.speclipse, under directory /plugins/net.bioclipse.bibtex/src/net/bioclipse/bibtex/popup/actions/.

Source file: JabRefAction.java

  21 
vote

public Object execute(ExecutionEvent event) throws ExecutionException {
  try {
    ISelection sel=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
    if (sel.isEmpty() == false) {
      if (sel instanceof IStructuredSelection) {
        IStructuredSelection ssel=(IStructuredSelection)sel;
        String[] args={((IFile)ssel.getFirstElement()).getLocation().toOSString()};
        JabRef.main(args);
      }
    }
  }
 catch (  Exception ex) {
    ex.printStackTrace();
  }
  return null;
}
 

Example 16

From project CIShell, under directory /clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/.

Source file: AbstractDataManagerView.java

  21 
vote

public void setSelection(ISelection selection){
  if (selection != this.selection) {
    this.selection=selection;
    AbstractDataManagerView.this.viewer.refresh(true);
    if ((selection != null) && (selection instanceof IStructuredSelection)) {
      IStructuredSelection selections=(IStructuredSelection)selection;
      Iterator<?> iterator=selections.iterator();
      TreeItem[] newTreeSelection=new TreeItem[selections.size()];
      int i=0;
      while (iterator.hasNext()) {
        Object next=iterator.next();
        if (next instanceof Data) {
          TreeItem result=getTreeItem((Data)next,AbstractDataManagerView.this.tree.getItems());
          newTreeSelection[i]=result;
          AbstractDataManagerView.this.viewer.expandToLevel(AbstractDataManagerView.this.dataToDataGUIItem.get(next),0);
        }
        i++;
      }
      AbstractDataManagerView.this.tree.setSelection(newTreeSelection);
    }
    Iterator<ISelectionChangedListener> listenerIterator=listeners.iterator();
    while (listenerIterator.hasNext()) {
      ISelectionChangedListener listener=listenerIterator.next();
      SelectionChangedEvent event=new SelectionChangedEvent(this,selection);
      listener.selectionChanged(event);
    }
  }
}
 

Example 17

From project acceleo-modules, under directory /psm-gen-scala/plugins/com.github.sbegaudeau.acceleo.modules.psm.gen.scala.editor/src-gen/com/github/sbegaudeau/acceleo/modules/psm/gen/scala/model/scala/presentation/.

Source file: ScalaActionBarContributor.java

  19 
vote

/** 
 * This implements  {@link org.eclipse.jface.viewers.ISelectionChangedListener}, handling  {@link org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for the children and siblings that can be added to the selected object and updating the menus accordingly. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public void selectionChanged(SelectionChangedEvent event){
  if (createChildMenuManager != null) {
    depopulateManager(createChildMenuManager,createChildActions);
  }
  if (createSiblingMenuManager != null) {
    depopulateManager(createSiblingMenuManager,createSiblingActions);
  }
  Collection<?> newChildDescriptors=null;
  Collection<?> newSiblingDescriptors=null;
  ISelection selection=event.getSelection();
  if (selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1) {
    Object object=((IStructuredSelection)selection).getFirstElement();
    EditingDomain domain=((IEditingDomainProvider)activeEditorPart).getEditingDomain();
    newChildDescriptors=domain.getNewChildDescriptors(object,null);
    newSiblingDescriptors=domain.getNewChildDescriptors(null,object);
  }
  createChildActions=generateCreateChildActions(newChildDescriptors,selection);
  createSiblingActions=generateCreateSiblingActions(newSiblingDescriptors,selection);
  if (createChildMenuManager != null) {
    populateManager(createChildMenuManager,createChildActions,null);
    createChildMenuManager.update(true);
  }
  if (createSiblingMenuManager != null) {
    populateManager(createSiblingMenuManager,createSiblingActions,null);
    createSiblingMenuManager.update(true);
  }
}
 

Example 18

From project acceleo-webapp-generator, under directory /plugins/org.eclipse.acceleo.tutorial.webapp.editor/src-gen/org/eclipse/acceleo/tutorial/webapp/presentation/.

Source file: WebappActionBarContributor.java

  19 
vote

/** 
 * This implements  {@link org.eclipse.jface.viewers.ISelectionChangedListener}, handling  {@link org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for the children and siblings that can be added to the selected object and updating the menus accordingly. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public void selectionChanged(SelectionChangedEvent event){
  if (createChildMenuManager != null) {
    depopulateManager(createChildMenuManager,createChildActions);
  }
  if (createSiblingMenuManager != null) {
    depopulateManager(createSiblingMenuManager,createSiblingActions);
  }
  Collection<?> newChildDescriptors=null;
  Collection<?> newSiblingDescriptors=null;
  ISelection selection=event.getSelection();
  if (selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1) {
    Object object=((IStructuredSelection)selection).getFirstElement();
    EditingDomain domain=((IEditingDomainProvider)activeEditorPart).getEditingDomain();
    newChildDescriptors=domain.getNewChildDescriptors(object,null);
    newSiblingDescriptors=domain.getNewChildDescriptors(null,object);
  }
  createChildActions=generateCreateChildActions(newChildDescriptors,selection);
  createSiblingActions=generateCreateSiblingActions(newSiblingDescriptors,selection);
  if (createChildMenuManager != null) {
    populateManager(createChildMenuManager,createChildActions,null);
    createChildMenuManager.update(true);
  }
  if (createSiblingMenuManager != null) {
    populateManager(createSiblingMenuManager,createSiblingActions,null);
    createSiblingMenuManager.update(true);
  }
}
 

Example 19

From project bioclipse.opentox, under directory /plugins/net.bioclipse.opentox.ui/src/net/bioclipse/opentox/ui/handlers/.

Source file: CreateDatasetHandler.java

  19 
vote

@Override public Object execute(ExecutionEvent event) throws ExecutionException {
  ISelection sel=HandlerUtil.getCurrentSelection(event);
  if (sel.isEmpty())   return null;
  if (!(sel instanceof IStructuredSelection))   return null;
  Object obj=((IStructuredSelection)sel).getFirstElement();
  if (!(obj instanceof IFile))   return null;
  IFile file=(IFile)obj;
  try {
    CreateDatasetWizard wiz=new CreateDatasetWizard(file);
    WizardDialog dialog=new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),wiz);
    dialog.open();
  }
 catch (  Exception e) {
    e.printStackTrace();
    throw new RuntimeException(e.getMessage());
  }
  return null;
}
 

Example 20

From project CBCJVM, under directory /eclipse/src/cbclipse/builder/.

Source file: ToggleNatureAction.java

  19 
vote

@SuppressWarnings("unchecked") public void run(IAction action){
  if (selection instanceof IStructuredSelection) {
    for (Iterator it=((IStructuredSelection)selection).iterator(); it.hasNext(); ) {
      Object element=it.next();
      IProject project=null;
      if (element instanceof IProject) {
        project=(IProject)element;
      }
 else       if (element instanceof IAdaptable) {
        project=(IProject)((IAdaptable)element).getAdapter(IProject.class);
      }
      if (project != null) {
        toggleNature(project);
      }
    }
  }
}
 

Example 21

From project Database-Designer, under directory /plugins/org.obeonetwork.dsl.database.editor/src/org/obeonetwork/dsl/database/presentation/.

Source file: DatabaseActionBarContributor.java

  19 
vote

/** 
 * This implements  {@link org.eclipse.jface.viewers.ISelectionChangedListener}, handling  {@link org.eclipse.jface.viewers.SelectionChangedEvent}s by querying for the children and siblings that can be added to the selected object and updating the menus accordingly. <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public void selectionChanged(SelectionChangedEvent event){
  if (createChildMenuManager != null) {
    depopulateManager(createChildMenuManager,createChildActions);
  }
  if (createSiblingMenuManager != null) {
    depopulateManager(createSiblingMenuManager,createSiblingActions);
  }
  Collection<?> newChildDescriptors=null;
  Collection<?> newSiblingDescriptors=null;
  ISelection selection=event.getSelection();
  if (selection instanceof IStructuredSelection && ((IStructuredSelection)selection).size() == 1) {
    Object object=((IStructuredSelection)selection).getFirstElement();
    EditingDomain domain=((IEditingDomainProvider)activeEditorPart).getEditingDomain();
    newChildDescriptors=domain.getNewChildDescriptors(object,null);
    newSiblingDescriptors=domain.getNewChildDescriptors(null,object);
  }
  createChildActions=generateCreateChildActions(newChildDescriptors,selection);
  createSiblingActions=generateCreateSiblingActions(newSiblingDescriptors,selection);
  if (createChildMenuManager != null) {
    populateManager(createChildMenuManager,createChildActions,null);
    createChildMenuManager.update(true);
  }
  if (createSiblingMenuManager != null) {
    populateManager(createSiblingMenuManager,createSiblingActions,null);
    createSiblingMenuManager.update(true);
  }
}