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

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

Introduction

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

Prototype

public int size();

Source Link

Document

Returns the number of elements selected in this selection.

Usage

From source file:com.nokia.carbide.cpp.internal.pi.save.SaveTableWizardPage.java

License:Open Source License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *//*w  w w.ja  va2 s  .co m*/

private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1)
            return;
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            //            containerText.setText(container.getFullPath().toString());
        }
    }
    fileText.setText("new_file.csv"); //$NON-NLS-1$
}

From source file:com.nokia.carbide.cpp.internal.project.ui.editors.inf.ExportSectionPart.java

License:Open Source License

private void updateButtons() {
    int selectionSize = 0;
    int firstSelection = tableViewer.getTable().getSelectionIndex();
    ISelection selection = tableViewer.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        selectionSize = ss.size();
    }//from  w  w  w.j  av  a  2  s  . c  o  m
    editButton.setEnabled(selectionSize == 1);
    removeButton.setEnabled(selectionSize > 0);
    upButton.setEnabled(selectionSize == 1 && firstSelection > 0);
    downButton.setEnabled(selectionSize == 1 && firstSelection < tableViewer.getTable().getItemCount() - 1);
}

From source file:com.nokia.carbide.cpp.internal.project.ui.editors.inf.MakMakeFilesSectionPart.java

License:Open Source License

private void updateButtons() {
    int selectionSize = 0;
    int firstSelection = tableViewer.getTable().getSelectionIndex();
    ISelection selection = tableViewer.getSelection();
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection ss = (IStructuredSelection) selection;
        selectionSize = ss.size();
    }// www  . j  ava  2  s. c om
    editButton.setEnabled(selectionSize == 1);
    launchEditorButton.setEnabled(selectionSize == 1);
    removeButton.setEnabled(selectionSize > 0);
    upButton.setEnabled(selectionSize == 1 && firstSelection > 0);
    downButton.setEnabled(selectionSize == 1 && firstSelection < tableViewer.getTable().getItemCount() - 1);
}

From source file:com.nokia.carbide.cpp.internal.project.ui.views.MainActionGroup.java

License:Open Source License

public void fillContextMenu(IMenuManager menu) {
    MenuManager newMenu = new MenuManager(Messages.MainActionGroup_NewMenu);
    menu.add(newMenu);//  w ww.  ja v  a2  s  . com
    newMenu.add(newWizardMenu);
    menu.add(new Separator());

    menu.add(new Separator(ICommonMenuConstants.GROUP_OPEN));
    openFileGroup.fillContextMenu(menu);
    menu.add(new Separator());

    menu.add(new Separator(ICommonMenuConstants.GROUP_REORGANIZE));
    refactorGroup.fillContextMenu(menu);
    menu.add(new Separator("group.private1")); //$NON-NLS-1$

    IStructuredSelection elements = (IStructuredSelection) getView().getViewer().getSelection();
    if (OpenIncludeAction.canActionBeAdded(elements)) {
        menu.add(openIncludeAction);
        menu.add(new Separator());
    }

    menu.add(importAction);
    menu.add(exportAction);
    menu.add(new Separator());
    openProjectGroup.fillContextMenu(menu);
    menu.add(new Separator());

    menu.add(new Separator(ICommonMenuConstants.GROUP_SEARCH));
    addSearchMenu(menu, elements);

    if (elements.size() == 1) {
        Object selection = elements.getFirstElement();
        if (selection instanceof IAdaptable) {
            if (((IAdaptable) selection).getAdapter(IResource.class) != null) {
                MenuManager showInSubMenu = new MenuManager("Show in");
                showInSubMenu.add(
                        ContributionItemFactory.VIEWS_SHOW_IN.create(view.getViewSite().getWorkbenchWindow()));
                menu.add(showInSubMenu);
            }
        }
    }

    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$

    menu.add(new Separator(ICommonMenuConstants.GROUP_PROPERTIES));
    openViewActionGroup.fillContextMenu(menu);
    crefactoringActionGroup.fillContextMenu(menu);
}

From source file:com.nokia.carbide.cpp.internal.project.ui.views.OpenFileGroup.java

License:Open Source License

