Example usage for org.eclipse.jface.action IToolBarManager update

List of usage examples for org.eclipse.jface.action IToolBarManager update

Introduction

In this page you can find the example usage for org.eclipse.jface.action IToolBarManager update.

Prototype

void update(boolean force);

Source Link

Document

Updates this manager's underlying widget(s) with any changes which have been made to it or its items.

Usage

From source file:net.sourceforge.sqlexplorer.plugin.views.SQLHistoryView.java

License:Open Source License

public void createPartControl(final Composite parent) {

    // MOD gdbu 2011-4-29 bug : 20960
    SQLHistory tem_history = SQLExplorerPlugin.getDefault().getSQLHistory();
    final SQLHistory history = tem_history == null ? new SQLHistory() : tem_history;
    // ~20960//from   w  w w . j  a  v a2 s.c om

    history.sort(1, SWT.DOWN);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, SQLExplorerPlugin.PLUGIN_ID + ".SQLHistoryView");//$NON-NLS-1$

    history.addListener(this);

    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.marginLeft = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 2;
    layout.marginWidth = 0;
    layout.marginHeight = 0;

    composite.setLayout(layout);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    // add search box
    _searchBox = new Text(composite, SWT.BORDER);
    _searchBox.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    _searchBox.setText(Messages.getString("SQLHistoryView.SearchText"));//$NON-NLS-1$
    _searchBox.selectAll();

    SQLHistorySearchListener searchListener = new SQLHistorySearchListener(history);
    _searchBox.addModifyListener(searchListener);
    _searchBox.addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent e) {

            Text searchbox = (Text) e.widget;
            if (searchbox.getText() != null
                    && searchbox.getText().equals(Messages.getString("SQLHistoryView.SearchText"))) {
                searchbox.setText("");
            }
        }

    });

    _tableViewer = new TableViewer(composite,
            SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.VIRTUAL);
    getSite().setSelectionProvider(_tableViewer);

    _table = _tableViewer.getTable();
    _table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    _table.setHeaderVisible(true);
    _table.setLinesVisible(true);
    _table.setItemCount(history.getEntryCount());

    _tableViewer.setLabelProvider(new SQLHistoryLabelProvider());
    _tableViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {

        }

        public Object[] getElements(Object inputElement) {

            return SQLExplorerPlugin.getDefault().getSQLHistory().toArray();
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {

        }
    });

    _tableViewer.setInput(history);

    // create listener for sorting
    Listener sortListener = new Listener() {

        public void handleEvent(Event e) {

            // determine new sort column and direction
            TableColumn sortColumn = _table.getSortColumn();
            TableColumn currentColumn = (TableColumn) e.widget;
            int dir = _table.getSortDirection();
            if (sortColumn == currentColumn) {
                dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
            } else {
                _table.setSortColumn(currentColumn);
                dir = SWT.UP;
            }

            sortColumn = _table.getSortColumn();
            TableColumn[] cols = _table.getColumns();
            for (int i = 0; i < cols.length; i++) {
                if (cols[i] == sortColumn) {
                    history.sort(i, dir);
                    break;
                }
            }

            // update data displayed in table
            _table.setSortDirection(dir);
            _tableViewer.refresh();
        }
    };

    String[] columnLabels = new String[] { Messages.getString("SQLHistoryView.Column.SQL"),
            Messages.getString("SQLHistoryView.Column.Time"),
            Messages.getString("SQLHistoryView.Column.Connection"),
            Messages.getString("SQLHistoryView.Column.Executions") };

    _tableViewer.setColumnProperties(columnLabels);

    // add all column headers to our table
    for (int i = 0; i < columnLabels.length; i++) {

        // add column header
        TableColumn column = new TableColumn(_table, SWT.LEFT);
        column.setText(columnLabels[i]);
        column.setMoveable(false);
        column.setResizable(true);
        column.addListener(SWT.Selection, sortListener);
    }

    _tableViewer.refresh();

    // add sizing weights to the different columns
    TableLayout tableLayout = new TableLayout();
    tableLayout.addColumnData(new ColumnWeightData(7, 150));
    tableLayout.addColumnData(new ColumnWeightData(2, 120));
    tableLayout.addColumnData(new ColumnWeightData(1, 50));
    tableLayout.addColumnData(new ColumnWeightData(1, 50));

    _table.setLayout(tableLayout);
    _table.layout();

    // redraw table if view is resized
    parent.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {

            super.controlResized(e);

            // reset weights in case of view resizing
            TableLayout tableLayout = new TableLayout();
            tableLayout.addColumnData(new ColumnWeightData(7, 150));
            tableLayout.addColumnData(new ColumnWeightData(2, 120));
            tableLayout.addColumnData(new ColumnWeightData(1, 50));
            tableLayout.addColumnData(new ColumnWeightData(1, 50));

            _table.setLayout(tableLayout);
        }

    });

    // create action bar
    final IToolBarManager toolBarMgr = getViewSite().getActionBars().getToolBarManager();

    final SQLHistoryActionGroup actionGroup = new SQLHistoryActionGroup(this, history, _tableViewer,
            toolBarMgr);

    _tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {

            actionGroup.refresh();
            toolBarMgr.update(true);
        }
    });

    // add context menus
    final MenuManager menuMgr = new MenuManager("#HistoryPopupMenu");
    menuMgr.setRemoveAllWhenShown(true);

    Menu historyContextMenu = menuMgr.createContextMenu(_table);
    _table.setMenu(historyContextMenu);

    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {

            toolBarMgr.markDirty();
            actionGroup.fillContextMenu(manager);
        }
    });

    // also add action as default when an entry is doubleclicked.
    final OpenInEditorAction openInEditorAction = new OpenInEditorAction();
    openInEditorAction.setTableViewer(_tableViewer);
    openInEditorAction.setView(this);

    _tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {

            openInEditorAction.run();
        }
    });

    // add remove action on delete key
    final RemoveFromHistoryAction removeFromHistoryAction = new RemoveFromHistoryAction();
    removeFromHistoryAction.setTableViewer(_tableViewer);
    _table.addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {

            // delete entry
            if (e.keyCode == SWT.DEL) {
                removeFromHistoryAction.run();
            }
        }

    });

    // Set multi-line tooltip
    final Display display = parent.getDisplay();
    _tipShell = new Shell(parent.getShell(), SWT.ON_TOP);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    gridLayout.marginWidth = 2;
    gridLayout.marginHeight = 2;

    _tipShell.setLayout(gridLayout);
    _tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

    _tipLabelText = new Label(_tipShell, SWT.WRAP | SWT.LEFT);
    _tipLabelText.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
    _tipLabelText.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));

    GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    _tipLabelText.setLayoutData(gridData);

    _table.addMouseListener(new MouseAdapter() {

        public void mouseDown(MouseEvent e) {

            if (_tipShell.isVisible()) {
                _tipShell.setVisible(false);
                _tipWidget = null;
            }
        }
    });

    _table.addMouseTrackListener(new MouseTrackAdapter() {

        public void mouseExit(MouseEvent e) {

            if (_tipShell.isVisible())
                _tipShell.setVisible(false);
            _tipWidget = null;
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.MouseTrackListener#mouseHover(org.eclipse.swt.events.MouseEvent)
         */
        public void mouseHover(MouseEvent event) {

            Point pt = new Point(event.x, event.y);
            Widget widget = event.widget;
            TableItem tableItem = null;

            if (widget instanceof Table) {
                Table table = (Table) widget;
                widget = table.getItem(pt);
            }
            if (widget instanceof TableItem) {
                tableItem = (TableItem) widget;
            }
            if (widget == null) {
                _tipShell.setVisible(false);
                _tipWidget = null;
                return;
            }
            if (widget == _tipWidget)
                return;
            _tipWidget = widget;
            _tipPosition = _table.toDisplay(pt);

            SQLHistoryElement sqlString = (SQLHistoryElement) tableItem.getData();
            String text = TextUtil.getWrappedText(sqlString.getRawSQLString());

            if (text == null || text.equals("")) {
                _tipWidget = null;
                return;
            }
            // Set off the table tooltip as we provide our own
            _table.setToolTipText("");
            _tipLabelText.setText(text);
            _tipShell.pack();
            setHoverLocation(_tipShell, _tipPosition, _tipLabelText.getBounds().height);
            _tipShell.setVisible(true);

        }
    });

    _tableViewer.setSelection(null);

    composite.layout();
    parent.layout();

}

