Example usage for org.eclipse.jface.viewers StructuredSelection size

List of usage examples for org.eclipse.jface.viewers StructuredSelection size

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection size.

Prototype

@Override
    public int size() 

Source Link

Usage

From source file:org.dawnsci.internal.intro.universal.CustomizationContentsArea.java

License:Open Source License

private void fillPopupMenu(IMenuManager manager, final TableViewer viewer) {
    StructuredSelection ssel = (StructuredSelection) viewer.getSelection();

    manager.add(new Separator());
    Action addSeparator = new Action(Messages.WelcomeCustomizationPreferencePage_addSeparator) {
        public void run() {
            doAddSeparator(viewer);/*from  w  w w  .jav  a  2s.c  o m*/
        }
    };

    manager.add(addSeparator);
    manager.add(new Separator());

    if (ssel.size() == 1 && viewer != available) {
        Action upAction = new Action(Messages.WelcomeCustomizationPreferencePage_up) {

            public void run() {
                doMove(viewer, true);
            }
        };
        Action downAction = new Action(Messages.WelcomeCustomizationPreferencePage_down) {

            public void run() {
                doMove(viewer, false);
            }
        };
        BaseData ed = (BaseData) ssel.getFirstElement();
        GroupData gd = (GroupData) viewer.getInput();
        upAction.setEnabled(gd.canMoveUp(ed));
        downAction.setEnabled(gd.canMoveDown(ed));
        manager.add(upAction);
        manager.add(downAction);
    }
    if (ssel.size() > 0) {
        manager.add(new Separator());
        MenuManager menu = new MenuManager(Messages.WelcomeCustomizationPreferencePage_moveTo);
        addMoveToAction(menu, available, viewer, Messages.WelcomeCustomizationPreferencePage_menu_available);
        addMoveToAction(menu, topLeft, viewer, Messages.WelcomeCustomizationPreferencePage_menu_top_left);
        addMoveToAction(menu, topRight, viewer, Messages.WelcomeCustomizationPreferencePage_menu_top_right);
        addMoveToAction(menu, bottomLeft, viewer, Messages.WelcomeCustomizationPreferencePage_menu_bottom_left);
        addMoveToAction(menu, bottomRight, viewer,
                Messages.WelcomeCustomizationPreferencePage_menu_bottom_right);
        manager.add(menu);

        boolean addDeleteSeparator = false;

        for (Iterator<?> iter = ssel.iterator(); iter.hasNext();) {
            Object obj = iter.next();
            if (obj instanceof SeparatorData)
                addDeleteSeparator = true;
            else {
                addDeleteSeparator = false;
                break;
            }
        }
        if (addDeleteSeparator) {
            Action deleteSeparator = new Action(Messages.WelcomeCustomizationPreferencePage_removeSeparator) {
                public void run() {
                    doRemoveSeparators(viewer);
                }
            };
            manager.add(deleteSeparator);
        }
    }
}

From source file:org.eclipse.ajdt.internal.ui.refactoring.RenameFileExtensionsAction.java

License:Open Source License

public void run(IAction action) {
    if (selection instanceof StructuredSelection) {
        StructuredSelection struct = (StructuredSelection) selection;
        if (struct.size() > 0) {
            Object o = struct.getFirstElement();
            if (o instanceof IAdaptable) {
                IProject project = (IProject) ((IAdaptable) o).getAdapter(IProject.class);
                if (project != null) {
                    RenameFileExtensionsDialog dialog = new RenameFileExtensionsDialog(
                            AspectJUIPlugin.getDefault().getDisplay().getActiveShell(), project);
                    dialog.open();/*from   ww w. ja  va 2  s.c  o  m*/
                }
            }

        }
    }
}

From source file:org.eclipse.ajdt.internal.ui.wizards.SuperInterfaceSelectionDialog.java

License:Open Source License

