Search in sources :

Example 56 with IToolBarManager

use of org.eclipse.jface.action.IToolBarManager in project knime-core by knime.

the class NodeMonitorView method createPartControl.

/**
 * {@inheritDoc}
 */
@Override
public void createPartControl(final Composite parent) {
    // Toolbar
    IToolBarManager toolbarMGR = getViewSite().getActionBars().getToolBarManager();
    // create button which allows to "pin" selection:
    final RetargetAction pinButton = new RetargetAction("PinView", "Pin view to selected node", IAction.AS_CHECK_BOX);
    pinButton.setImageDescriptor(ImageDescriptor.createFromFile(this.getClass(), "icons/pin.png"));
    pinButton.setChecked(m_pinned);
    pinButton.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (pinButton.isChecked()) {
                m_pinned = true;
                m_lastSelectionWhilePinned = m_lastSelection;
            } else {
                m_pinned = false;
                selectionChanged(null, m_lastSelectionWhilePinned);
            }
        }
    });
    pinButton.setEnabled(true);
    toolbarMGR.add(pinButton);
    toolbarMGR.add(new Separator());
    // configure drop down menu
    IMenuManager dropDownMenu = getViewSite().getActionBars().getMenuManager();
    // drop down menu entry for outport table:
    final RetargetAction menuentrytable = new RetargetAction("OutputTable", "Show Output Table", IAction.AS_RADIO_BUTTON);
    menuentrytable.setChecked(DISPLAYOPTIONS.TABLE.equals(m_choice));
    menuentrytable.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (menuentrytable.isChecked()) {
                m_choice = DISPLAYOPTIONS.TABLE;
                updateNodeContainerInfo(m_lastNode);
            }
        }
    });
    menuentrytable.setEnabled(true);
    dropDownMenu.add(menuentrytable);
    // drop down menu entry for node variables:
    final RetargetAction dropdownmenuvars = new RetargetAction("NodeVariables", "Show Variables", IAction.AS_RADIO_BUTTON);
    dropdownmenuvars.setChecked(DISPLAYOPTIONS.VARS.equals(m_choice));
    dropdownmenuvars.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (dropdownmenuvars.isChecked()) {
                m_choice = DISPLAYOPTIONS.VARS;
                updateNodeContainerInfo(m_lastNode);
            }
        }
    });
    dropdownmenuvars.setEnabled(true);
    dropDownMenu.add(dropdownmenuvars);
    // drop down menu entry for configuration/settings:
    final RetargetAction menuentrysettings = new RetargetAction("NodeConf", "Show Configuration", IAction.AS_RADIO_BUTTON);
    menuentrysettings.setChecked(DISPLAYOPTIONS.SETTINGS.equals(m_choice));
    menuentrysettings.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (menuentrysettings.isChecked()) {
                m_choice = DISPLAYOPTIONS.SETTINGS;
                updateNodeContainerInfo(m_lastNode);
            }
        }
    });
    menuentrysettings.setEnabled(true);
    dropDownMenu.add(menuentrysettings);
    // drop down menu entry for configuration/settings:
    final RetargetAction menuentryallsettings = new RetargetAction("NodeConfAll", "Show Entire Configuration", IAction.AS_RADIO_BUTTON);
    menuentryallsettings.setChecked(DISPLAYOPTIONS.ALLSETTINGS.equals(m_choice));
    menuentryallsettings.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (menuentryallsettings.isChecked()) {
                m_choice = DISPLAYOPTIONS.ALLSETTINGS;
                updateNodeContainerInfo(m_lastNode);
            }
        }
    });
    menuentryallsettings.setEnabled(true);
    dropDownMenu.add(menuentryallsettings);
    // drop down menu entry for node timer
    final RetargetAction menuentrynodetimer = new RetargetAction("NodeTimer", "Show Node Timing Information", IAction.AS_RADIO_BUTTON);
    menuentrynodetimer.setChecked(DISPLAYOPTIONS.TIMER.equals(m_choice));
    menuentrynodetimer.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (menuentrynodetimer.isChecked()) {
                m_choice = DISPLAYOPTIONS.TIMER;
                updateNodeContainerInfo(m_lastNode);
            }
        }
    });
    menuentrynodetimer.setEnabled(true);
    dropDownMenu.add(menuentrynodetimer);
    // drop down menu entry for node graph annotations
    final RetargetAction menuentrygraphannotations = new RetargetAction("NodeGraphAnno", "Show Graph Annotations", IAction.AS_RADIO_BUTTON);
    menuentrygraphannotations.setChecked(DISPLAYOPTIONS.GRAPHANNOTATIONS.equals(m_choice));
    menuentrygraphannotations.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            if (menuentrygraphannotations.isChecked()) {
                m_choice = DISPLAYOPTIONS.GRAPHANNOTATIONS;
                updateNodeContainerInfo(m_lastNode);
            }
        }
    });
    menuentrygraphannotations.setEnabled(true);
    dropDownMenu.add(menuentrygraphannotations);
    // Content
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(parent);
    // Node Title:
    Label titlelabel = new Label(parent, SWT.NONE);
    titlelabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    titlelabel.setText("Node: ");
    m_title = new Text(parent, SWT.BORDER);
    m_title.setEditable(false);
    m_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    m_title.setText("n/a.");
    // Node State:
    Label statelabel = new Label(parent, SWT.NONE);
    statelabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    statelabel.setText("State: ");
    m_state = new Text(parent, SWT.BORDER);
    m_state.setEditable(false);
    m_state.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    m_state.setText("n/a.");
    // Panel for currently displayed information (some information
    // providers will add more elements to this):
    Composite infoPanel = new Composite(parent, SWT.NONE);
    GridData infoGrid = new GridData(SWT.FILL, SWT.TOP, true, false);
    infoGrid.horizontalSpan = 2;
    infoPanel.setLayoutData(infoGrid);
    GridLayoutFactory.swtDefaults().numColumns(3).applyTo(infoPanel);
    m_info = new Label(infoPanel, SWT.NONE);
    m_info.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    m_info.setText("n/a.                        ");
    m_portIndex = new ComboViewer(infoPanel);
    m_portIndex.add(new String[] { "port 0", "port 1", "port 2" });
    m_portIndex.getCombo().setEnabled(false);
    m_portIndex.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            ISelection sel = event.getSelection();
            try {
                int newIndex = Integer.parseInt(sel.toString().substring(5).replace(']', ' ').trim());
                updateDataTable(unwrapNC(m_lastNode), newIndex);
            } catch (NumberFormatException nfe) {
            // ignore.
            }
        }
    });
    // Table:
    m_table = new Table(parent, SWT.MULTI | SWT.BORDER);
    m_table.setLinesVisible(true);
    m_table.setHeaderVisible(true);
    GridData tableGrid = new GridData(SWT.FILL, SWT.FILL, true, true);
    tableGrid.horizontalSpan = 2;
    m_table.setLayoutData(tableGrid);
    String[] titles = { "Name", "Value" };
    for (int i = 0; i < titles.length; i++) {
        TableColumn column = new TableColumn(m_table, SWT.NONE);
        column.setText(titles[i]);
    }
    for (int i = 0; i < titles.length; i++) {
        m_table.getColumn(i).pack();
    }
    m_lastNode = null;
    getViewSite().getPage().addSelectionListener(this);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) BufferedDataTable(org.knime.core.node.BufferedDataTable) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) RetargetAction(org.eclipse.ui.actions.RetargetAction) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ISelection(org.eclipse.jface.viewers.ISelection) IMenuManager(org.eclipse.jface.action.IMenuManager) Separator(org.eclipse.jface.action.Separator)

