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

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

Introduction

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

Prototype

public StructuredSelection(List elements) 

Source Link

Document

Creates a structured selection from the given List.

Usage

From source file:com.architexa.org.eclipse.gef.ui.parts.TreeViewer.java

License:Open Source License

/**
 * "Hooks up" a Control, i.e. sets it as the control for the RootTreeEditPart,
 * adds necessary listener for proper operation, etc.
 *///  ww  w  .  j a v a2  s . c  o m
protected void hookControl() {
    if (getControl() == null)
        return;

    final Tree tree = (Tree) getControl();
    tree.addFocusListener(dispatcher);
    tree.addMouseListener(dispatcher);
    tree.addMouseMoveListener(dispatcher);
    tree.addKeyListener(dispatcher);
    tree.addMouseTrackListener(dispatcher);
    tree.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            TreeItem[] ties = tree.getSelection();
            Object newSelection[] = new Object[ties.length];
            for (int i = 0; i < ties.length; i++)
                newSelection[i] = ties[i].getData();
            ignore = true;
            setSelection(new StructuredSelection(newSelection));
            ignore = false;
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    TreeEditPart tep = (TreeEditPart) getRootEditPart();
    tep.setWidget(tree);
    super.hookControl();
}

From source file:com.architexa.org.eclipse.gef.ui.parts.TreeViewerTransferDragListener.java

License:Open Source License

protected void revertModelSelection() {
    List list = new ArrayList();
    Object editpart;//from  ww  w  .  j a  v a2  s.  c om
    for (int i = 0; i < modelSelection.size(); i++) {
        editpart = getViewer().getEditPartRegistry().get(modelSelection.get(i));
        if (editpart != null)
            list.add(editpart);
    }
    getViewer().setSelection(new StructuredSelection(list));
    modelSelection = null;
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.dialogs.CrucibleEditCommentDialog.java

License:Open Source License

protected void createCombo(Composite parent, final CustomFieldDef customField) {
    ((GridLayout) parent.getLayout()).numColumns++;
    Label label = new Label(parent, SWT.NONE);
    label.setText("Select " + customField.getName());
    ((GridLayout) parent.getLayout()).numColumns++;
    ComboViewer comboViewer = new ComboViewer(parent);
    comboViewer.setContentProvider(new ArrayContentProvider());

    comboViewer.setLabelProvider(new LabelProvider() {
        @Override//from w w w  .java 2s  .  co m
        public String getText(Object element) {
            CustomFieldValue fieldValue = (CustomFieldValue) element;
            return fieldValue.getName();
        }
    });
    final ArrayList<CustomFieldValue> values = MiscUtil.buildArrayList(EMPTY_CUSTOM_FIELD_VALUE);
    values.addAll(customField.getValues());
    comboViewer.setInput(values);
    comboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtonsState();
        }
    });

    // setting default values for combo
    final CustomField commentCustomField = comment.getCustomFields().get(customField.getName());
    if (commentCustomField != null) {
        for (CustomFieldValue value : customField.getValues()) {
            if (value.getName().equals(commentCustomField.getValue())) {
                ISelection selection = new StructuredSelection(MiscUtil.buildArrayList(value));
                comboViewer.setSelection(selection, true);
                break;
            }
        }
    } else {
        comboViewer.setSelection(new StructuredSelection(MiscUtil.buildArrayList(EMPTY_CUSTOM_FIELD_VALUE)),
                true);
    }

    customCombos.put(customField, comboViewer);
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.editor.parts.AbstractCommentPart.java

License:Open Source License

