Example usage for org.eclipse.jface.viewers ISelection isEmpty

List of usage examples for org.eclipse.jface.viewers ISelection isEmpty

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ISelection isEmpty.

Prototype

public boolean isEmpty();

Source Link

Document

Returns whether this selection is empty.

Usage

From source file:BMVirtualFindAction.java

License:Open Source License

protected void setSelectionToClient(VirtualTreeModelViewer virtualViewer, ILabelProvider labelProvider,
        VirtualItem findItem) {/*from w ww . j ava 2  s . c  o m*/
    virtualViewer.getTree().setSelection(new VirtualItem[] { findItem });
    ModelDelta stateDelta = new ModelDelta(virtualViewer.getInput(), IModelDelta.NO_CHANGE);
    virtualViewer.saveElementState(TreePath.EMPTY, stateDelta, IModelDelta.SELECT);
    fClientViewer.updateViewer(stateDelta);

    ISelection selection = fClientViewer.getSelection();
    if (!selection.isEmpty() && selection instanceof IStructuredSelection
            && ((IStructuredSelection) selection).getFirstElement().equals(findItem.getData())) {
    } else {
        DebugUIPlugin.errorDialog(fClientViewer.getControl().getShell(), "Error",
                "Could not select item:" + labelProvider.getText(findItem),
                new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), "Element no longer in viewer."));
    }
}

From source file:ac.soton.eventb.classdiagrams.diagram.part.ClassdiagramsInitDiagramFileAction.java

License:Open Source License

/**
 * @generated//  w  w w .  ja  va2  s .c  o m
 */
public void selectionChanged(IAction action, ISelection selection) {
    domainModelURI = null;
    action.setEnabled(false);
    if (selection instanceof IStructuredSelection == false || selection.isEmpty()) {
        return;
    }
    IFile file = (IFile) ((IStructuredSelection) selection).getFirstElement();
    domainModelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
    action.setEnabled(true);
}

From source file:ac.soton.eventb.classdiagrams.diagram.sheet.ClassdiagramsPropertySection.java

License:Open Source License

/**
 * @generated//from w  w w  .  j a v a2  s.c  o  m
 */
public void setInput(IWorkbenchPart part, ISelection selection) {
    if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
        super.setInput(part, selection);
        return;
    }
    final StructuredSelection structuredSelection = ((StructuredSelection) selection);
    ArrayList transformedSelection = new ArrayList(structuredSelection.size());
    for (Iterator it = structuredSelection.iterator(); it.hasNext();) {
        Object r = transformSelection(it.next());
        if (r != null) {
            transformedSelection.add(r);
        }
    }
    super.setInput(part, new StructuredSelection(transformedSelection));
}

From source file:ac.soton.eventb.roseEditor.propertySections.abstracts.AbstractEventBPropertySection.java

License:Open Source License

@Override
public void setInput(final IWorkbenchPart part, final ISelection selection) {
    owner = null;//  w w  w.j  a v a 2 s  .  c om
    if (selection.isEmpty() || false == selection instanceof StructuredSelection) {
        super.setInput(part, selection);
        return;
    }
    final StructuredSelection structuredSelection = (StructuredSelection) selection;
    ArrayList<Object> transformedSelection = new ArrayList<Object>(structuredSelection.size());
    for (Object object : structuredSelection.toList()) {
        if (owner == null && object instanceof EventBElement) {
            owner = (EventBElement) object;
        }
        if (object != null) {
            transformedSelection.add(object);
        }
    }
    super.setInput(part, new StructuredSelection(transformedSelection));
}

From source file:ac.soton.fmusim.components.presentation.ComponentsEditor.java

License:Open Source License

/**
 * This deals with how we want selection in the outliner to affect the other views.
 * <!-- begin-user-doc -->/*from   w w  w.j ava  2s  .  com*/
 * <!-- end-user-doc -->
 * @generated
 */