Example 57 with IToolBarManager

use of org.eclipse.jface.action.IToolBarManager in project knime-core by knime.

the class WorkflowCoachView method createPartControl.

/**
 * {@inheritDoc}
 */
@Override
public void createPartControl(final Composite parent) {
    m_viewer = new TableViewer(parent, SWT.V_SCROLL | SWT.FULL_SELECTION) {

        @Override
        public ISelection getSelection() {
            ISelection sel = super.getSelection();
            if (!sel.isEmpty() && sel instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) sel;
                if (ss.getFirstElement() instanceof NodeRecommendation[]) {
                    // turn node recommendation selection into a node template selection
                    NodeRecommendation[] nps = (NodeRecommendation[]) ss.getFirstElement();
                    return new StructuredSelection(new Object[] { getNonNullEntry(nps).getNodeTemplate() });
                }
            }
            return sel;
        }
    };
    getSite().setSelectionProvider(m_viewer);
    m_viewer.setComparator(new TableColumnSorter(m_viewer));
    Table table = m_viewer.getTable();
    // drag & drop
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    m_viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new WorkflowCoachDragSource(this));
    // column configuration
    TableColumn column = new TableColumn(table, SWT.LEFT, 0);
    column.setText("Recommended Nodes");
    column.setToolTipText("Nodes recommended to use next (e.g. based on the currently selected node).");
    column.setWidth(200);
    table.setHeaderVisible(true);
    table.setLinesVisible(false);
    m_viewer.setContentProvider(new WorkflowCoachContentProvider());
    m_viewer.setLabelProvider(new WorkflowCoachLabelProvider());
    m_viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    getViewSite().getPage().addSelectionListener(this);
    hookDoubleClickAction();
    // actions
    IToolBarManager toolbarMGR = getViewSite().getActionBars().getToolBarManager();
    toolbarMGR.add(new ConfigureAction(m_viewer));
    updateInput("Waiting for node repository to be loaded ...");
    m_loadState.set(LoadState.LoadingNodes);
    Job nodesLoader = new KNIMEJob("Workflow Coach loader", FrameworkUtil.getBundle(getClass())) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            // wait until the repository is fully loaded
            RepositoryManager.INSTANCE.getRoot();
            if (m_loadState.get() == LoadState.Disposed) {
                return Status.CANCEL_STATUS;
            } else if (monitor.isCanceled()) {
                m_loadState.set(LoadState.Initizalized);
                return Status.CANCEL_STATUS;
            } else {
                // check for update if necessary
                updateInput("Loading recommendations...");
                checkForStatisticUpdates();
            }
            m_loadState.set(LoadState.Initizalized);
            NodeRecommendationManager.getInstance().addUpdateListener(WorkflowCoachView.this);
            updateFrequencyColumnHeadersAndToolTips();
            updateInput(StructuredSelection.EMPTY);
            return Status.OK_STATUS;
        }
    };
    nodesLoader.setSystem(true);
    nodesLoader.schedule();
    // if the 'send anonymous statistics'-property has been changed, try updating the workflow coach
    KNIMECorePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(e -> {
        if (e.getProperty().equals(HeadlessPreferencesConstants.P_SEND_ANONYMOUS_STATISTICS)) {
            if (e.getNewValue().equals(Boolean.TRUE)) {
                // enable the community recommendations
                PREFS.setValue(WorkflowCoachPreferenceInitializer.P_COMMUNITY_NODE_TRIPLE_PROVIDER, true);
                try {
                    PREFS.save();
                } catch (Exception e1) {
                    throw new RuntimeException(e1);
                }
                updateInput(StructuredSelection.EMPTY);
            }
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) NodeRecommendation(org.knime.workbench.workflowcoach.NodeRecommendationManager.NodeRecommendation) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableColumn(org.eclipse.swt.widgets.TableColumn) KNIMEJob(org.knime.core.util.KNIMEJob) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ISelection(org.eclipse.jface.viewers.ISelection) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) GridData(org.eclipse.swt.layout.GridData) KNIMEJob(org.knime.core.util.KNIMEJob) UpdateJob(org.knime.workbench.workflowcoach.prefs.UpdateJob) Job(org.eclipse.core.runtime.jobs.Job) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 58 with IToolBarManager

use of org.eclipse.jface.action.IToolBarManager in project knime-core by knime.

the class KNIMEApplicationActionBarAdvisor method fillCoolBar.

/**
 * {@inheritDoc}
 */
@Override
protected void fillCoolBar(final ICoolBarManager coolBar) {
    // create a toolbar and add it to the coolbar :)
    IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
    Stream.of(coolBar.getItems()).forEach(item -> toolbar.remove(item));
    coolBar.add(new ToolBarContributionItem(toolbar, "main"));
    // add tools to the toolbar
    toolbar.add(m_newWizardDropdownAction);
    toolbar.add(m_saveAction);
    toolbar.add(m_saveAsAction);
    toolbar.add(m_saveAllAction);
}
Also used : ToolBarContributionItem(org.eclipse.jface.action.ToolBarContributionItem) IToolBarManager(org.eclipse.jface.action.IToolBarManager) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager)

Aggregations

IToolBarManager (org.eclipse.jface.action.IToolBarManager)58 IActionBars (org.eclipse.ui.IActionBars)20 Action (org.eclipse.jface.action.Action)18 Separator (org.eclipse.jface.action.Separator)10 IMenuManager (org.eclipse.jface.action.IMenuManager)9 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)8 IAction (org.eclipse.jface.action.IAction)7 RecordAction (com.cubrid.cubridmanager.ui.monitoring.editor.internal.RecordAction)6 ToolBarManager (org.eclipse.jface.action.ToolBarManager)6 IContributionItem (org.eclipse.jface.action.IContributionItem)5 ToolBarContributionItem (org.eclipse.jface.action.ToolBarContributionItem)5 GridData (org.eclipse.swt.layout.GridData)5 MenuManager (org.eclipse.jface.action.MenuManager)4 ISelection (org.eclipse.jface.viewers.ISelection)4 DropDownAction (com.cubrid.common.ui.common.action.DropDownAction)3 ActionManager (com.cubrid.common.ui.spi.action.ActionManager)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 TableLayout (org.eclipse.jface.viewers.TableLayout)3 Composite (org.eclipse.swt.widgets.Composite)3