Search in sources :

Example 1 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project cogtool by cogtool.

the class MenuFactory method addWindowMenu.

// addToCascade
protected static void addWindowMenu(Menu newWindowMenu, IWindowMenuData<?> menuData) {
    if (windowMenus.size() > 0) {
        copyExistingWindows(windowMenus.get(0), newWindowMenu);
    }
    // Add to global registry
    windowMenus.add(newWindowMenu);
    newWindowMenu.setData(menuData);
    // i.e. the RootView will not be added!
    if (menuData.getNexusData() != null) {
        Iterator<Menu> menus = windowMenus.iterator();
        while (menus.hasNext()) {
            Menu windowMenu = menus.next();
            Menu nexusCascade = null;
            // Remove the last item if it is the NO_WINDOWS_SENTINEL
            MenuItem[] nexusItems = windowMenu.getItems();
            if (nexusItems.length > 0) {
                MenuItem lastItem = nexusItems[nexusItems.length - 1];
                if (lastItem.getData() == NO_WINDOWS_SENTINEL) {
                    lastItem.dispose();
                    nexusCascade = createNexusCascade(windowMenu, -1, menuData);
                }
            }
            if (nexusCascade == null) {
                nexusCascade = ensureNexusCascade(windowMenu, nexusItems, menuData);
            }
            addToCascade(nexusCascade, menuData);
        }
        newWindowMenu.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                removeWindowMenu((Menu) e.getSource());
            }
        });
    } else {
        newWindowMenu.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                windowMenus.remove(e.getSource());
            }
        });
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 2 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project cogtool by cogtool.

the class MenuUtil method createMenuStep.

/**
     * Recursive support method for navigating the tree of
     * menu item definitions to construct actual menus and menu items.
     * <p>
     * Each menu item created is associated with its
     * <code>ListenerIdentifier</code>.
     */
protected static void createMenuStep(Shell shell, Menu parent, MenuItemDefinition defn, Boolean availability, Listener selectionListener, final ListenerIdentifierMap lIDMap) {
    if (defn.isSingle()) {
        SimpleMenuItemDefinition itemDef = (SimpleMenuItemDefinition) defn;
        renderShortcut(itemDef);
        final MenuItem item = addMenuItem(parent, itemDef.name, itemDef.image, itemDef.style, itemDef.accelerator, itemDef.enabledInitially, itemDef.selectedInitially);
        // pull the lid out to a local so the whole SimpleMenuItemDefinition
        // doesn't get stored in the dispose listener
        final ListenerIdentifier lid = itemDef.listenerID;
        if (lid != null) {
            // avoid separator
            // Associate LID with menu item so that it can be used to find
            // the associated semantic action by the selectionListener.
            item.setData(lid);
            item.addListener(SWT.Selection, selectionListener);
            lIDMap.addWidget(lid, item, availability);
            // If this menu item gets disposed, as for example from a
            // dynamic menu, we don't want the LID still pointing at it
            item.addDisposeListener(new DisposeListener() {

                public void widgetDisposed(DisposeEvent e) {
                    lIDMap.removeWidget(lid, item);
                }
            });
        }
    } else {
        CascadingMenuItemDefinition itemDef = (CascadingMenuItemDefinition) defn;
        MenuItem item = addMenuItem(parent, itemDef.name, itemDef.image, SWT.CASCADE);
        Menu cascadeParent = new Menu(shell, SWT.DROP_DOWN);
        item.setMenu(cascadeParent);
        item.setData(itemDef.data);
        if (itemDef.menuItems != null) {
            for (MenuItemDefinition menuItem : itemDef.menuItems) {
                createMenuStep(shell, cascadeParent, menuItem, availability, selectionListener, lIDMap);
            }
        }
    }
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 3 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project tdi-studio-se by Talend.

the class SchemaXMLLinker method initColors.

/**
     * amaumont Comment method "initColors".
     * 
     * @param display
     */
private void initColors(Display display) {
    // selectedLoopLinkColor = new Color(display, 255, 131, 255);
    // light blue
    selectedLoopLinkColor = new Color(display, 110, 168, 255);
    selectedRelativeLinkColor = new Color(display, 110, 168, 0);
    getSource().addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            selectedLoopLinkColor.dispose();
            selectedRelativeLinkColor.dispose();
            getSource().removeDisposeListener(this);
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Color(org.eclipse.swt.graphics.Color) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 4 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project tdi-studio-se by Talend.

the class TabFolderEditors method addListenersToOutputButtons.

/**
     * DOC amaumont Comment method "addListenersToInputButtons".
     */
private void addListenersToOutputButtons() {
    MetadataToolbarEditorView toolBar = outputMetaEditor.getToolBar();
    outputToolBarButtons = toolBar.getButtons();
    beforeCommandListenerForOutputButtons = new IExtendedButtonListener() {

        public void handleEvent(ExtendedButtonEvent event) {
            TableViewerCreator tableViewerCreator = mapperManager.getUiManager().getCurrentSelectedOutputTableView().getTableViewerCreatorForColumns();
            if (tableViewerCreator != null) {
                tableViewerCreator.applyActivatedCellEditor();
            }
        }
    };
    for (ExtendedPushButton extendedPushButton : outputToolBarButtons) {
        extendedPushButton.addListener(beforeCommandListenerForOutputButtons, true);
        if (extendedPushButton instanceof RemovePushButton && !mapperManager.componentIsReadOnly()) {
            removeButton = (RemovePushButtonForExtendedTable) extendedPushButton;
        }
    }
    if (removeButton != null) {
        final TableViewerCreator tableViewerCreator = removeButton.getExtendedTableViewer().getTableViewerCreator();
        tableViewerCreator.getSelectionHelper().addAfterSelectionListener(new ILineSelectionListener() {

            public void handle(LineSelectionEvent e) {
                for (TableItem item : tableViewerCreator.getTable().getSelection()) {
                    if (item.getData() instanceof MetadataColumn) {
                        MetadataColumn column = (MetadataColumn) item.getData();
                        removeButton.getButton().setEnabled(!column.isCustom());
                        break;
                    }
                }
            }
        });
    }
    this.addDisposeListener(new DisposeListener() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
             */
        public void widgetDisposed(DisposeEvent e) {
            for (ExtendedPushButton extendedPushButton : outputToolBarButtons) {
                extendedPushButton.removeListener(beforeCommandListenerForOutputButtons, true);
            }
        }
    });
}
Also used : MetadataColumn(org.talend.core.model.metadata.MetadataColumn) DisposeListener(org.eclipse.swt.events.DisposeListener) LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) TableViewerCreator(org.talend.commons.ui.swt.tableviewer.TableViewerCreator) RemovePushButton(org.talend.commons.ui.swt.advanced.dataeditor.button.RemovePushButton) ExtendedPushButton(org.talend.commons.ui.swt.advanced.dataeditor.control.ExtendedPushButton) TableItem(org.eclipse.swt.widgets.TableItem) MetadataToolbarEditorView(org.talend.core.ui.metadata.editor.MetadataToolbarEditorView) IExtendedButtonListener(org.talend.commons.ui.swt.extended.table.IExtendedButtonListener) ILineSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ExtendedButtonEvent(org.talend.commons.ui.swt.extended.table.ExtendedButtonEvent)

