Search in sources :

Example 81 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project pentaho-kettle by pentaho.

the class RunConfigurationPopupMenuExtension method createItemPopupMenu.

private Menu createItemPopupMenu(Tree tree) {
    if (itemMenu == null) {
        itemMenu = new Menu(tree);
        MenuItem editMenuItem = new MenuItem(itemMenu, SWT.NONE);
        editMenuItem.setText(BaseMessages.getString(PKG, "RunConfigurationPopupMenuExtension.MenuItem.Edit"));
        editMenuItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent selectionEvent) {
                runConfigurationDelegate.edit(runConfiguration);
            }
        });
        MenuItem deleteMenuItem = new MenuItem(itemMenu, SWT.NONE);
        deleteMenuItem.setText(BaseMessages.getString(PKG, "RunConfigurationPopupMenuExtension.MenuItem.Delete"));
        deleteMenuItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent selectionEvent) {
                runConfigurationDelegate.delete(runConfiguration);
            }
        });
    }
    return itemMenu;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 82 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project pentaho-kettle by pentaho.

the class Spoon method addTabs.

private void addTabs() {
    if (tabComp != null) {
        tabComp.dispose();
    }
    tabComp = new Composite(sashform, SWT.BORDER);
    props.setLook(tabComp);
    tabComp.setLayout(new FillLayout());
    tabfolder = new TabSet(tabComp);
    tabfolder.setChangedFont(GUIResource.getInstance().getFontBold());
    final CTabFolder cTabFolder = tabfolder.getSwtTabset();
    props.setLook(cTabFolder, Props.WIDGET_STYLE_TAB);
    cTabFolder.addMenuDetectListener(new MenuDetectListener() {

        @Override
        public void menuDetected(MenuDetectEvent event) {
            org.eclipse.swt.graphics.Point real = new org.eclipse.swt.graphics.Point(event.x, event.y);
            org.eclipse.swt.graphics.Point point = display.map(null, cTabFolder, real);
            final CTabItem item = cTabFolder.getItem(point);
            if (item != null) {
                Menu menu = new Menu(cTabFolder);
                MenuItem closeItem = new MenuItem(menu, SWT.NONE);
                closeItem.setText(BaseMessages.getString(PKG, "Spoon.Tab.Close"));
                closeItem.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        int index = tabfolder.getSwtTabset().indexOf(item);
                        if (index >= 0) {
                            TabMapEntry entry = delegates.tabs.getTabs().get(index);
                            tabClose(entry.getTabItem());
                        }
                    }
                });
                MenuItem closeAllItems = new MenuItem(menu, SWT.NONE);
                closeAllItems.setText(BaseMessages.getString(PKG, "Spoon.Tab.CloseAll"));
                closeAllItems.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        for (TabMapEntry entry : delegates.tabs.getTabs()) {
                            tabClose(entry.getTabItem());
                        }
                    }
                });
                MenuItem closeOtherItems = new MenuItem(menu, SWT.NONE);
                closeOtherItems.setText(BaseMessages.getString(PKG, "Spoon.Tab.CloseOthers"));
                closeOtherItems.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent event) {
                        int index = tabfolder.getSwtTabset().indexOf(item);
                        if (index >= 0) {
                            TabMapEntry entry = delegates.tabs.getTabs().get(index);
                            for (TabMapEntry closeEntry : delegates.tabs.getTabs()) {
                                if (!closeEntry.equals(entry)) {
                                    tabClose(closeEntry.getTabItem());
                                }
                            }
                        }
                    }
                });
                menu.setLocation(real);
                menu.setVisible(true);
            }
        }
    });
    int[] weights = props.getSashWeights();
    sashform.setWeights(weights);
    sashform.setVisible(true);
    // Set a minimum width on the sash so that the view and design buttons
    // on the left panel are always visible.
    // 
    Control[] comps = sashform.getChildren();
    for (Control comp : comps) {
        if (comp instanceof Sash) {
            int limit = 10;
            final int SASH_LIMIT = Const.isOSX() ? 150 : limit;
            final Sash sash = (Sash) comp;
            sash.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    Rectangle rect = sash.getParent().getClientArea();
                    event.x = Math.min(Math.max(event.x, SASH_LIMIT), rect.width - SASH_LIMIT);
                    if (event.detail != SWT.DRAG) {
                        sash.setBounds(event.x, event.y, event.width, event.height);
                        sashform.layout();
                    }
                }
            });
        }
    }
    // methods: tabDeselected, tabClose,
    tabfolder.addListener(this);
// tabSelected
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) Rectangle(org.eclipse.swt.graphics.Rectangle) CTabItem(org.eclipse.swt.custom.CTabItem) Control(org.eclipse.swt.widgets.Control) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Composite(org.eclipse.swt.widgets.Composite) Sash(org.eclipse.swt.widgets.Sash) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) TabSet(org.pentaho.xul.swt.tab.TabSet) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener)

