Example usage for org.eclipse.jface.viewers AbstractTreeViewer ALL_LEVELS

List of usage examples for org.eclipse.jface.viewers AbstractTreeViewer ALL_LEVELS

Introduction

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

Prototype

int ALL_LEVELS

To view the source code for org.eclipse.jface.viewers AbstractTreeViewer ALL_LEVELS.

Click Source Link

Document

Constant indicating that all levels of the tree should be expanded or collapsed.

Usage

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.commands.handlers.NewReviewItemHandler.java

License:Open Source License

/**
 * Method addReviewItemToExistingFileContext.
 * /*from   w w w.j a  v  a 2  s .  c o  m*/
 * @param aContainer
 *            R4EUISelectionContainer
 * @param aUIPosition
 *            IR4EUIPosition
 * @throws ResourceHandlingException
 * @throws OutOfSyncException
 */
private void addReviewItemToExistingFileContext(R4EUISelectionContainer aContainer, IR4EUIPosition aUIPosition)
        throws ResourceHandlingException, OutOfSyncException {

    final R4EUISelection uiSelection = aContainer.createSelection((R4EUITextPosition) aUIPosition);
    R4EUIModelController.setJobInProgress(false);
    UIUtils.setNavigatorViewFocus(uiSelection, AbstractTreeViewer.ALL_LEVELS);
}

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.commands.handlers.PasteElementHandler.java

License:Open Source License

/**
 * Method execute.//ww w .  java2s . c  om
 * 
 * @param event
 *            ExecutionEvent
 * @return Object
 * @see org.eclipse.core.commands.IHandler#execute(ExecutionEvent)
 */