From source file:net.sourceforge.tagsea.cloudsee.views.CloudSeeViewOld.java

License:Open Source License

private void fillToolBar() {
    IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();

    toolBarManager.add(refreshAction);//from w  ww . j  a  v  a2 s  . c o  m
    toolBarManager.add(backAction);
    toolBarManager.add(forwardAction);
    toolBarManager.update(true);

    forwardAction.setEnabled(false);
    backAction.setEnabled(false);
}

From source file:net.tourbook.chart.Chart.java

License:Open Source License

/**
 * put the actions into the internal toolbar
 * /*w w  w. j a va  2 s.  co  m*/
 * @param refreshToolbar
 */
public void fillToolbar(final boolean refreshToolbar) {

    if (_allChartActions == null) {
        return;
    }

    if (_isShowZoomActions || _isShowMouseMode) {

        // add the action to the toolbar
        final IToolBarManager tbm = getToolBarManager();

        if (_isShowZoomActions) {

            tbm.add(new Separator());

            if (_isShowMouseMode) {
                tbm.add(_allChartActions.get(ACTION_ID_MOUSE_MODE));
            }

            tbm.add(_allChartActions.get(ACTION_ID_ZOOM_IN));
            tbm.add(_allChartActions.get(ACTION_ID_ZOOM_OUT));

            if (_chartDataModel.getChartType() != ChartType.BAR) {
                tbm.add(_allChartActions.get(ACTION_ID_ZOOM_FIT_GRAPH));
            }
        }

        if (refreshToolbar) {
            tbm.update(true);
        }
    }
}

