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.astra.ses.spell.database.browser.views.DatabasePage.java

License:Open Source License

/**************************************************************************
 * Init the drag action for the viewer/*from   ww w  .j  ava 2s . c o  m*/
 *************************************************************************/
private void initDragAction() {
    //Add transfer types for this drag source
    Transfer[] types = new Transfer[] { OfflineDatabaseTransfer.getInstance() };
    //Drag listener
    DragSourceListener dragListener = new DragSourceListener() {
        @Override
        public void dragFinished(DragSourceEvent event) {
            event.data = null;
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (OfflineDatabaseTransfer.getInstance().isSupportedType(event.dataType)) {
                TelemetryView tmView = (TelemetryView) getSite().getWorkbenchWindow().getActivePage()
                        .findView(TelemetryView.ID);
                TelecommandView tcView = (TelecommandView) getSite().getWorkbenchWindow().getActivePage()
                        .findView(TelecommandView.ID);

                List<ITelemetryParameter> tmList = new ArrayList<ITelemetryParameter>();
                if (tmView != null) {
                    tmList = tmView.getSelectedParameters();
                    tmView.deselectAll();
                }

                List<ITelecommand> tcList = new ArrayList<ITelecommand>();
                if (tcView != null) {
                    tcList = tcView.getSelectedCommands();
                    tcView.deselectAll();
                }
                event.data = new DatabaseTransferable(tmList, tcList);
            }
        }

        @Override
        public void dragStart(DragSourceEvent event) {
            IStructuredSelection selection = (IStructuredSelection) m_viewer.getSelection();
            if (selection.size() < 1) {
                event.doit = false;
            }
        }
    };

    m_viewer.addDragSupport(DND.DROP_COPY, types, dragListener);
}

From source file:com.astra.ses.spell.database.browser.views.telecommand.TelecommandViewPart.java

License:Open Source License

/**************************************************************************
 * Init the drag action for the viewer//from   ww  w. j  a v a 2  s .co m
 *************************************************************************/
private void initDragAction() {
    Transfer[] types = new Transfer[] { OfflineDatabaseTransfer.getInstance() };
    //Drag listener
    DragSourceListener dragListener = new DragSourceListener() {
        @Override
        public void dragFinished(DragSourceEvent event) {
            event.data = null;
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (OfflineDatabaseTransfer.getInstance().isSupportedType(event.dataType)) {
                // Retrieve selected elements from this viewer
                Command[] commands = getSelectedCommands();
                // Retrieve selected elements from the Telecommand viewer
                IViewPart tmView = getSite().getWorkbenchWindow().getActivePage()
                        .findView(TelemetryViewPart.ID);
                TelemetryParameter[] params = new TelemetryParameter[0];
                if (tmView != null) {
                    TelemetryViewPart tmViewPart = (TelemetryViewPart) tmView;
                    params = tmViewPart.getSelectedParameters();
                    // Deselect elements
                    tmViewPart.deselectAll();
                }

                event.data = new DatabaseTransferable(params, commands);
                deselectAll();
            }
        }

        @Override
        public void dragStart(DragSourceEvent event) {
            IStructuredSelection selection = (IStructuredSelection) m_viewer.getSelection();
            if (selection.size() < 1) {
                event.doit = false;
            }
        }
    };
    m_viewer.addDragSupport(DND.DROP_COPY, types, dragListener);
}

From source file:com.astra.ses.spell.database.browser.views.telemetry.TelemetryViewPart.java

License:Open Source License

/**************************************************************************
 * Init the drag action for the viewer/* www . j  av  a  2 s  .c  om*/
 *************************************************************************/