protected void handleSelected(StructuredSelection selection) {
    super.handleSelected(selection);

    if (selection.size() == 0 && fTypeWizardPage.getSuperInterfaces().size() > fOldContent.size()) {
        // overrides updateStatus() from handleSelected() if
        // list of super interfaces was modified
        // the <code>super.handleSelected(selection)</code> has to be
        // called, because superclass implementation of this class updates
        // state of the table.

        updateStatus(new Status(IStatus.OK, JavaPlugin.getPluginId(), IStatus.OK, "", null)); //$NON-NLS-1$

        getButton(ADD_ID).setEnabled(false);
    } else {/*from  www.ja v a2s. c o m*/
        // if selection isn't empty, the add button should be enabled in
        // exactly the same scenarios as the OK button
        getButton(ADD_ID).setEnabled(getButton(OK).isEnabled());
    }
}

From source file:org.eclipse.birt.report.designer.ui.dialogs.CascadingParametersDialog.java

License:Open Source License

private void updateDynamicTableButtons() {
    StructuredSelection selection = (StructuredSelection) defaultValueViewer.getSelection();
    boolean enable = (selection.size() == 1);
    editValueBtn.setEnabled(enable);// ww  w .  j  a  v a 2s .c o m
    delValueBtn.setEnabled(!selection.isEmpty());
    delAllValuesBtn.setEnabled(defaultValueViewer.getTable().getItemCount() > 0);

    Expression expression = ExpressionButtonUtil.getExpression(defaultValueChooser);
    if (defaultValueChooser.getText().trim().length() == 0) {
        addValueButton.setEnabled(false);
    } else {
        if (defaultValueList != null && defaultValueList.contains(expression))
            addValueButton.setEnabled(false);
        else
            addValueButton.setEnabled(true);
    }
}

From source file:org.eclipse.birt.report.designer.ui.dialogs.ParameterDialog.java

License:Open Source License

private void updateDynamicTableButtons() {
    StructuredSelection selection = (StructuredSelection) defaultValueViewer.getSelection();
    boolean enable = (selection.size() == 1);
    editBtn.setEnabled(enable);//from  w w  w. j  a v a 2s.  c o  m
    delBtn.setEnabled(!selection.isEmpty());
    delAllBtn.setEnabled(defaultValueViewer.getTable().getItemCount() > 0);

    String type = (String) defaultValueChooser.getData(ExpressionButtonUtil.EXPR_TYPE);
    String value = UIUtil.convertToModelString(defaultValueChooser.getText(), false);
    if (value != null) {
        if (value.equals(EMPTY_VALUE))
            value = ""; //$NON-NLS-1$
        else if (value.equals(NULL_VALUE))
            value = null;
    }
    Expression expression = null;
    if (value != null)
        expression = new Expression(value, type);

    if (defaultValueChooser.getText().trim().length() == 0) {
        addButton.setEnabled(false);
    } else {
        if (defaultValueList != null && defaultValueList.contains(expression))
            addButton.setEnabled(false);
        else
            addButton.setEnabled(true);
    }
    updateMessageLine();
}

From source file:org.eclipse.birt.report.designer.ui.lib.explorer.action.AddElementtoReport.java

License:Open Source License

public Object getTarget() {
    IViewPart viewPart = UIUtil.getView(IPageLayout.ID_OUTLINE);
    if (!(viewPart instanceof ContentOutline)) {
        return null;
    }//  w w  w .j  av  a  2  s  .  co  m
    ContentOutline outlineView = (ContentOutline) viewPart;

    ISelection selection = outlineView.getSelection();
    if (selection instanceof StructuredSelection) {
        StructuredSelection strSelection = (StructuredSelection) selection;
        if (strSelection.size() == 1) {
            return strSelection.getFirstElement();
        }
    }
    return null;
}

From source file:org.eclipse.bpel.ui.BPELEditor.java

License:Open Source License