public void fillContextMenu(IMenuManager menu) {

    IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
    boolean onlyFilesSelected = !selection.isEmpty() && allResourcesAreOfType(selection, IResource.FILE);

    if (onlyFilesSelected) {
        openFileAction.selectionChanged(selection);
        menu.add(openFileAction);//from ww w . jav a2s.co m
        fillOpenWithMenu(menu, selection);
    }

    if (selection.size() == 1 && selection.getFirstElement() instanceof INonWorkspaceFileEntry) {
        openNonWorkspaceFileAction.selectionChanged(selection);
        menu.add(openNonWorkspaceFileAction);
    }

    if (selection.size() == 1 && selection.getFirstElement() instanceof IMBMMIFFileEntry) {
        openMBMMIFAction.selectionChanged(selection);
        menu.add(openMBMMIFAction);
    }
}

From source file:com.nokia.carbide.cpp.internal.project.ui.views.OpenFileGroup.java

License:Open Source License

/**
 * Adds the OpenWith submenu to the context menu.
 * /*  www .j a  va2  s  .c  o  m*/
 * @param menu
 *            the context menu
 * @param selection
 *            the current selection
 */
private void fillOpenWithMenu(IMenuManager menu, IStructuredSelection selection) {
    // Only supported if exactly one file is selected.
    if (selection.size() != 1) {
        return;
    }
    Object element = selection.getFirstElement();
    if (!(element instanceof IAdaptable)) {
        return;
    }

    MenuManager submenu = new MenuManager(Messages.OpenFileGroup_OpenWith, OPEN_WITH_ID);
    submenu.add(new OpenWithMenu(view.getSite().getPage(), (IAdaptable) element));
    menu.add(submenu);
}

From source file:com.nokia.carbide.cpp.internal.project.ui.views.SymbianProjectNavigatorView.java

License:Open Source License

void updateStatusLine(IStructuredSelection selection) {
    String msg = ""; //$NON-NLS-1$
    if (selection.size() == 1) {
        Object o = selection.getFirstElement();

        if (o instanceof IResource) {
            msg = ((IResource) o).getFullPath().makeRelative().toString();
        } else if (o instanceof ISPNStatusLineDecorator) {
            msg = ((ISPNStatusLineDecorator) o).getStatusLineText();
        } else if (o instanceof IWorkbenchAdapter) {
            IWorkbenchAdapter wAdapter = (IWorkbenchAdapter) o;
            msg = wAdapter.getLabel(o);//from  w w  w  .j  a  v a  2  s .  co m
        } else if (o instanceof ITranslationUnit) {
            IPath location = ((ITranslationUnit) o).getLocation();
            if (location != null) {
                msg = location.toString();
            }
        }
    }

    getViewSite().getActionBars().getStatusLineManager().setMessage(msg);
}

From source file:com.nokia.carbide.cpp.internal.project.ui.wizards.MMPWizardPage.java

License:Open Source License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *///from www.j  a  v  a 2 s.c  om

private void initialize() {
    if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
        IStructuredSelection ssel = (IStructuredSelection) selection;
        if (ssel.size() > 1)
            return;
        Object obj = ssel.getFirstElement();
        if (obj instanceof IResource) {
            IContainer container;
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            containerText.setText(container.getFullPath().toString());
        }
    }
    fileText.setText(Messages.getString("MMPWizardPage.defaultMMPName")); //$NON-NLS-1$
}

From source file:com.nokia.carbide.cpp.internal.sdk.ui.SDKPreferencePage.java

License:Open Source License

private void addSDKTableViewerListeners() {
    sdkListTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                if (selection.size() == 1) {
                    ISymbianSDK sdk = (ISymbianSDK) selection.getFirstElement();
                    deleteButton.setEnabled(true);
                    propertiesButton.setEnabled(true);
                    updateSDKStatus(sdk);
                } else {
                    deleteButton.setEnabled(false);
                    propertiesButton.setEnabled(false);
                }/*w  ww .  java  2s.  com*/
            }
        }
    });
}

From source file:com.nokia.carbide.cpp.uiq.ui.vieweditor.CommandElementDragListener.java

License:Open Source License

/**
 * Method declared on DragSourceListener
 *///from ww  w .j av a 2 s  .  c  o  m
public void dragSetData(DragSourceEvent event) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Object[] elements = (Object[]) selection.toList().toArray(new Object[selection.size()]);
    if (CommandElementTransfer.getInstance().isSupportedType(event.dataType)) {
        event.data = elements;
    }
}