private void initDragAction() {
    //Add transfer types for this drag source
    Transfer[] types = new Transfer[] { OfflineDatabaseTransfer.getInstance() };
    //Drag listener
    DragSourceListener dragListener = new DragSourceListener() {
        @Override
        public void dragFinished(DragSourceEvent event) {
            event.data = null;
        }

        @Override
        public void dragSetData(DragSourceEvent event) {
            if (OfflineDatabaseTransfer.getInstance().isSupportedType(event.dataType)) {
                // Retrieve selected elements from this viewer
                TelemetryParameter[] params = getSelectedParameters();
                // Retrieve selected elements from the Telecommand viewer
                IViewPart tcView = getSite().getWorkbenchWindow().getActivePage()
                        .findView(TelecommandViewPart.ID);
                Command[] commands = new Command[0];
                if (tcView != null) {
                    TelecommandViewPart tcViewPart = (TelecommandViewPart) tcView;
                    commands = tcViewPart.getSelectedCommands();
                    // Deselect elements
                    tcViewPart.deselectAll();
                }
                event.data = new DatabaseTransferable(params, commands);
                deselectAll();
            }
        }

        @Override
        public void dragStart(DragSourceEvent event) {
            IStructuredSelection selection = (IStructuredSelection) m_viewer.getSelection();
            if (selection.size() < 1) {
                event.doit = false;
            }
        }
    };

    m_viewer.addDragSupport(DND.DROP_COPY, types, dragListener);
}

From source file:com.astra.ses.spell.database.db.ui.actions.ChangeDatabaseAction.java

License:Open Source License

@SuppressWarnings("unchecked")
public boolean isEnabled() {
    /*//from  w ww .  jav a  2s. com
     * Conditions for enabling this action
     * 1.- Only one element can be selected
     */
    IStructuredSelection selection = (IStructuredSelection) m_selectionProvider.getSelection();
    return (selection.size() == 1);
}

From source file:com.astra.ses.spell.database.db.ui.wizards.FileInformationWizard.java

License:Open Source License

/**
 * Tests if the current workbench selection is a suitable container to use.
 *///w w  w.j  a v a2  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("databaseFile.imp");
}

From source file:com.astra.ses.spell.gui.views.controls.watchvariables.WatchVariablesMenuManager.java

License:Open Source License

/**************************************************************************
 * Fill the menu with the appropiate actions
 *************************************************************************/
private void fillMenu() {
    /*/*w  ww .  j  ava  2 s .  c  o m*/
     * Remove current items from the menu
     */
    for (MenuItem item : m_menu.getItems()) {
        item.dispose();
    }

    // First thing, if there are no elements, do not build the menu
    IStructuredContentProvider provider = (IStructuredContentProvider) m_viewer.getContentProvider();
    Object[] allElements = provider.getElements(null);
    if (allElements.length == 0)
        return;

    // See if there is an element registered in the whole table, no matter
    // if selected
    boolean atLeastOneRegistered = WatchVariablesSelection.anyRegistered(allElements);

    // Now check the selection
    IStructuredSelection sel = (IStructuredSelection) m_viewer.getSelection();
    // Will be false if any of the items selected is not registered
    boolean allSelectedRegistered = WatchVariablesSelection.allRegistered(sel);
    // Will be false if any of the items selected is registered
    boolean noneSelectedRegistered = WatchVariablesSelection.noneRegistered(sel);

    if (sel.size() > 0) // At lease one item selected
    {
        if (allSelectedRegistered) {
            MenuItem unsubscribe = new MenuItem(m_menu, SWT.PUSH);
            unsubscribe.setText("Remove watch");
            unsubscribe.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    m_page.unsubscribeSelected();
                }
            });
        } else if (noneSelectedRegistered) {
            MenuItem unsubscribe = new MenuItem(m_menu, SWT.PUSH);
            unsubscribe.setText("Add watch");
            unsubscribe.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    m_page.subscribeSelected();
                }
            });
        }

        if (atLeastOneRegistered) {
            MenuItem unsubscribe = new MenuItem(m_menu, SWT.PUSH);
            unsubscribe.setText("Remove all watches");
            unsubscribe.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    m_page.unsubscribeAll();
                }
            });
        }
    }
}