/**
 * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer()
 *///from www.  ja v a 2  s  .c om
@Override
protected void initializeGraphicalViewer() {
    ///FIXME moved to multi
    //initializeFileChangeListener();
    //initializeRefactoringListeners();

    getGraphicalViewer().setEditPartFactory(new BPELEditPartFactory());

    BPELUIPlugin.INSTANCE.getPreferenceStore().setValue(IBPELUIConstants.PREF_SHOW_FREEFORM_FLOW, true);
    GraphicalViewer viewer = getGraphicalViewer();
    viewer.setContents(getProcess());

    viewer.addDropTargetListener(new FileDropTargetListener(viewer, this));
    viewer.addDropTargetListener(new TextDropTargetListener(viewer, this));
    viewer.addDropTargetListener(new BPELTextTransferDropTargetListener(viewer, this));
    viewer.addDropTargetListener(new BPELTemplateTransferDropTargetListener(viewer));

    this.selectionChangeListener = new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            // if this is a multi-selection we should not present anything on the details area
            if (selection.size() > 1) {
                // TODO: This doesn't work
                //               getBPELDetailsEditor().getDetailsArea().setInput(null);
            } else {
                final Object o = selection.getFirstElement();
                if (o instanceof EditPart) {
                    // CAREFUL: must setInput() on the DetailsArea *before* we remember
                    // the lastSelectedEditPart (because setInput() might execute a pending
                    // command for an IOngoingChange whose wrapper will not execute correctly
                    // unless lastSelectedEditPart has its old value).
                    lastSelectedEditPart = (EditPart) o;
                }
            }
        }
    };
    this.traySelectionChangeListener = new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            // if this is a multi-selection we should not present anything on the details area
            if (selection.size() > 1) {
                // TODO: This doesn't work.
                //               getBPELDetailsEditor().getDetailsArea().setInput(null);
            } else {
                final Object o = selection.getFirstElement();
                if (o instanceof EditPart) {
                    // CAREFUL: must setInput() on the DetailsArea *before* we remember
                    // the lastSelectedEditPart (because setInput() might execute a pending
                    // command for an IOngoingChange whose wrapper will not execute correctly
                    // unless lastSelectedEditPart has its old value).
                    lastSelectedEditPart = (EditPart) o;
                }
            }
        }
    };
    getGraphicalViewer().addSelectionChangedListener(this.selectionChangeListener);
    arrangeEditParts(getGraphicalViewer());
}

From source file:org.eclipse.cdt.mylyn.internal.ui.actions.FocusCViewAction.java

License:Open Source License

@Override
protected ISelection resolveSelection(IEditorPart part, ITextSelection changedSelection,
        StructuredViewer viewer) throws CoreException {
    Object elementToSelect = null;
    if (changedSelection instanceof TextSelection && part instanceof CEditor) {
        ICElement cdtElement = SelectionConverter.getElementAtOffset(((CEditor) part).getInputCElement(),
                changedSelection);//www. j a va 2  s .com
        elementToSelect = cdtElement;
    }

    if (elementToSelect != null) {
        StructuredSelection currentSelection = (StructuredSelection) viewer.getSelection();
        if (currentSelection.size() <= 1) {
            for (ViewerFilter filter : Arrays.asList(viewer.getFilters())) {
                if (filter instanceof CDTDeclarationsFilter && elementToSelect instanceof IMethod) {
                    elementToSelect = ((IMethod) elementToSelect).getTranslationUnit();
                }
            }
        }
        return new StructuredSelection(elementToSelect);
    } else {
        return null;
    }
}

From source file:org.eclipse.dltk.internal.mylyn.actions.FocusPackageExplorerAction.java

License:Open Source License