Example 5 with DisposeEvent

use of org.eclipse.swt.events.DisposeEvent in project tdi-studio-se by Talend.

the class SQLResultComposite method createTabItem.

/**
     * 
     * DOC dev Comment method "createTabItem".
     * 
     * @throws Exception throw all exception
     */
private void createTabItem() throws Exception {
    lastTabNumber = lastTabNumber + 1;
    final CTabItem tabItem = new CTabItem(tabFolder, SWT.NULL);
    String labelText = Messages.getString("SQLResultComposite.Result") + ": " + lastTabNumber;
    tabItem.setText(labelText);
    //$NON-NLS-1$
    tabItem.setData("tabLabel", labelText);
    tabItem.setToolTipText(TextUtil.getWrappedText(sqlExecution.getSqlStatement()));
    Composite composite = new Composite(tabFolder, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginLeft = 0;
    layout.marginTop = 0;
    layout.marginBottom = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    tabItem.setControl(composite);
    tabItem.setData(sqlExecution);
    tabItem.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(final DisposeEvent e) {
            BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

                public void run() {
                    CTabItem tabItem = (CTabItem) e.getSource();
                    AbstractSQLExecution sqlExe = (AbstractSQLExecution) tabItem.getData();
                    sqlExe.stop();
                    tabItem.setData(null);
                    if (tabFolder != null && !tabFolder.isDisposed()) {
                        if (tabFolder.getItemCount() == 0) {
                            // this is last tab..
                            clearParent();
                            setDefaultMessage();
                        }
                    } else if (tabFolder.isDisposed()) {
                        clearParent();
                        setDefaultMessage();
                    }
                }
            });
        }
    });
    createHeaderComposite(composite, tabItem);
    createDetailComposite(composite, tabItem);
    // refresh view
    composite.layout();
    tabFolder.layout();
    tabFolder.redraw();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) AbstractSQLExecution(org.talend.sqlbuilder.sqlcontrol.AbstractSQLExecution) GridData(org.eclipse.swt.layout.GridData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) CTabItem(org.eclipse.swt.custom.CTabItem)

Aggregations

DisposeEvent (org.eclipse.swt.events.DisposeEvent)365 DisposeListener (org.eclipse.swt.events.DisposeListener)362 GridData (org.eclipse.swt.layout.GridData)103 Composite (org.eclipse.swt.widgets.Composite)91 SelectionEvent (org.eclipse.swt.events.SelectionEvent)88 GridLayout (org.eclipse.swt.layout.GridLayout)76 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)71 Image (org.eclipse.swt.graphics.Image)53 Cursor (org.eclipse.swt.graphics.Cursor)49 Label (org.eclipse.swt.widgets.Label)42 ToolBar (org.eclipse.swt.widgets.ToolBar)42 Point (org.eclipse.swt.graphics.Point)38 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)37 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)36 Control (org.eclipse.swt.widgets.Control)36 Color (org.eclipse.swt.graphics.Color)35 FillLayout (org.eclipse.swt.layout.FillLayout)35 Event (org.eclipse.swt.widgets.Event)35 MouseEvent (org.eclipse.swt.events.MouseEvent)32 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)31