public void handleContentOutlineSelection(ISelection selection) {
    if (currentViewerPane != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        Iterator<?> selectedElements = ((IStructuredSelection) selection).iterator();
        if (selectedElements.hasNext()) {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next();

            // If it's the selection viewer, then we want it to select the same selection as this selection.
            //
            if (currentViewerPane.getViewer() == selectionViewer) {
                ArrayList<Object> selectionList = new ArrayList<Object>();
                selectionList.add(selectedElement);
                while (selectedElements.hasNext()) {
                    selectionList.add(selectedElements.next());
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection(new StructuredSelection(selectionList));
            } else {
                // Set the input to the widget.
                //
                if (currentViewerPane.getViewer().getInput() != selectedElement) {
                    currentViewerPane.getViewer().setInput(selectedElement);
                    currentViewerPane.setTitle(selectedElement);
                }
            }
        }
    }
}

From source file:ar.com.fluxit.jqa.wizard.page.LayersDefinitionWizardPage.java

License:Open Source License

private void layerSelectionChanged(ISelection selection, EditLayerAction editLayerAction,
        RemoveLayerAction removeLayerAction) {
    boolean selectionIsNotEmpty = !selection.isEmpty();
    editLayerAction.setEnabled(selectionIsNotEmpty);
    removeLayerAction.setEnabled(selectionIsNotEmpty);
    updateLayerPackagesGroup(selection);
}

From source file:ar.com.fluxit.jqa.wizard.page.LayersDefinitionWizardPage.java

License:Open Source License

private void updateLayerPackagesGroup(ISelection selection) {
    Set<IJavaElement> input;
    if (selection.isEmpty()) {
        input = Collections.emptySet();
    } else {//from   ww w  .j  av  a 2 s .c om
        input = ((Layer) ((StructuredSelection) selection).getFirstElement()).getPackages();
    }
    layerPackagesTable.setInput(input);
}

From source file:at.bestsolution.persistence.emap.ecoregenerator.GeneratorOptionsDialog.java

License:Open Source License

@Override
protected final Control createDialogArea(final Composite parent) {
    Composite area = new Composite(parent, SWT.NONE);
    area.setLayout(new GridLayout(1, false));
    area.setLayoutData(new GridData(GridData.FILL_BOTH));

    getShell().setText(Messages.GeneratorOptionsDialog_shellTitle);
    setTitle(Messages.GeneratorOptionsDialog_title);

    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(3, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    {/*from  ww  w  .  j  a va  2  s . c  om*/
        Label l = new Label(container, SWT.NONE);
        l.setText(Messages.GeneratorOptionsDialog_emapProject);

        projectsViewer = new ComboViewer(container, SWT.READ_ONLY);
        projectsViewer.setLabelProvider(new LabelProvider() {
            @Override
            public String getText(final Object element) {
                if (element == null) {
                    return ""; //$NON-NLS-1$
                } else {
                    return ((IProject) element).getName();
                }
            }
        });
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        projectsViewer.getCombo().setLayoutData(gd);
        projectsViewer.setContentProvider(ArrayContentProvider.getInstance());
        projectsViewer.setInput(projects);
        projectsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            @Override
            public void selectionChanged(final SelectionChangedEvent event) {
                selectedFolder = null;
                ISelection s = event.getSelection();
                if (s instanceof StructuredSelection && !s.isEmpty()) {
                    selectedProject = (IProject) ((StructuredSelection) s).getFirstElement();
                    selectedFolder = selectedProject
                            .getFolder("/src/" + selectedProject.getName().replace('.', '/'));
                    tFolder.setText(selectedFolder.getFullPath().toString());
                }
            }
        });
    }
    {
        Label l = new Label(container, SWT.NONE);
        l.setText(Messages.GeneratorOptionsDialog_rootFolder);

        tFolder = new Text(container, SWT.READ_ONLY | SWT.BORDER);
        tFolder.setEditable(false);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        tFolder.setLayoutData(gd);

        Button b = new Button(container, SWT.NONE);
        b.setText(Messages.GeneratorOptionsDialog_buttonFolder);

        b.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                if (selectedProject != null) {
                    ILabelProvider lp = new WorkbenchLabelProvider();
                    ITreeContentProvider cp = new WorkbenchContentProvider();

                    Class<?>[] acceptedClasses = new Class[] { IFolder.class };
                    ViewerFilter filter = new TypedViewerFilter(acceptedClasses);

                    FolderSelectionDialog dialog = new FolderSelectionDialog(
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), lp, cp);
                    dialog.setTitle(Messages.GeneratorOptionsDialog_outputDirectory);
                    dialog.setMessage(Messages.GeneratorOptionsDialog_selectOutputDirectory);
                    dialog.addFilter(filter);
                    dialog.setInput(selectedProject);
                    if (dialog.open() == Window.OK) {
                        selectedFolder = (IFolder) dialog.getFirstResult();
                        tFolder.setText(selectedFolder.getFullPath().toString());
                    }
                }
            }
        });

        if (!projects.isEmpty()) {
            projectsViewer.setSelection(new StructuredSelection(projects.get(0)));
        }
    }
    return area;
}

