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.atlassian.connector.eclipse.internal.crucible.ui.actions.PostDraftCommentAction.java

License:Open Source License

@Override
protected boolean updateSelection(IStructuredSelection selection) {
    review = null;/*from   w  ww.j a  v  a 2 s. c  om*/

    Object element = selection.getFirstElement();
    if (element instanceof Comment && selection.size() == 1) {
        review = getActiveReview();
        if (review != null && CrucibleUiUtil.canModifyComment(review, (Comment) element)
                && CrucibleUtil.canPublishDraft((Comment) element)) {
            return true;
        }
    }
    return false;
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.actions.RemoveCommentAction.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 ((Comment) element).getReplies().size() == 0;
        }//from  w  w w  .ja v a2s.c  o m
    }
    return false;
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.actions.ReplyToCommentAction.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 && CrucibleUtil.canAddCommentToReview(review)) {
            return true;
        }/*ww w . j av a2s .  co m*/
    }
    return false;
}

From source file:com.axmor.eclipse.typescript.editor.preferences.TypescriptTemplatePreferencePage.java

License:Open Source License

protected void updateViewerInput() {
    IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
    SourceViewer viewer = getViewer();/*  ww  w.  ja v  a2s . c o  m*/

    if (selection.size() == 1 && selection.getFirstElement() instanceof TemplatePersistenceData) {
        TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
        Template template = data.getTemplate();
        viewer.getDocument().set(template.getPattern());
    } else {
        viewer.getDocument().set(""); //$NON-NLS-1$
    }
}

From source file:com.axmor.eclipse.typescript.editor.wizards.NewClassWizardPage.java

License:Open Source License

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;//w  w  w  .  java2  s  .c  o m
            if (obj instanceof IContainer)
                container = (IContainer) obj;
            else
                container = ((IResource) obj).getParent();
            containerText.setText(container.getFullPath().toString());
        }
    }
    fileText.setText("new_file.ts");
    //TODO focus
    fileText.setFocus();
}

From source file:com.bb.extensions.plugin.unittests.internal.actions.TestFileActionProvider.java

License:Open Source License

@Override
public void setContext(ActionContext context) {
    super.setContext(context);

    if ((context != null) && (context.getSelection() instanceof IStructuredSelection)) {
        IStructuredSelection selection = (IStructuredSelection) context.getSelection();

        _openAction.selectionChanged(selection);

        // because we are using the default delete and rename actions we
        // need a list of IResource objects. Rename is only allowed on the
        // UnknownTestFile node
        List<IResource> renameResourceList = Lists.newArrayListWithExpectedSize(selection.size());
        List<IResource> deleteResourceList = Lists.newArrayListWithExpectedSize(selection.size());
        for (Object o : selection.toList()) {
            if (o instanceof UnknownTestFileUnitTestsNavigatorElement) {
                IFile file = ((UnknownTestFileUnitTestsNavigatorElement) o).getTestFile();
                addResourceIfItExists(deleteResourceList, file);
                renameResourceList.add(file);
            } else if (o instanceof TestFileUnitTestsNavigatorElement) {
                addResourceIfItExists(deleteResourceList,
                        ((TestFileUnitTestsNavigatorElement) o).getTestFile());
            }// w  w w .ja va2  s. co m
        }
        StructuredSelection renameResourceSelection = new StructuredSelection(renameResourceList);
        StructuredSelection deleteResourceSelection = new StructuredSelection(deleteResourceList);
        _deleteAction.selectionChanged(deleteResourceSelection);
        _renameAction.selectionChanged(renameResourceSelection);
    }
}

From source file:com.bdaum.zoom.gps.internal.dialogs.TrackpointDialog.java

License:Open Source License

protected void updateButtons() {
    IStructuredSelection selection = viewer.getStructuredSelection();
    int size = selection.size();
    boolean single = size == 1;
    boolean any = size > 0;
    editButton.setEnabled(single);//from w ww.  j ava2 s .c o  m
    removeButton.setEnabled(any);
    int previous = -1;
    boolean join = false;
    if (size > 1) {
        join = true;
        Iterator<?> it = selection.iterator();
        while (it.hasNext()) {
            int index = subtracks.indexOf(it.next());
            if (previous >= 0) {
                if (index - previous > 1) {
                    join = false;
                    break;
                }
            }
            previous = index;
        }
    }
    joinButton.setEnabled(join);
    splitButton.setEnabled(single);
}

From source file:com.bdaum.zoom.ui.internal.dialogs.AutoRuleComponent.java

License:Open Source License

protected void updateButtons() {
    if (ruleViewer.getControl().isEnabled()) {
        IStructuredSelection selection = ruleViewer.getStructuredSelection();
        editAutoButton.setEnabled(selection.size() == 1);
        removeAutoButton.setEnabled(!selection.isEmpty());
        applyButton.setEnabled(!selection.isEmpty());
        addAutoButton.setEnabled(true);/*from www  .ja  v  a 2  s  . c o  m*/
    } else {
        editAutoButton.setEnabled(false);
        removeAutoButton.setEnabled(false);
        applyButton.setEnabled(false);
        addAutoButton.setEnabled(false);
    }
}

From source file:com.bdaum.zoom.ui.internal.dialogs.EditMetaDialog.java

License:Open Source License