Example 83 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project pentaho-kettle by pentaho.

the class SpoonPerspectiveManager method initialize.

public void initialize() {
    XulToolbar mainToolbar = (XulToolbar) domContainer.getDocumentRoot().getElementById("main-toolbar");
    SwtDeck deck = (SwtDeck) domContainer.getDocumentRoot().getElementById("canvas-deck");
    int y = 0;
    int perspectiveIdx = 0;
    Class<? extends SpoonPerspective> perClass = null;
    List<SpoonPerspective> perspectives = getPerspectives();
    if (this.startupPerspective != null) {
        for (int i = 0; i < perspectives.size(); i++) {
            if (perspectives.get(i).getId().equals(this.startupPerspective)) {
                perspectiveIdx = i;
                break;
            }
        }
    }
    final List<PerspectiveData> perspectiveList = new ArrayList<>();
    final ToolBar swtToolbar = (ToolBar) mainToolbar.getManagedObject();
    final Shell shell = swtToolbar.getShell();
    final ToolItem perspectiveButton = new ToolItem(swtToolbar, SWT.DROP_DOWN, 7);
    perspectiveButton.setImage(GUIResource.getInstance().getImage("ui/images/perspective_changer.svg"));
    perspectiveButton.setToolTipText(BaseMessages.getString(PKG, "Spoon.Menu.View.Perspectives"));
    perspectiveButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Menu menu = new Menu(shell);
            for (final PerspectiveData perspectiveData : perspectiveList) {
                MenuItem item = new MenuItem(menu, SWT.CHECK);
                if (perspectiveData.isHidden()) {
                    item.setEnabled(false);
                }
                if (activePerspective.getId().equals(perspectiveData.getId())) {
                    item.setSelection(true);
                }
                item.setText(perspectiveData.getName());
                item.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent selectionEvent) {
                        Spoon.getInstance().loadPerspective(perspectiveData.getId());
                        swtToolbar.forceFocus();
                    }
                });
            }
            ToolItem item = (ToolItem) e.widget;
            Rectangle rect = item.getBounds();
            Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y + rect.height));
            menu.setLocation(pt.x, pt.y);
            menu.setVisible(true);
        }
    });
    for (final SpoonPerspective per : getPerspectives()) {
        if (installedPerspectives.contains(per)) {
            y++;
            continue;
        }
        String name = per.getDisplayName(LanguageChoice.getInstance().getDefaultLocale());
        PerspectiveData perspectiveData = new PerspectiveData(name, per.getId());
        if (Arrays.asList(defaultDisabled).contains(per.getId())) {
            perspectiveData.setHidden(true);
        }
        perspectiveList.add(perspectiveData);
        XulVbox box = deck.createVBoxCard();
        box.setId("perspective-" + per.getId());
        box.setFlex(1);
        deck.addChild(box);
        PerspectiveManager perspectiveManager = new PerspectiveManager(per, box, mainToolbar, perspectiveList, name);
        perspectiveManagerMap.put(per, perspectiveManager);
        // Need to force init for main perspective even if it won't be shown
        if (perspectiveIdx == y || y == 0) {
            if (perspectiveIdx == y) {
                // we have a startup perspective. Hold onto the class
                perClass = per.getClass();
            }
            // force init
            perspectiveManager.initializeIfNeeded();
        }
        y++;
        installedPerspectives.add(per);
    }
    deck.setSelectedIndex(perspectiveIdx);
    if (perClass != null) {
        // activate the startup perspective
        try {
            activatePerspective(perClass);
            // stop other perspectives from opening
            SpoonPerspectiveManager.getInstance().setForcePerspective(true);
        } catch (KettleException e) {
        // TODO Auto-generated catch block
        }
    }
}
Also used : SwtDeck(org.pentaho.ui.xul.swt.tags.SwtDeck) XulVbox(org.pentaho.ui.xul.containers.XulVbox) KettleException(org.pentaho.di.core.exception.KettleException) XulToolbar(org.pentaho.ui.xul.containers.XulToolbar) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Shell(org.eclipse.swt.widgets.Shell) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ToolItem(org.eclipse.swt.widgets.ToolItem)

Example 84 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project archi by archimatetool.

the class HintsView method selectionChanged.

