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

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 aws-toolkit-for-eclipse, under directory /com.amazonaws.eclipse.elasticbeanstalk/src/com/amazonaws/eclipse/elasticbeanstalk/ui/menu/.

Source file: DeployToElasticBeanstalkHandler.java

  22 
vote

public Object execute(ExecutionEvent event) throws ExecutionException {
  ISelection selection=HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
  if (selection != null & selection instanceof IStructuredSelection) {
    IStructuredSelection structurredSelection=(IStructuredSelection)selection;
    new RunOnServerAction(structurredSelection.getFirstElement()).run();
  }
  return null;
}
 

Example 2

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

Source file: NewSenecaJobWizard.java

  22 
vote

/** 
 * Adding the pages to the wizard.
 */
public void addPages(){
  ISelection sel=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
  if (sel instanceof IStructuredSelection) {
    selectFilePage=new WizardNewFileCreationPage("newfile",(IStructuredSelection)sel);
    selectFilePage.setFileName(WizardHelper.findUnusedFileName((IStructuredSelection)sel,"unnamed",""));
  }
 else {
    selectFilePage=new WizardNewFileCreationPage("newfile",StructuredSelection.EMPTY);
  }
  selectFilePage.setTitle("Choose name and location for new CASE project");
  selectFilePage.setDescription("Extension will be set to .sjs");
  addPage(selectFilePage);
}
 

Example 3

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

Source file: NewBibtexWizard.java

  22 
vote

/** 
 * Adding the page to the wizard.
 */
public void addPages(){
  ISelection sel=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
  if (sel instanceof IStructuredSelection) {
    filePage=new NewBibtexFileWizardPage((IStructuredSelection)sel);
    filePage.setFileName(WizardHelper.findUnusedFileName((IStructuredSelection)sel,"unnamed",".bib"));
  }
 else {
    filePage=new NewBibtexFileWizardPage(StructuredSelection.EMPTY);
  }
  addPage(filePage);
}
 

Example 4

From project bndtools, under directory /bndtools.core/src/bndtools/utils/.

Source file: SelectionDragAdapter.java

  22 
vote

public void dragStart(DragSourceEvent event){
  ISelection selection=viewer.getSelection();
  LocalSelectionTransfer.getTransfer().setSelection(selection);
  LocalSelectionTransfer.getTransfer().setSelectionSetTime(event.time & 0xFFFFFFFFL);
  event.doit=!selection.isEmpty();
}
 

Example 5

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

Source file: BPELUnitView.java

  22 
vote

public void selectionChanged(SelectionChangedEvent event){
  ISelection selection=event.getSelection();
  if (selection instanceof IStructuredSelection) {
    Object o=((IStructuredSelection)selection).getFirstElement();
    if (o instanceof ITestArtefact)     handleSelected((ITestArtefact)o);
  }
}
 

Example 6

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

Source file: ImprovedAdvancedPropertiesComposite.java

  22 
vote

private EObject getSelectedBaseElement(){
  ISelection selection=treeViewer.getSelection();
  EObject baseElement=null;
  if (selection instanceof IStructuredSelection) {
    Object firstElement=((IStructuredSelection)selection).getFirstElement();
    if (firstElement instanceof EObject) {
      baseElement=(EObject)firstElement;
    }
  }
  return baseElement;
}
 

Example 7

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

Source file: AbstractBundleMakerHandler.java

  22 
vote

@Override public Object execute(ExecutionEvent event) throws ExecutionException {
  ISelection selection=HandlerUtil.getCurrentSelection(event);
  if (selection != null) {
    try {
      execute(event,selection);
    }
 catch (    Exception ex) {
      reportError(Activator.PLUGIN_ID,"Error while executing command: " + ex,ex);
      throw new ExecutionException("Error while executing command: " + ex,ex);
    }
  }
  return null;
}
 

Example 8

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

Source file: ClojureOutlinePage.java

  22 
vote

public void selectionChanged(SelectionChangedEvent event){
  ISelection selection=event.getSelection();
  if (isActivePart()) {
    selectInEditor(selection);
  }
}
 

Example 9

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

Source file: WorkingSetDropAdapter.java

  22 
vote

/** 
 * {@inheritDoc}
 */
public boolean isEnabled(DropTargetEvent event){
  Object target=event.item != null ? event.item.getData() : null;
  if (target == null)   return false;
  ISelection selection=LocalSelectionTransfer.getInstance().getSelection();
  if (!isValidSelection(selection)) {
    return false;
  }
  if (!isValidTarget(target))   return false;
  initializeState(target,selection);
  return true;
}
 

Example 10

From project cilia-workbench, under directory /cilia-workbench-common/src/fr/liglab/adele/cilia/workbench/common/ui/view/graphview/.

Source file: GraphView.java

  22 
vote

public Object getFirstSelectedElement(){
  ISelectionService selServ=getSite().getWorkbenchWindow().getSelectionService();
  ISelection sel=selServ.getSelection();
  if (sel != null && sel instanceof StructuredSelection) {
    StructuredSelection ss=(StructuredSelection)sel;
    return ss.getFirstElement();
  }
  return null;
}
 

Example 11

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 12

From project dawn-isenciaui, under directory /com.isencia.passerelle.workbench.model.editor.ui/src/main/java/com/isencia/passerelle/workbench/model/editor/ui/dnd/.

Source file: FileTransferDropTargetListener.java

  22 
vote

private IResource getSelected(){
  final ISelection sel=EclipseUtils.getPage().getSelection();
  if (!(sel instanceof IStructuredSelection))   return null;
  final IStructuredSelection ss=(IStructuredSelection)sel;
  final Object element=ss.getFirstElement();
  if (element instanceof IResource) {
    return (IResource)element;
  }
  if (element instanceof IContributorResourceAdapter) {
    return ((IContributorResourceAdapter)element).getAdaptedResource((IAdaptable)element);
  }
  return null;
}
 