protected void updateButtons() {
    boolean sel = !catTreeViewer.getSelection().isEmpty();
    categoryRefineButton.setEnabled(sel && !readonly);
    categoryEditButton.setEnabled(sel);//ww w  .j  a v a  2 s.co m
    categoryRemoveButton.setEnabled(sel && !readonly);
    IStructuredSelection kwSelection = (IStructuredSelection) keywordViewer.getSelection();
    boolean kwSel = kwSelection.getFirstElement() instanceof String;
    keywordAddButton.setEnabled(!readonly);
    keywordModifyButton.setEnabled(!readonly && kwSel);
    keywordDeleteButton.setEnabled(!readonly && kwSel);
    keywordReplaceButton.setEnabled(!readonly && kwSelection.size() == 1 && kwSel);
    keywordShowButton.setEnabled(kwSel);
    keywordLoadButton.setEnabled(!readonly);
    categoryAddButton.setEnabled(!readonly);
    categoryEditButton.setEnabled(!readonly);
    vocabAddButton.setEnabled(!readonly);
    boolean vocabSel = !vocabViewer.getSelection().isEmpty();
    vocabRemoveButton.setEnabled(vocabSel && !readonly);
    vocabViewButton.setEnabled(vocabSel);
    vocabEnforceButton.setEnabled(vocabularies != null && !vocabularies.isEmpty());
    loadCatButton.setEnabled(!readonly);
    boolean enabled = newDb
            ? visited[OVERVIEW] && visited[THUMBNAILS] && visited[CATEGORIES] && visited[KEYWORDS]
                    && visited[INDEXING]
            : true;
    getButton(IDialogConstants.OK_ID).setEnabled(enabled);
    getShell().setModified(enabled);
    int selectionIndex = tabFolder.getSelectionIndex();
    getButton(PREVIOUS).setEnabled(selectionIndex > WELCOME + 1);
    getButton(NEXT).setEnabled(selectionIndex < tabFolder.getTabList().length - 1);
}

From source file:com.bdaum.zoom.ui.internal.NavigationHistory.java

License:Open Source License

public boolean updateHistory(IWorkbenchPart part, ISelection selection) {
    if (restoring)
        return false;
    if (selection instanceof AssetSelection) {
        if (!selection.isEmpty() && !previousStack.isEmpty()) {
            AssetSelection assetSelection = (AssetSelection) selection;
            HistoryItem item = previousStack.peek();
            if (assetSelection.isPicked())
                item.setSelectedAssets(assetSelection.getAssets());
            else//w  ww .ja v  a  2  s  .  c o m
                item.setSelectedAssets(null);
            if (part instanceof AbstractGalleryView) {
                item.setActivePart(((BasicView) part).getViewSite().getId());
                item.setSecondaryId(((BasicView) part).getViewSite().getSecondaryId());
            }
        }
        return true;
    }
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection sel = (IStructuredSelection) selection;
        if (sel.size() == 1 && sel.getFirstElement() instanceof IdentifiableObject) {
            String perspectiveId = part == null ? null : part.getSite().getPage().getPerspective().getId();
            IdentifiableObject obj = (IdentifiableObject) sel.getFirstElement();
            IDbManager dbManager = Core.getCore().getDbManager();
            Object o = null;
            Date now = new Date();
            if (obj instanceof SmartCollectionImpl) {
                ((SmartCollectionImpl) obj).setLastAccessDate(now);
                ((SmartCollectionImpl) obj).setPerspective(perspectiveId);
                o = obj.getStringId();
            } else if (obj instanceof SlideShowImpl) {
                ((SlideShowImpl) obj).setLastAccessDate(now);
                ((SlideShowImpl) obj).setPerspective(perspectiveId);
                o = obj.getStringId();
            } else if (obj instanceof ExhibitionImpl) {
                ((ExhibitionImpl) obj).setLastAccessDate(now);
                ((ExhibitionImpl) obj).setPerspective(perspectiveId);
                o = obj.getStringId();
            } else if (obj instanceof WebGalleryImpl) {
                ((WebGalleryImpl) obj).setLastAccessDate(now);
                ((WebGalleryImpl) obj).setPerspective(perspectiveId);
                o = obj.getStringId();
            }
            if (o != null) {
                boolean readOnly = dbManager.isReadOnly();
                dbManager.setReadOnly(false);
                if (obj instanceof SmartCollectionImpl && ((SmartCollectionImpl) obj).getAdhoc())
                    dbManager.safeTransaction(null,
                            Utilities.storeCollection((SmartCollection) obj, false, null));
                else
                    dbManager.storeAndCommit(obj);
                dbManager.setReadOnly(readOnly);
                fireQueryHistoryChanged(obj);
            } else
                o = (dbManager.exists(IdentifiableObject.class, obj.getStringId())) ? obj.getStringId() : obj;
            IAssetFilter[] oldfilters = previousStack.isEmpty() ? null : previousStack.peek().getFilters();
            SortCriterion oldSort = previousStack.isEmpty() ? null : previousStack.peek().getSort();
            return push(new HistoryItem(o,
                    obj instanceof SmartCollection ? ((SmartCollection) obj).getGeneration() : 0, perspectiveId,
                    oldfilters, oldSort));
        }
    }
    return false;
}