Example usage for org.eclipse.jface.action SubContributionItem setVisible

List of usage examples for org.eclipse.jface.action SubContributionItem setVisible

Introduction

In this page you can find the example usage for org.eclipse.jface.action SubContributionItem setVisible.

Prototype

@Override
    public void setVisible(boolean visible) 

Source Link

Usage

From source file:org.eclipse.sirius.table.ui.tools.internal.editor.DTableMenuListener.java

License:Open Source License

/**
 * @param navigateMenuItem//from   w w  w .  java2  s . c o  m
 * @param semanticElement
 */
private void createOpenAction(final SubContributionItem openRepresentation,
        final DSemanticDecorator decorator) {
    final EObject semanticElement = decorator.getTarget();
    final Session session = SessionManager.INSTANCE.getSession(semanticElement);
    if (session != null) {
        final Collection<DRepresentation> otherRepresentations = DialectManager.INSTANCE
                .getRepresentations(semanticElement, session);
        for (final DRepresentation representation : otherRepresentations) {
            if (!EcoreUtil.equals(dTable, representation) && isFromActiveViewpoint(session, representation)) {
                openRepresentation.setVisible(true);
                ((IMenuManager) openRepresentation.getInnerItem()).appendToGroup(
                        EXISTING_REPRESENTATION_GROUP_SEPARATOR,
                        MenuHelper.buildOpenRepresentationAction(session, representation, adapterFactory));
            }
        }
        if (decorator instanceof DRepresentationElement) {
            if (buildOpenRepresentationsMenu((IMenuManager) openRepresentation.getInnerItem(), decorator,
                    session)) {
                // If at least one navigable representation menu
                // has been created, we have to make the navigate menu
                // visible
                openRepresentation.setVisible(true);
            }
        }
    }
}

From source file:org.eclipse.sirius.table.ui.tools.internal.editor.DTableMenuListener.java

License:Open Source License

private void addExportMenu(final IMenuManager manager) {
    // Create a new sub-menu manager
    final MenuManager exportMenuManager = new MenuManager("Export", DTableMenuListener.MENU_EXPORT_ID);
    // Create the item to add to the main manager
    final SubContributionItem menuItem = new SubContributionItem(exportMenuManager);
    menuItem.setVisible(true);
    manager.add(menuItem);//from ww  w.  ja v a  2  s . c om
    exportMenuManager.add(new Separator(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR));
    final IAction action = new Action("CSV",
            DTableViewerManager.getImageRegistry().getDescriptor(DTableViewerManager.EXPORT_IMG)) {

        /**
         * {@inheritDoc}
         * 
         * @see org.eclipse.jface.action.Action#run()
         */
        @Override
        public void run() {
            final IHandlerService handlerService = (IHandlerService) treeViewManager.getEditor().getSite()
                    .getService(IHandlerService.class);
            try {
                handlerService.executeCommand("org.eclipse.sirius.table.ui.exportToCsv", null); //$NON-NLS-1$
            } catch (final CommandException ex) {
                throw new RuntimeException("export to csv command not found");
            }
        }
    };
    exportMenuManager.appendToGroup(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR, action);
}

From source file:org.eclipse.sirius.table.ui.tools.internal.editor.DTableMenuListener.java

License:Open Source License

/**
 * Add the viewpoint sub menu and its actions if needed.
 * /*from w  w w  .java  2  s  . c  o  m*/
 * @param manager
 *            The menu manager
 */
private void addHideRevealMenu(final IMenuManager manager) {
    // Create a new sub-menu manager
    final MenuManager hideRevealMenuManager = new MenuManager("Show/Hide",
            DTableMenuListener.MENU_HIDEREVEAL_ID);
    // Create the item to add to the main manager
    final SubContributionItem viewpointMenuItem = new SubContributionItem(hideRevealMenuManager);
    viewpointMenuItem.setVisible(true);
    manager.add(viewpointMenuItem);
    hideRevealMenuManager.add(new Separator(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR));

    // Columns visibility
    DColumn activeColumn = null;
    if (treeViewManager.getActiveColumn() > 0) {
        activeColumn = dTable.getColumns().get(treeViewManager.getActiveColumn() - 1);
    }

    if (activeColumn != null && activeColumn.isVisible()) {
        hideColumnAction.setColumn(activeColumn);
        if (hideColumnAction.isEnabled()) {
            hideRevealMenuManager.appendToGroup(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR, hideColumnAction);
        }
    }

    hideRevealMenuManager.appendToGroup(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR, showAllColumnsAction);

    hideRevealMenuManager.appendToGroup(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR, hideRevealColumnsAction);

    hideRevealMenuManager.appendToGroup(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR, new Separator());

    // Lines visibility
    final Collection<DLine> selectedLines = treeViewManager.getSelectedLines();
    if (selectedLines != null && !selectedLines.isEmpty()) {
        Predicate<DLine> isVisible = new Predicate<DLine>() {
            public boolean apply(DLine input) {
                return input.isVisible();
            }
        };
        Iterable<DLine> visibleSelection = Iterables.filter(selectedLines, isVisible);

        hideLineAction.setLines(Lists.newArrayList(visibleSelection));
        if (hideLineAction.isEnabled()) {
            hideRevealMenuManager.appendToGroup(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR, hideLineAction);
        }
    }
    hideRevealMenuManager.appendToGroup(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR, showAllLinesAction);

    hideRevealMenuManager.appendToGroup(DTableMenuListener.VIEWPOINT_GROUP_SEPARATOR, hideRevealLinesAction);
}