From source file:at.bestsolution.persistence.emap.ecoregenerator.GenModelGenerateDoctrineActionDelegate.java

License:Open Source License

@Override
public final void runWithEvent(final IAction action, final Event event) {
    if (action instanceof EditorPluginAction) {

        ISelection s = ((EditorPluginAction) action).getSelection();
        if (s instanceof IStructuredSelection && !s.isEmpty()
                && ((IStructuredSelection) s).getFirstElement() instanceof GenModel) {
            try {
                GenModel genModel = (GenModel) ((IStructuredSelection) s).getFirstElement();

                IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
                List<IProject> emapProjects = new ArrayList<IProject>();
                for (IProject p : allProjects) {
                    if (p.isOpen() && p.getNature(Messages.GenModelGenerateDoctrineActionDelegate_5) != null
                            && p.getNature("org.eclipse.xtext.ui.shared.xtextNature") != null) {
                        emapProjects.add(p);
                    }//from   ww w.  jav a2  s.  c  om
                }
                if (emapProjects.isEmpty()) {
                    MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                            Messages.GenModelGenerateDoctrineActionDelegate_6,
                            Messages.GenModelGenerateDoctrineActionDelegate_7);
                } else {
                    GeneratorOptionsDialog dlg = new GeneratorOptionsDialog(
                            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), emapProjects);
                    if (dlg.open() == IDialogConstants.OK_ID) {
                        final IProject project = dlg.getSelectedProject();
                        if (!project.exists()) {
                            project.create(new NullProgressMonitor());
                        }
                        if (!project.isOpen()) {
                            project.open(new NullProgressMonitor());
                        }

                        final HashMap<EClass, EClassMetaInfo> metaInfo = new HashMap<EClass, EClassMetaInfo>();
                        try {
                            IFolder srcFolder = dlg.getSelectedFolder();
                            for (GenPackage pack : genModel.getGenPackages()) {
                                collectMetaPackageCode(metaInfo, project, srcFolder, srcFolder, pack);
                            }
                            for (GenPackage pack : genModel.getGenPackages()) {
                                generatePackageCode(metaInfo, project, srcFolder, pack);
                            }
                        } finally {
                            metaInfo.clear();
                        }
                    }
                }
            } catch (CoreException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    Messages.GenModelGenerateDoctrineActionDelegate_8,
                    Messages.GenModelGenerateDoctrineActionDelegate_9);
        }
    } else {
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.GenModelGenerateDoctrineActionDelegate_10,
                Messages.GenModelGenerateDoctrineActionDelegate_11);
    }
}

From source file:at.bitandart.zoubek.mervin.model.modelreview.presentation.ModelReviewEditor.java

License:Open Source License

/**
 * This deals with how we want selection in the outliner to affect the other
 * views. <!-- begin-user-doc --> <!-- end-user-doc -->
 * //from w  w  w  .  jav  a2  s. c  o m
 * @generated
 */
public void handleContentOutlineSelection(ISelection selection) {
    if (currentViewerPane != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
        Iterator<?> selectedElements = ((IStructuredSelection) selection).iterator();
        if (selectedElements.hasNext()) {
            // Get the first selected element.
            //
            Object selectedElement = selectedElements.next();

            // If it's the selection viewer, then we want it to select the
            // same selection as this selection.
            //
            if (currentViewerPane.getViewer() == selectionViewer) {
                ArrayList<Object> selectionList = new ArrayList<Object>();
                selectionList.add(selectedElement);
                while (selectedElements.hasNext()) {
                    selectionList.add(selectedElements.next());
                }

                // Set the selection to the widget.
                //
                selectionViewer.setSelection(new StructuredSelection(selectionList));
            } else {
                // Set the input to the widget.
                //
                if (currentViewerPane.getViewer().getInput() != selectedElement) {
                    currentViewerPane.getViewer().setInput(selectedElement);
                    currentViewerPane.setTitle(selectedElement);
                }
            }
        }
    }
}