public void selectionChanged(Object source, Object selected) {
    if (fActionPinContent.isChecked()) {
        return;
    }
    Object object = null;
    String key = null;
    // EClass (selected from Diagram Palette) so get Java class
    if (selected instanceof EClass) {
        EClass eClass = (EClass) selected;
        object = eClass.getInstanceClass();
    } else // Adaptable, dig in to get to get Element...
    if (selected instanceof IAdaptable) {
        // This first
        object = ((IAdaptable) selected).getAdapter(IHelpHintProvider.class);
        if (object == null) {
            object = ((IAdaptable) selected).getAdapter(IArchimateConcept.class);
        }
        if (object == null) {
            object = ((IAdaptable) selected).getAdapter(IDiagramModelObject.class);
        }
        if (object == null) {
            object = ((IAdaptable) selected).getAdapter(IDiagramModelConnection.class);
        }
        if (object == null) {
            object = ((IAdaptable) selected).getAdapter(IDiagramModel.class);
        }
    } else // Default
    {
        object = selected;
    }
    // Hint Provider, if set
    if (object instanceof IHelpHintProvider) {
        String title = ((IHelpHintProvider) object).getHelpHintTitle();
        String text = ((IHelpHintProvider) object).getHelpHintContent();
        if (StringUtils.isSet(title) || StringUtils.isSet(text)) {
            fTitleLabel.setText(title);
            Color color = getTitleColor(object);
            fTitleLabel.setBackground(new Color[] { color, ColorConstants.white }, new int[] { 80 }, false);
            text = makeHTMLEntry(text);
            fBrowser.setText(text);
            // $NON-NLS-1$
            fLastPath = "";
            return;
        }
    }
    // Archimate Diagram Model use Viewpoint as key
    if (object instanceof IArchimateDiagramModel) {
        key = ((IArchimateDiagramModel) object).getViewpoint();
    }
    Hint hint = getHintFromObject(object, key);
    if (hint != null) {
        if (fLastPath != hint.path) {
            // Title and Color
            Color color = getTitleColor(object);
            fTitleLabel.setBackground(new Color[] { color, ColorConstants.white }, new int[] { 80 }, false);
            fTitleLabel.setText(hint.title);
            // Load page
            fPageLoaded = false;
            fBrowser.setUrl(hint.path);
            fLastPath = hint.path;
            // Kludge for Mac/Safari when displaying hint on mouse rollover menu item in MagicConnectionCreationTool
            if (PlatformUtils.isMac() && source instanceof MenuItem) {
                _doMacWaitKludge();
            }
        }
    } else {
        // $NON-NLS-1$
        fBrowser.setText("");
        // $NON-NLS-1$
        fLastPath = "";
        // $NON-NLS-1$
        fTitleLabel.setText("");
        fTitleLabel.setBackground(ColorConstants.white);
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) EClass(org.eclipse.emf.ecore.EClass) Color(org.eclipse.swt.graphics.Color) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) MenuItem(org.eclipse.swt.widgets.MenuItem) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel)

Example 85 with MenuItem

use of org.eclipse.swt.widgets.MenuItem in project archi by archimatetool.

the class MagicConnectionCreationTool method addConnectionActions.

/**
 * Add Connection Actions going in both directions
 */
private void addConnectionActions(Menu menu, IArchimateConcept sourceConcept, IArchimateConcept targetConcept) {
    EClass[] forwardConnections = ArchimateModelUtils.getValidRelationships(sourceConcept, targetConcept);
    EClass[] reverseConnections = ArchimateModelUtils.getValidRelationships(targetConcept, sourceConcept);
    // Add forward direction connections
    for (EClass type : forwardConnections) {
        addConnectionAction(menu, type, false);
    }
    // Add reverse direction connections
    for (EClass type : reverseConnections) {
        addConnectionAction(menu, type, true);
    }
    // Add a separator only if we have both sets of items on the menu
    if (forwardConnections.length > 0 && reverseConnections.length > 0) {
        new MenuItem(menu, SWT.SEPARATOR, forwardConnections.length);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) MenuItem(org.eclipse.swt.widgets.MenuItem)

Aggregations

MenuItem (org.eclipse.swt.widgets.MenuItem)386 Menu (org.eclipse.swt.widgets.Menu)259 SelectionEvent (org.eclipse.swt.events.SelectionEvent)247 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)208 Event (org.eclipse.swt.widgets.Event)58 ArrayList (java.util.ArrayList)55 Point (org.eclipse.swt.graphics.Point)52 GridData (org.eclipse.swt.layout.GridData)49 Listener (org.eclipse.swt.widgets.Listener)48 SelectionListener (org.eclipse.swt.events.SelectionListener)46 Composite (org.eclipse.swt.widgets.Composite)43 GridLayout (org.eclipse.swt.layout.GridLayout)42 Rectangle (org.eclipse.swt.graphics.Rectangle)35 Label (org.eclipse.swt.widgets.Label)34 Shell (org.eclipse.swt.widgets.Shell)34 Table (org.eclipse.swt.widgets.Table)33 MenuEvent (org.eclipse.swt.events.MenuEvent)32 Button (org.eclipse.swt.widgets.Button)32 List (java.util.List)31 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)29