@Override
protected List<IReviewAction> getToolbarActions(boolean isExpanded) {
    List<IReviewAction> actions = new ArrayList<IReviewAction>();
    if (isExpanded) {
        if (!comment.isReply() && CrucibleUtil.canAddCommentToReview(crucibleReview)) {
            ReplyToCommentAction action = new ReplyToCommentAction();
            action.selectionChanged(new StructuredSelection(comment));
            actions.add(action);//from  ww  w .  j  ava 2s  . c  om
        }

        if (CrucibleUiUtil.canModifyComment(crucibleReview, comment)) {
            EditCommentAction action = new EditCommentAction();
            action.selectionChanged(new StructuredSelection(comment));
            actions.add(action);

            if (!comment.isReply() && comment.getReplies().size() > 0) {
                actions.add(new CannotRemoveCommentAction("Remove Comment", CrucibleImages.COMMENT_DELETE));
            } else {
                RemoveCommentAction action1 = new RemoveCommentAction();
                action1.selectionChanged(new StructuredSelection(comment));
                actions.add(action1);
            }

            if (CrucibleUtil.canPublishDraft(comment)) {
                PostDraftCommentAction action1 = new PostDraftCommentAction();
                action1.selectionChanged(new StructuredSelection(comment));
                actions.add(action1);
            }
        }
    }
    return actions;
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.wizards.CrucibleReviewDetailsPage.java

License:Open Source License

private void setInputAndInitialSelections() {
    updateInput();//from  w ww  . j  a  v a2 s.c o m

    final String lastSelectedProjectKey = CrucibleUiPlugin.getDefault()
            .getLastSelectedProjectKey(taskRepository);
    final BasicProject lastSelectedProject = CrucibleUiUtil.getCachedProject(taskRepository,
            lastSelectedProjectKey);
    if (lastSelectedProject != null) {
        projectsComboViewer.setSelection(new StructuredSelection(lastSelectedProject));
    } else {
        if (projectsComboViewer.getElementAt(0) != null) {
            projectsComboViewer.setSelection(new StructuredSelection(projectsComboViewer.getElementAt(0)));
        }
    }

    User currentUser = CrucibleUiUtil.getCurrentCachedUser(taskRepository);
    if (currentUser != null) {
        moderatorComboViewer.setSelection(new StructuredSelection(currentUser));
        authorComboViewer.setSelection(new StructuredSelection(currentUser));
    } else {
        if (moderatorComboViewer.getElementAt(0) != null) {
            moderatorComboViewer.setSelection(new StructuredSelection(moderatorComboViewer.getElementAt(0)));
        }
        if (authorComboViewer.getElementAt(0) != null) {
            authorComboViewer.setSelection(new StructuredSelection(authorComboViewer.getElementAt(0)));
        }
    }

    // restore checkboxes selection
    anyoneCanJoin.setSelection(CrucibleUiPlugin.getDefault().getAllowAnyoneOption(taskRepository));
    startReview.setSelection(CrucibleUiPlugin.getDefault().getStartReviewOption(taskRepository));
    updateReviewersControl();
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.wizards.CrucibleReviewDetailsPage.java

License:Open Source License

private void updateInputAndRestoreSelections() {
    BasicProject previousProject = (BasicProject) ((IStructuredSelection) projectsComboViewer.getSelection())
            .getFirstElement();/*  www .  j a v a  2  s .  com*/
    User previousModerator = (User) ((IStructuredSelection) moderatorComboViewer.getSelection())
            .getFirstElement();
    User previousAuthor = (User) ((IStructuredSelection) authorComboViewer.getSelection()).getFirstElement();

    updateInput();

    if (previousProject != null) {
        projectsComboViewer.setSelection(new StructuredSelection(previousProject));
    }

    if (previousModerator != null) {
        moderatorComboViewer.setSelection(new StructuredSelection(previousModerator));
    }

    if (previousAuthor != null) {
        authorComboViewer.setSelection(new StructuredSelection(previousAuthor));
    }
    updateReviewersControl();
}

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

License:Open Source License

private void initialize() {
    fHighlightingColorListViewer.setInput(fHighlightingColorList);
    fHighlightingColorListViewer//from w  w w  . j a  v a2  s  . co  m
            .setSelection(new StructuredSelection(fHighlightingColorListViewer.getElementAt(0)));
}

From source file:com.axmor.eclipse.typescript.editor.TypeScriptQuickOutlineDialog.java

License:Open Source License

/**
 * Performs passing to selected element with use of outline page functionality
 */// w w w .ja  va  2 s.  co m
private void gotoSelectedElement() {
    Object selectedElement = getSelectedElement();
    if (selectedElement == null) {
        return;
    }
    dispose();
    outlinePage.setSelection(new StructuredSelection(selectedElement));
}

From source file:com.axmor.eclipse.typescript.editor.TypeScriptQuickOutlineDialog.java

License:Open Source License

/**
 * Selects the first element in the tree which
 * matches the current filter pattern.//from  ww w. ja va  2 s  .co  m
 */
private void selectFirstMatch() {
    Tree tree = treeViewer.getTree();
    Object element = findFirstMatchToPattern(tree.getItems());
    if (element != null) {
        treeViewer.setSelection(new StructuredSelection(element), true);
    } else {
        treeViewer.setSelection(StructuredSelection.EMPTY);
    }
}

From source file:com.axmor.eclipse.typescript.editor.TypeScriptQuickOutlineDialog.java

License:Open Source License

@Override
public void setInput(Object input) {
    // Input comes from PDESourceInfoProvider.getInformation2()
    // The input should be a model object of some sort
    // Turn it into a structured selection and set the selection in the tree
    if (input != null) {
        treeViewer.setSelection(new StructuredSelection(input));
    }// w  ww .j  a  v a2  s .  co m
}