From source file:org.eclipse.sirius.table.ui.tools.internal.editor.DTableMenuListener.java

License:Open Source License

private void createDetailsActions(final DTableElement currentElement, final SubContributionItem newMenuItems) {
    if (currentElement.getMapping() != null) {
        final Session session = currentElement.getTarget() != null
                ? SessionManager.INSTANCE.getSession(currentElement.getTarget())
                : null;//from  w  ww.  java  2  s . c  om
        if (session != null) {
            for (RepresentationCreationDescription desc : currentElement.getMapping().getDetailDescriptions()) {
                boolean append = true;
                if (!isFromActiveViewpoint(session, desc.getRepresentationDescription())) {
                    append = false;
                }

                final String precondition = desc.getPrecondition();
                if (append && !StringUtil.isEmpty(precondition)) {
                    append = false;
                    final IInterpreter interpreter = SiriusPlugin.getDefault().getInterpreterRegistry()
                            .getInterpreter(currentElement.getTarget());
                    try {
                        append = interpreter.evaluateBoolean(currentElement.getTarget(), precondition);
                    } catch (final EvaluationException e) {
                        // do nothing
                    }
                }
                if (append) {
                    newMenuItems.setVisible(true);
                    ((IMenuManager) newMenuItems.getInnerItem()).appendToGroup(
                            NEW_REPRESENTATION_GROUP_SEPARATOR,
                            new CreateRepresentationFromRepresentationCreationDescription(desc, currentElement,
                                    treeViewManager.getEditingDomain(),
                                    treeViewManager.getTableCommandFactory()));
                }
            }
        }
    }
}

From source file:org.eclipse.sirius.tree.ui.tools.internal.editor.DTreeMenuListener.java

License:Open Source License

/**
 * @param openMenuItem//from   w  w w.  j a  v a 2 s .c  o m
 * @param semanticElement
 */
private void createOpenAction(final SubContributionItem openItem, final DSemanticDecorator decorator) {
    final EObject semanticElement = decorator.getTarget();
    final Session session = SessionManager.INSTANCE.getSession(semanticElement);
    if (session != null) {
        final Collection<DRepresentation> otherRepresentations = DialectManager.INSTANCE
                .getRepresentations(semanticElement, session);
        for (final DRepresentation representation : otherRepresentations) {
            if (!EcoreUtil.equals(dTree, representation) && isFromActiveViewpoint(session, representation)) {
                openItem.setVisible(true);
                ((IMenuManager) openItem.getInnerItem()).appendToGroup(EXISTING_REPRESENTATION_GROUP_SEPARATOR,
                        MenuHelper.buildOpenRepresentationAction(session, representation, adapterFactory));
            }
        }
        if (decorator instanceof DRepresentationElement) {
            if (buildOpenRepresentationsMenu((IMenuManager) openItem.getInnerItem(),
                    (DRepresentationElement) decorator, session)) {
                // if at least one navigable representation menu
                // has been created, we have to make the navigate menu
                // visible
                openItem.setVisible(true);
            }
        }
    }
}

From source file:org.eclipse.sirius.tree.ui.tools.internal.editor.DTreeMenuListener.java

License:Open Source License

private void createDetailsActions(final DTreeItem currentElement, final SubContributionItem newMenuItem) {
    if (currentElement.getMapping() != null) {
        final Session session = currentElement.getTarget() != null
                ? SessionManager.INSTANCE.getSession(currentElement.getTarget())
                : null;//from   www . jav a2 s . com
        if (session != null) {
            for (RepresentationCreationDescription desc : currentElement.getMapping().getDetailDescriptions()) {
                boolean append = true;
                if (!isFromActiveViewpoint(session, desc.getRepresentationDescription())) {
                    append = false;
                }

                final String precondition = desc.getPrecondition();
                if (append && !StringUtil.isEmpty(precondition)) {
                    append = false;
                    final IInterpreter interpreter = SiriusPlugin.getDefault().getInterpreterRegistry()
                            .getInterpreter(currentElement.getTarget());
                    try {
                        append = interpreter.evaluateBoolean(currentElement.getTarget(), precondition);
                    } catch (final EvaluationException e) {
                        // do nothing
                    }
                }
                if (append) {
                    newMenuItem.setVisible(true);
                    ((IMenuManager) newMenuItem.getInnerItem()).appendToGroup(
                            NEW_REPRESENTATION_GROUP_SEPARATOR,
                            new CreateRepresentationFromRepresentationCreationDescription(desc, currentElement,
                                    treeViewManager.getEditingDomain(),
                                    treeViewManager.getTreeCommandFactory()));
                }
            }
        }
    }
}