From source file:net.tourbook.conconi.ConconiView.java

License:Open Source License

private void fillToolbar() {

    /*// www  .j  ava  2  s.  c  om
     * View toolbar
     */
    final IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
    tbm.add(_actionConconiOptions);

    // update toolbar which creates the slideout
    tbm.update(true);
}

From source file:net.tourbook.statistic.StatisticView.java

License:Open Source License

/**
 * Each statistic has it's own toolbar/* ww  w.ja va2  s  . c  o  m*/
 */
private void updateUI_Toolbar() {

    // update view toolbar
    final IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
    tbm.removeAll();

    tbm.add(_actionSynchChartScale);
    tbm.add(_actionStatisticOptions);

    // add actions from the statistic
    _activeStatistic.updateToolBar();

    // update toolbar to show added items
    tbm.update(true);

    // use slideout AFTER the toolbar is created/updated/filled, this creates it
    _activeStatistic.setupStatisticSlideout(_slideoutStatisticOptions);
    _slideoutStatisticOptions.setupGrid(//
            _activeStatistic.getGridPrefPrefix(), _activeStatistic.getEnabledGridOptions());
}

From source file:net.tourbook.statistics.StatisticTourNumbers.java

License:Open Source License

public void refreshStatistic(final TourPerson person, final TourTypeFilter typeId, final int year,
        final int numberOfYears, final boolean refreshData) {

    _activePerson = person;/*w w  w.j a v  a 2 s. c o m*/
    _activeTourTypeFilter = typeId;
    _currentYear = year;

    _tourDayData = DataProviderTourDay.getInstance().getDayData(person, typeId, year, numberOfYears,
            isDataDirtyWithReset() || refreshData);

    // reset min/max values
    if (_isSynchScaleEnabled == false && refreshData) {
        resetMinMaxKeeper();
    }

    // hide actions from other statistics
    final IToolBarManager tbm = _viewSite.getActionBars().getToolBarManager();
    tbm.removeAll();
    tbm.update(true);

    createStatisticData(_tourDayData);
    updateCharts();

}