@Override
protected ISelection resolveSelection(IEditorPart part, ITextSelection changedSelection,
        StructuredViewer viewer) throws CoreException {
    Object elementToSelect = null;
    if (changedSelection instanceof TextSelection) {
        TextSelection textSelection = (TextSelection) changedSelection;
        IModelElement javaElement = SelectionConverter.resolveEnclosingElement(part, textSelection);
        if (javaElement != null) {
            elementToSelect = javaElement;
        }/* www .  j a  v  a 2  s . c  om*/
    }

    if (elementToSelect != null) {
        StructuredSelection currentSelection = (StructuredSelection) viewer.getSelection();
        if (currentSelection.size() <= 1) {
            if (elementToSelect instanceof IMember) {
                if (viewer.getContentProvider() instanceof StandardModelElementContentProvider) {
                    if (!((StandardModelElementContentProvider) viewer.getContentProvider())
                            .getProvideMembers()) {
                        elementToSelect = ((IMember) elementToSelect).getSourceModule();
                        return new StructuredSelection(elementToSelect);
                    }
                }

                for (ViewerFilter filter : Arrays.asList(viewer.getFilters())) {
                    if (filter instanceof DLTKDeclarationsFilter) {
                        elementToSelect = ((IMember) elementToSelect).getSourceModule();
                        return new StructuredSelection(elementToSelect);
                    }
                }
            }
        }
        return new StructuredSelection(elementToSelect);
    } else {
        return null;
    }
}

From source file:org.eclipse.e4.demo.e4photo.Library.java

License:Open Source License

@Inject
public Library(Composite parent, final IWorkspace workspace) {
    final Realm realm = SWTObservables.getRealm(parent.getDisplay());
    this.workspace = workspace;
    initializeWorkspace();//from  w w w . j  ava 2s  . co m
    viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.getTree().setData("org.eclipse.e4.ui.css.id", "library");

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            selectionService
                    .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray());
        }
    });
    IObservableFactory setFactory = new IObservableFactory() {
        public IObservable createObservable(Object element) {
            if (element instanceof IContainer && ((IContainer) element).exists()) {
                IObservableSet observableSet = observableSets.get(element);
                if (observableSet == null) {
                    observableSet = new WritableSet(realm);
                    try {
                        observableSet.addAll(Arrays.asList(((IContainer) element).members()));
                    } catch (CoreException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    observableSets.put((IContainer) element, observableSet);
                }
                return observableSet;
            }
            return Observables.emptyObservableSet();
        }
    };
    viewer.setContentProvider(new ObservableSetTreeContentProvider(setFactory, new TreeStructureAdvisor() {
        public Boolean hasChildren(Object element) {
            return Boolean.valueOf(element instanceof IContainer);
        }
    }));

    viewer.setLabelProvider(new LabelProvider() {
        public String getText(Object element) {
            if (element instanceof IResource)
                return ((IResource) element).getName();
            return element == null ? "" : element.toString();
        }
    });

    viewer.setSorter(new ViewerSorter());
    viewer.setInput(workspace.getRoot());

    //      Button button = new Button(parent, SWT.PUSH);
    //      button.setText("Create Project");
    //      button.addSelectionListener(new SelectionListener() {
    //         public void widgetSelected(SelectionEvent e) {
    //            String projectName = "Project" + (counter++);
    //            final IProject project = workspace.getRoot().getProject(
    //                  projectName);
    //            final IProjectDescription pd = workspace
    //                  .newProjectDescription(projectName);
    //            try {
    //               workspace.run(new IWorkspaceRunnable() {
    //                  public void run(IProgressMonitor monitor)
    //                        throws CoreException {
    //                     project.create(pd, monitor);
    //                     project.open(monitor);
    //                  }
    //               }, new NullProgressMonitor());
    //            } catch (CoreException e1) {
    //               // TODO Auto-generated catch block
    //               e1.printStackTrace();
    //            }
    //         }
    //
    //         public void widgetDefaultSelected(SelectionEvent e) {
    //         }
    //      });

    GridLayoutFactory.fillDefaults().generateLayout(parent);
}