From source file:com.astra.ses.spell.gui.views.WatchVariablesView.java

License:Open Source License

/***************************************************************************
 * Update actions status/*  w ww. j ava 2 s . co  m*/
 **************************************************************************/
private void updateActionState(IStructuredSelection selection) {
    int selectionSize = selection.size();

    boolean refresh = true;
    boolean subscribe = false;
    boolean unsubscribe = false;
    boolean cleanup = false;

    WatchVariablesPage page = (WatchVariablesPage) getCurrentPage();
    boolean registered = page.isShowingRegistered();
    boolean active = page.isActive();

    refresh = active;

    if (selectionSize > 0) {
        subscribe = !registered;
        unsubscribe = true;

        Iterator<VariableData> variableIterator = selection.iterator();
        while (variableIterator.hasNext()) {
            VariableData var = variableIterator.next();
            subscribe = (subscribe && (!var.isRegistered));
            unsubscribe = (unsubscribe && (var.isRegistered));
        }
        cleanup = !subscribe;
    }

    m_refreshAction.setEnabled(refresh);
    m_unsubscribeAction.setEnabled(unsubscribe);
    m_subscribeAction.setEnabled(subscribe);
    m_unsubscribeAllAction.setEnabled(cleanup);
}

From source file:com.astra.ses.spell.gui.watchvariables.views.WatchVariablesView.java

License:Open Source License

/***************************************************************************
 * Update actions status//from   w  ww.  j  a v  a2  s.c  o  m
 **************************************************************************/
private void updateActionState(IStructuredSelection selection) {
    int selectionSize = selection.size();

    boolean refresh = true;
    boolean subscribe = false;
    boolean unsubscribe = false;
    boolean cleanup = false;

    WatchVariablesPage page = (WatchVariablesPage) getCurrentPage();
    boolean registered = page.isShowingRegistered();
    boolean active = page.isActive();

    refresh = active;

    if (selectionSize > 0) {
        subscribe = !registered;
        unsubscribe = true;

        @SuppressWarnings("unchecked")
        Iterator<VariableData> variableIterator = selection.iterator();
        while (variableIterator.hasNext()) {
            VariableData var = variableIterator.next();
            subscribe = (subscribe && (!var.isRegistered));
            unsubscribe = (unsubscribe && (var.isRegistered));
        }
        cleanup = !subscribe;
    }

    m_refreshAction.setEnabled(refresh);
    m_unsubscribeAction.setEnabled(unsubscribe);
    m_subscribeAction.setEnabled(subscribe);
    m_unsubscribeAllAction.setEnabled(cleanup);
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.actions.AddFileCommentAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    this.review = null;
    this.fileInfo = null;
    if (selection.size() != 1) {
        return false;
    }// www .j a v a2 s.  com

    Object element = selection.getFirstElement();
    if (element instanceof CrucibleFileInfo && selection.size() == 1) {
        this.review = CrucibleUiPlugin.getDefault().getActiveReviewManager().getActiveReview();
        if (this.review != null && CrucibleUtil.canAddCommentToReview(review)) {
            this.fileInfo = (CrucibleFileInfo) element;
            return true;
        }
    }

    if (element instanceof Comment) {
        this.review = CrucibleUiPlugin.getDefault().getActiveReviewManager().getActiveReview();
        final VersionedComment parentVersionedComment = ReviewModelUtil
                .getParentVersionedComment((Comment) element);
        if (parentVersionedComment != null) {
            this.fileInfo = parentVersionedComment.getCrucibleFileInfo();
        }
        return true;
    }

    return false;
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.actions.EditCommentAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    this.review = null;

    Object element = selection.getFirstElement();
    if (element instanceof Comment && selection.size() == 1) {
        this.review = getActiveReview();
        if (this.review != null && CrucibleUiUtil.canModifyComment(review, (Comment) element)) {
            return true;
        }/*from   w w w  .j av  a 2s. c o m*/
    }
    return false;
}