Example 13

From project dawn-ui, under directory /org.dawb.workbench.convert/src/org/edna/workbench/actions/.

Source file: ConvertWizardHandler.java

  22 
vote

public boolean isEnabled(){
  final ISelection selection=EclipseUtils.getActivePage().getSelection();
  if (selection instanceof StructuredSelection) {
    StructuredSelection s=(StructuredSelection)selection;
    final Object o=s.getFirstElement();
    if (o instanceof IFile)     return true;
  }
  return false;
}
 

Example 14

From project dawn-workflow, under directory /org.dawb.passerelle.actors/src/org/dawb/passerelle/editors/.

Source file: UserModifyComposite.java

  22 
vote

public void run(){
  final ISelection sel=tableViewer.getSelection();
  if (sel != null && sel instanceof StructuredSelection) {
    final Map.Entry<String,String> entry=(Map.Entry<String,String>)((StructuredSelection)sel).getFirstElement();
    if (entry != null) {
      values.remove(entry.getKey());
      tableViewer.refresh();
    }
  }
}
 

Example 15

From project Diver, under directory /ca.uvic.chisel.javasketch/src/ca/uvic/chisel/javasketch/persistence/ui/internal/.

Source file: FiltersComposite.java

  22 
vote

@Override public void widgetSelected(SelectionEvent e){
  ISelection s=viewer.getSelection();
  TreeSet<String> input=new TreeSet<String>(Arrays.asList((String[])viewer.getInput()));
  if (s instanceof IStructuredSelection) {
    Iterator<?> i=((IStructuredSelection)s).iterator();
    while (i.hasNext()) {
      input.remove(i.next());
    }
  }
  viewer.setInput(input.toArray(new String[input.size()]));
  if (parentContext != null) {
    parentContext.filterChanged();
  }
}
 

Example 16

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

  21 
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 17

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

  21 
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 bel-editor, under directory /org.openbel.editor.ui/src/org/openbel/editor/ui/views/.

Source file: ResourceView.java

  21 
vote

private void makeActions(){
  action1=new Action(){
    @Override public void run(){
      System.out.println("Unbound \"Action 1\" action.");
      System.out.println(StackUtilities.myFrame());
    }
  }
;
  action1.setText("Action 1");
  action1.setToolTipText("Action 1 tooltip");
  action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
  action2=new Action(){
    @Override public void run(){
      System.out.println("Unbound \"Action 2\" action.");
      System.out.println(StackUtilities.myFrame());
    }
  }
;
  action2.setText("Action 2");
  action2.setToolTipText("Action 2 tooltip");
  action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
  doubleClickAction=new Action(){
    @Override public void run(){
      ISelection selection=viewer.getSelection();
      @SuppressWarnings("unused") Object obj=((IStructuredSelection)selection).getFirstElement();
      System.out.println("Unbound double click action.");
      System.out.println(StackUtilities.myFrame());
    }
  }
;
}
 

Example 19

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

Source file: AddExtrasBtnSelection.java

  21 
vote

@SuppressWarnings("unchecked") @Override public void widgetSelected(SelectionEvent e){
  Product product=null;
  ISelection treeSelection=orderView.getOrderTreeViewer().getSelection();
  if (treeSelection instanceof IStructuredSelection) {
    IStructuredSelection structuredSelection=(IStructuredSelection)treeSelection;
    product=(Product)structuredSelection.getFirstElement();
  }
  if (product != null) {
    IStructuredSelection selection=(IStructuredSelection)orderView.getExtrasComboViewer().getSelection();
    Class<Product> p=(Class<Product>)selection.getFirstElement();
    if (p.equals(Milk.class)) {
      model.replaceProduct(product,new Milk(product));
      orderView.getOrderTreeViewer().setInput(model);
    }
 else     if (p.equals(Sugar.class)) {
      model.replaceProduct(product,new Sugar(product));
      orderView.getOrderTreeViewer().setInput(model);
    }
  }
}
 

Example 20

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

Source file: CreateDatasetHandler.java

  21 
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 21

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

Source file: DatabaseActionBarContributor.java

  21 
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 22

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

Source file: InterpreterView.java

  19 
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 23

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

  19 
vote

public ISelection getSelection(){
  int selectionIndex=this.folder.getSelectionIndex();
  if (selectionIndex == -1)   return StructuredSelection.EMPTY;
  IChart chart=charts.get(folder.getItem(selectionIndex));
  if (chart == null)   return StructuredSelection.EMPTY;
  return new StructuredSelection(chart);
}
 

Example 24

From project Bioclipse.clustering, under directory /src/net/bioclipse/chem/clustering/.

Source file: ViewClustering.java

  19 
vote

public void selectionChanged(IWorkbenchPart part,ISelection selection){
  org.eclipse.core.internal.resources.File file;
  final int NUMCLUSTS=2;
  if ((file=getFileFromSelection(selection)) != null) {
    try {
      ClusterList cl=new ClusterList();
      List l=getMolecules(file);
      for (      Object o : l) {
        Cluster clust=new Cluster();
        clust.addElement(o);
        cl.add(clust);
      }
      text.setText("right before display clusterlist");
      clustering=new ClusteringManager();
      ClusterList results=clustering.doClustering(cl,NUMCLUSTS);
      displayClusterList(results);
    }
 catch (    BioclipseException e) {
      text.setText(e.getMessage());
    }
  }
}
 

Example 25

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

Source file: AbstractDataManagerView.java

  19 
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);
    }
  }
}