From source file:net.tourbook.training.TrainingView.java

License:Open Source License

private void fillToolbar() {

    /*//from  ww  w  . ja v  a2s.  co m
     * View toolbar
     */
    final IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
    tbm.add(_actionTrainingOptions);

    // update toolbar which creates the slideout
    tbm.update(true);

    /*
     * Header toolbar
     */
    _headerToolbarManager.add(_actionShowAllPulseValues);
    _headerToolbarManager.add(_actionSynchVerticalChartScaling);

    _headerToolbarManager.update(true);
}

From source file:net.tourbook.ui.tourChart.TourChart.java

License:Open Source License

/**
 * create the tour specific action bar, they are defined in the chart configuration
 *//*from   w  w w  . j  a v  a2  s . c  o m*/
private void fillToolbar() {

    // check if toolbar is created
    if (_isTourChartToolbarCreated) {
        return;
    }

    _isTourChartToolbarCreated = true;

    final IToolBarManager tbm = getToolBarManager();

    /*
     * add actions to the toolbar
     */
    if (_tcc.canShowTourCompareGraph) {
        tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_TOUR_COMPARE)));
    }

    tbm.add(new Separator());
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_ALTITUDE)));
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_PULSE)));
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_SPEED)));
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_PACE)));
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_POWER)));
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_TEMPERATURE)));
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_GRADIENT)));
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_ALTIMETER)));
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_CADENCE)));
    tbm.add(_allTourChartActions.get(getGraphActionId(TourManager.GRAPH_GEARS)));

    tbm.add(new Separator());
    tbm.add(_allTourChartActions.get(ACTION_ID_IS_GRAPH_OVERLAPPED));
    tbm.add(_allTourChartActions.get(ACTION_ID_HR_ZONE_DROPDOWN_MENU));
    tbm.add(_allTourChartActions.get(ACTION_ID_X_AXIS_TIME));
    tbm.add(_allTourChartActions.get(ACTION_ID_X_AXIS_DISTANCE));

    tbm.add(new Separator());
    tbm.add(_allTourChartActions.get(ACTION_ID_IS_SHOW_TOUR_PHOTOS));
    tbm.add(_actionTourMarker);
    tbm.add(_actionTourInfo);
    tbm.add(_actionTourChartSmoothing);
    tbm.add(_actionGraphMinMax);
    tbm.add(_actionTourChartOptions);

    tbm.update(true);
}

From source file:net.tourbook.ui.views.collateTours.CollatedToursView.java

License:Open Source License

private void fillActionBars() {

    /*//from   w  ww .  j a  v  a2 s .c  o m
     * fill view menu
     */
    final IMenuManager menuMgr = getViewSite().getActionBars().getMenuManager();

    menuMgr.add(_actionModifyColumns);

    /*
     * fill view toolbar
     */
    final IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();

    tbm.add(_contribItem_CollatedTours);

    tbm.add(new Separator());
    tbm.add(_actionExpandSelection);
    tbm.add(_actionCollapseAll);

    tbm.add(_actionRefreshView);

    // update that actions are fully created otherwise action enable will fail
    tbm.update(true);
}

From source file:net.tourbook.ui.views.tagging.TaggingView.java

License:Open Source License

private void fillToolBar() {
    /*// w  ww.  j av a2  s . c om
     * action in the view toolbar
     */
    final IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();

    // recreate the toolbar
    tbm.removeAll();

    tbm.add(_actionExpandSelection);
    tbm.add(_actionCollapseAll);

    tbm.add(_actionSetLayoutFlat);
    tbm.add(_actionSetLayoutHierarchical);

    tbm.add(_actionRefreshView);

    tbm.update(true);
}