public Object execute(final ExecutionEvent event) {

    final List<IR4EUIModelElement> selectedElements = UIUtils.getCommandUIElements();

    final Job job = new Job(COMMAND_MESSAGE) {
        public String familyName = R4EUIConstants.R4E_UI_JOB_FAMILY;

        @Override
        public boolean belongsTo(Object family) {
            return familyName.equals(family);
        }

        @Override
        public IStatus run(IProgressMonitor monitor) {

            R4EUIModelController.setJobInProgress(true);
            for (IR4EUIModelElement target : selectedElements) {
                if (target != null) {
                    final Object[] sourceSelection = new Object[1];
                    Display.getDefault().syncExec(new Runnable() {
                        public void run() {
                            sourceSelection[0] = R4EUIModelController.getNavigatorView().getClipboardContents();
                        }
                    });

                    Object sourceElement = null;
                    if (null != sourceSelection[0]) {
                        for (final Iterator<?> iterator = ((IStructuredSelection) sourceSelection[0])
                                .iterator(); iterator.hasNext();) {
                            sourceElement = iterator.next();
                            if (target instanceof R4EUIContent && sourceElement instanceof R4EUIAnomalyBasic
                                    && null == AnomalyUtils.isAnomalyExist(
                                            (R4EUIFileContext) target.getParent().getParent(),
                                            ((R4EUIContent) target).getPosition(),
                                            ((R4EUIAnomalyBasic) sourceElement).getAnomaly()
                                                    .getDescription())) {
                                try {
                                    //Pasting the Anomaly into content creates a cloned linked anomaly
                                    AnomalyUtils.cloneLinkedAnomaly((R4EUIContent) target,
                                            (R4EUIAnomalyBasic) sourceElement);
                                } catch (ResourceHandlingException e) {
                                    UIUtils.displayResourceErrorDialog(e);
                                } catch (OutOfSyncException e) {
                                    UIUtils.displaySyncErrorDialog(e);
                                }
                            } else if (target instanceof R4EUIAnomalyBasic
                                    && sourceElement instanceof R4EUIComment) {
                                if (null == AnomalyUtils.isCommentExist((R4EUIAnomalyBasic) target,
                                        ((R4EUIComment) sourceElement).getComment().getDescription())) {
                                    try {
                                        //Pasting the comment into the anomaly copies it to this anomaly
                                        IR4EUIModelElement newUIComment = ((R4EUIAnomalyBasic) target)
                                                .createChildren(((R4EUIComment) sourceElement).getComment());
                                        UIUtils.setNavigatorViewFocus(newUIComment,
                                                AbstractTreeViewer.ALL_LEVELS);
                                    } catch (ResourceHandlingException e) {
                                        UIUtils.displayResourceErrorDialog(e);
                                    } catch (OutOfSyncException e) {
                                        UIUtils.displaySyncErrorDialog(e);
                                    } catch (CompatibilityException e) {
                                        UIUtils.displayCompatibilityErrorDialog(e);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            R4EUIModelController.setJobInProgress(false);
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setUser(false);
    job.schedule();
    return null;
}

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIAnomalyBasic.java

License:Open Source License

/**
 * Method createComment.// w  w w. j  a v a 2s.  c om
 * 
 * @param aRejectionComment
 *            - boolean
 * @return boolean
 */
public boolean createComment(boolean aRejectionComment) {

    //Get comment details from user
    final ICommentInputDialog dialog = R4EUIDialogFactory.getInstance().getCommentInputDialog();
    final IR4EUIModelElement commentParent = this;
    final int[] result = new int[1]; //We need this to be able to pass the result value outside.  This is safe as we are using SyncExec
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            result[0] = dialog.open();
        }
    });

    if (result[0] == Window.OK) {
        final Job job = new Job(CREATE_COMMENT_MESSAGE) {
            public String familyName = R4EUIConstants.R4E_UI_JOB_FAMILY;

            @Override
            public boolean belongsTo(Object family) {
                return familyName.equals(family);
            }

            @Override
            public IStatus run(IProgressMonitor monitor) {

                try {
                    //Create comment model element
                    final R4EUIReviewBasic uiReview = R4EUIModelController.getActiveReview();
                    final R4EParticipant participant = uiReview
                            .getParticipant(R4EUIModelController.getReviewer(), true);

                    final R4EComment comment = R4EUIModelController.FModelExt.createR4EComment(participant,
                            fAnomaly);
                    final Long bookNum = R4EUIModelController.FResourceUpdater.checkOut(comment,
                            R4EUIModelController.getReviewer());
                    comment.setDescription(dialog.getCommentValue());
                    R4EUIModelController.FResourceUpdater.checkIn(bookNum);

                    //Create and set UI model element
                    final R4EUIComment uiComment = new R4EUIComment(commentParent, comment);
                    addChildren(uiComment);
                    R4EUIModelController.setJobInProgress(false);
                    UIUtils.setNavigatorViewFocus(uiComment, AbstractTreeViewer.ALL_LEVELS);
                } catch (ResourceHandlingException e) {
                    UIUtils.displayResourceErrorDialog(e);
                } catch (OutOfSyncException e) {
                    UIUtils.displaySyncErrorDialog(e);
                }
                monitor.done();
                return Status.OK_STATUS;
            }
        };
        job.setUser(true);
        job.schedule();
    } else {
        if (aRejectionComment) {
            return false;
        }
    }
    return true;
}

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.model.R4EUIAnomalyContainer.java

License:Open Source License

/**
 * Method createAnomaly Creates a new Anomaly from the user dialog
 * //from   w w  w .j  a  v  a  2s  . c  o  m
 * @param aFile
 *            R4EFileVersion
 * @param aUiPosition
 *            - the position of the anomaly to create
 * @param aClone
 *            - flag set if this is a cloned anomaly
 */
public void createAnomaly(final R4EUIFileContext aFile, final R4EUITextPosition aUiPosition, boolean aClone) {

    //Get anomaly details from user
    final IAnomalyInputDialog dialog;
    if (aClone) {
        dialog = R4EUIDialogFactory.getInstance().getCloneAnomalyInputDialog();
    } else {
        dialog = R4EUIDialogFactory.getInstance().getNewAnomalyInputDialog();
    }
    final int[] result = new int[1]; //We need this to be able to pass the result value outside.  This is safe as we are using SyncExec
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            result[0] = dialog.open();
        }
    });

    //Create actual model element
    if (result[0] == Window.OK) {
        final Job job = new Job(CREATE_ANOMALY_MESSAGE) {
            public String familyName = R4EUIConstants.R4E_UI_JOB_FAMILY;

            @Override
            public boolean belongsTo(Object family) {
                return familyName.equals(family);
            }

            @Override
            public IStatus run(IProgressMonitor monitor) {

                //First check if the anomaly already exist
                final String existingAnomalyName = AnomalyUtils.isAnomalyExist(aFile, aUiPosition,
                        dialog.getAnomalyDescriptionValue());
                if (null == existingAnomalyName) {
                    //Create anomaly model element
                    try {
                        final R4EUIReviewBasic uiReview = R4EUIModelController.getActiveReview();
                        final R4EParticipant participant = uiReview
                                .getParticipant(R4EUIModelController.getReviewer(), true);
                        final R4EAnomaly anomaly = R4EUIModelController.FModelExt.createR4EAnomaly(participant);
                        final Long bookNum = R4EUIModelController.FResourceUpdater.checkOut(anomaly,
                                R4EUIModelController.getReviewer());
                        setAnomalyWithDialogValues(anomaly, dialog);
                        R4EUIModelController.FResourceUpdater.checkIn(bookNum);
                        final R4EUIAnomalyBasic uiAnomaly = createAnomalyDetails(anomaly,
                                aFile.getTargetFileVersion(), aUiPosition);
                        R4EUIModelController.setJobInProgress(false);
                        UIUtils.setNavigatorViewFocus(uiAnomaly, AbstractTreeViewer.ALL_LEVELS);

                        //Add inline anomaly to editor (if applicable)
                        Display.getDefault().syncExec(new Runnable() {
                            public void run() {
                                UIUtils.addAnnotation(uiAnomaly, aFile);
                            }
                        });

                    } catch (ResourceHandlingException e) {
                        UIUtils.displayResourceErrorDialog(e);
                    } catch (OutOfSyncException e) {
                        UIUtils.displaySyncErrorDialog(e);
                    }
                    monitor.done();
                    return Status.OK_STATUS;
                } else {
                    String msg = "Anomaly with same description already exist:" + R4EUIConstants.LINE_FEED
                            + "Anomaly: " + existingAnomalyName + R4EUIConstants.LINE_FEED + "File: "
                            + aFile.getFileContext().getTarget().getName() + R4EUIConstants.LINE_FEED
                            + "Position: " + aUiPosition.toString();
                    R4EUIPlugin.Ftracer.traceWarning(msg);
                    final ErrorDialog dialog = new ErrorDialog(null, R4EUIConstants.DIALOG_TITLE_ERROR,
                            "Cannot Add Anomaly",
                            new Status(IStatus.WARNING, R4EUIPlugin.PLUGIN_ID, 0, msg, null), IStatus.WARNING);
                    Display.getDefault().syncExec(new Runnable() {
                        public void run() {
                            dialog.open();
                        }
                    });

                    monitor.done();
                    return Status.CANCEL_STATUS;
                }
            }
        };
        job.setUser(true);
        job.schedule();
    }
}

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.navigator.R4EUIElementDropAdapter.java

License:Open Source License

/**
 * Method declared on ViewerDropAdapter//from  w w  w . jav a 2s.co  m
 * 
 * @param aData
 *            - Object
 */
@Override
public boolean performDrop(Object aData) {
    if (null != aData) {
        R4EUIModelElement target = (R4EUIModelElement) getCurrentTarget();
        if (target != null) {
            Object[] sourceElements = ((IStructuredSelection) aData).toArray();

            for (Object sourceElement : sourceElements) {
                if (target instanceof R4EUIContent && sourceElement instanceof R4EUIAnomalyBasic) {
                    if (null == AnomalyUtils.isAnomalyExist((R4EUIFileContext) target.getParent().getParent(),
                            ((R4EUIContent) target).getPosition(),
                            ((R4EUIAnomalyBasic) sourceElement).getAnomaly().getDescription())) {
                        try {
                            //Dropping the anomaly into content creates a cloned linked anomaly
                            AnomalyUtils.cloneLinkedAnomaly((R4EUIContent) target,
                                    (R4EUIAnomalyBasic) sourceElement);
                        } catch (ResourceHandlingException e) {
                            UIUtils.displayResourceErrorDialog(e);
                        } catch (OutOfSyncException e) {
                            UIUtils.displaySyncErrorDialog(e);
                        }
                    }
                } else if (target instanceof R4EUIAnomalyBasic && sourceElement instanceof R4EUIComment) {
                    if (null == AnomalyUtils.isCommentExist((R4EUIAnomalyBasic) target,
                            ((R4EUIComment) sourceElement).getComment().getDescription())) {
                        try {
                            //Dropping the comment into the Anomaly copies it to this anomaly
                            IR4EUIModelElement newUIComment = ((R4EUIAnomalyBasic) target)
                                    .createChildren(((R4EUIComment) sourceElement).getComment());
                            UIUtils.setNavigatorViewFocus(newUIComment, AbstractTreeViewer.ALL_LEVELS);
                        } catch (ResourceHandlingException e) {
                            UIUtils.displayResourceErrorDialog(e);
                        } catch (OutOfSyncException e) {
                            UIUtils.displaySyncErrorDialog(e);
                        } catch (CompatibilityException e) {
                            UIUtils.displayCompatibilityErrorDialog(e);
                        }
                    }
                }
            }
            return true;
        }
    }
    return false;
}

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.utils.AnomalyUtils.java

License:Open Source License

/**
 * Method addAnomalyToNewFileContext./*  w  ww  .ja  v  a  2  s  .  c  om*/
 * 
 * @param aBaseFileVersion
 *            R4EFileVersion
 * @param aTargetFileVersion
 *            R4EFileVersion
 * @param aUIPosition
 *            IR4EUIPosition
 */
private static void addAnomalyToNewFileContext(final R4EFileVersion aBaseFileVersion,
        final R4EFileVersion aTargetFileVersion, final IR4EUIPosition aUIPosition, final boolean aClone) {

    final R4EAnomaly tempAnomaly = R4EUIAnomalyContainer.createDetachedAnomaly(aClone);

    if (null != tempAnomaly) {

        final Job job = new Job(R4EUIAnomalyContainer.CREATE_ANOMALY_MESSAGE) {
            public String familyName = R4EUIConstants.R4E_UI_JOB_FAMILY;

            @Override
            public boolean belongsTo(Object family) {
                return familyName.equals(family);
            }

            @Override
            public IStatus run(IProgressMonitor monitor) {
                try {
                    final R4EUIReviewBasic uiReview = R4EUIModelController.getActiveReview();
                    final R4EUIReviewItem uiReviewItem = uiReview
                            .createResourceReviewItem(aTargetFileVersion.getName());
                    if (null == uiReviewItem) {
                        return Status.CANCEL_STATUS;
                    }
                    final R4EUIFileContext uiFileContext = uiReviewItem.createFileContext(aBaseFileVersion,
                            aTargetFileVersion, null);
                    if (null == uiFileContext) {
                        uiReview.removeChildren(uiReviewItem, false);
                        return Status.CANCEL_STATUS;
                    }

                    final R4EUIAnomalyContainer uiAnomalyContainer = uiFileContext.getAnomalyContainerElement();
                    final R4EUIAnomalyBasic uiAnomaly = uiAnomalyContainer.createAnomalyFromDetached(
                            aTargetFileVersion, tempAnomaly, (R4EUITextPosition) aUIPosition, false);
                    R4EUIModelController.setJobInProgress(false);
                    UIUtils.setNavigatorViewFocus(uiAnomaly, AbstractTreeViewer.ALL_LEVELS);
                } catch (ResourceHandlingException e) {
                    UIUtils.displayResourceErrorDialog(e);
                } catch (OutOfSyncException e) {
                    UIUtils.displaySyncErrorDialog(e);
                }
                monitor.done();
                return Status.OK_STATUS;
            }
        };
        job.setUser(true);
        job.schedule();
    }
}

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.utils.AnomalyUtils.java

License:Open Source License

/**
 * Method cloneLinkedAnomaly.// ww w.  j  a v a 2s  .c o  m
 * 
 * @param aElement
 *            R4EUIContent
 * @throws OutOfSyncException
 * @throws ResourceHandlingException
 */
public static void cloneLinkedAnomaly(R4EUIContent aTargetContent, R4EUIAnomalyBasic aSourceAnomaly)
        throws ResourceHandlingException, OutOfSyncException {
    final R4EUIFileContext fileContext = (R4EUIFileContext) aTargetContent.getParent().getParent();
    final R4EUIAnomalyContainer container = (fileContext.getAnomalyContainerElement());
    R4EUIAnomalyBasic newUiAnomaly = container.createAnomalyFromDetached(fileContext.getTargetFileVersion(),
            aSourceAnomaly.getAnomaly(), (R4EUITextPosition) aTargetContent.getPosition(), true);
    UIUtils.setNavigatorViewFocus(newUiAnomaly, AbstractTreeViewer.ALL_LEVELS);
}

From source file:org.eclipse.mylyn.wikitext.ui.editor.DefaultWikiTextSourceEditorOutline.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    super.createControl(parent);

    TreeViewer viewer = getTreeViewer();
    viewer.setUseHashlookup(true);/*  w w  w. j  a  va 2s .  c o  m*/
    viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    viewer.setContentProvider(new BaseWorkbenchContentProvider());
    viewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
    viewer.setInput(getEditor().getAdapter(OutlineItem.class));

    viewer.addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            revealInEditor(event.getSelection());
        }
    });
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            revealInEditor(event.getSelection());
        }
    });
    viewer.expandAll();

    updateSelectionToMatchEditor();

    new ToolTip(viewer.getControl(), ToolTip.RECREATE, false) {
        @Override
        protected Composite createToolTipContentArea(Event event, Composite parent) {

            Composite comp = new Composite(parent, SWT.NONE);
            comp.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));

            GridLayout gl = new GridLayout(1, false);
            gl.marginBottom = 2;
            gl.marginTop = 2;
            gl.marginHeight = 0;
            gl.marginWidth = 0;
            gl.marginLeft = 2;
            gl.marginRight = 2;
            gl.verticalSpacing = 1;
            comp.setLayout(gl);

            Object tipItem = getToolTipItem(new Point(event.x, event.y));
            if (tipItem instanceof OutlineItem) {
                OutlineItem outlineItem = (OutlineItem) tipItem;
                Label label = new Label(comp, SWT.WRAP);
                label.setBackground(comp.getBackground());
                label.setText(outlineItem.getTooltip());
            }

            return comp;
        }

        @Override
        protected boolean shouldCreateToolTip(Event event) {
            final Object eventItem = getToolTipItem(new Point(event.x, event.y));
            boolean shouldCreate = eventItem != null && eventItem instanceof OutlineItem
                    && super.shouldCreateToolTip(event);
            if (!shouldCreate) {
                hide();
            }
            return shouldCreate;
        }

        protected Object getToolTipItem(Point point) {
            TreeItem item = ((Tree) getTreeViewer().getControl()).getItem(point);
            if (item != null) {
                return item.getData();
            }
            return null;
        }
    };

    MenuManager manager = new MenuManager("#PopUp"); //$NON-NLS-1$
    manager.setRemoveAllWhenShown(true);
    manager.addMenuListener(new IMenuListener() {
        public void menuAboutToShow(IMenuManager menuManager) {
            contextMenuAboutToShow(menuManager);
        }
    });
    viewer.getTree().setMenu(manager.createContextMenu(viewer.getTree()));

}

From source file:org.eclipse.osee.framework.ui.skynet.action.ExpandAllAction.java

License:Open Source License

private void expandAll(IStructuredSelection selection) {
    Iterator<?> iter = selection.iterator();
    while (iter.hasNext()) {
        treeViewer.expandToLevel(iter.next(), AbstractTreeViewer.ALL_LEVELS);
    }/*  w  w w. j  av  a2  s .  c om*/
}

From source file:org.eclipse.osee.framework.ui.skynet.commandHandlers.ExpandTreeHandler.java

License:Open Source License

@Override
protected Object executeWithException(ExecutionEvent event, IStructuredSelection selection) {
    Iterator<?> iter = selection.iterator();
    while (iter.hasNext()) {
        treeViewer.expandToLevel(iter.next(), AbstractTreeViewer.ALL_LEVELS);
    }/*from  w  w w.j  a  va 2 s . c om*/
    return null;
}