List of usage examples for org.eclipse.jface.action IContributionManager insertAfter
void insertAfter(String id, IContributionItem item);
From source file:com.nokia.carbide.cpp.pi.address.GenericAddrTable.java
License:Open Source License
public void setIsDrilldown(boolean isDrilldown) { this.isDrilldown = isDrilldown; copyDrilldownAction.setEnabled(isDrilldown); saveDrilldownAction.setEnabled(isDrilldown); // may need to clean up stale Edit & File menu entry for PICopyDrilldown and PISaveDrilldown if (!isDrilldown) { IMenuManager editMenuManager = PIPageEditor.getActionBars().getMenuManager() .findMenuUsingPath(IIDEActionConstants.M_EDIT); if (editMenuManager instanceof SubMenuManager) { IContributionManager editManager = ((SubMenuManager) editMenuManager).getParent(); ActionContributionItem item; editMenuManager.remove("PICopyDrilldown"); //$NON-NLS-1$ item = new ActionContributionItem(copyDrilldownAction); item.setVisible(true);// www .j a v a 2 s . c o m editManager.prependToGroup(IIDEActionConstants.CUT_EXT, item); editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ copyTableAction.setEnabled(table.getItemCount() > 0); item = new ActionContributionItem(copyTableAction); item.setVisible(true); editManager.prependToGroup(IIDEActionConstants.CUT_EXT, item); } IMenuManager fileMenuManager = PIPageEditor.getActionBars().getMenuManager() .findMenuUsingPath(IIDEActionConstants.M_FILE); if (fileMenuManager instanceof SubMenuManager) { IContributionManager fileManager = ((SubMenuManager) fileMenuManager).getParent(); ActionContributionItem item; fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ saveTableAction.setEnabled(table.getItemCount() > 0); item = new ActionContributionItem(saveTableAction); item.setVisible(true); fileManager.insertAfter("saveAll", item); //$NON-NLS-1$ fileMenuManager.remove("PISaveDrilldown"); //$NON-NLS-1$ item = new ActionContributionItem(saveDrilldownAction); item.setVisible(true); fileManager.insertAfter("PISaveTable", item); //$NON-NLS-1$ fileManager.update(true); } } }
From source file:com.nokia.carbide.cpp.pi.call.CallVisualiser.java
License:Open Source License
private void createCurrentFunctionTableViewer(SashForm sashForm) { /*//from w w w .jav a 2s . c o m * Functions (one checkbox selectable at a time) * * selected checkbox * percent load * function name * function start address * binary containing function * sample count */ Label label; Composite holder; Table table; TableColumn column; // middle functionTable and title holder = new Composite(sashForm, SWT.NONE); GridLayout gridLayout = new GridLayout(1, true); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; holder.setLayout(gridLayout); label = new Label(holder, SWT.CENTER | SWT.BORDER); label.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_YELLOW)); label.setFont(PIPageEditor.helvetica_10); label.setText(Messages.getString("CallVisualiser.selectFunction")); //$NON-NLS-1$ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.currentFunctionTableViewer = new TableViewer(holder, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); this.currentFunctionTable = currentFunctionTableViewer.getTable(); // add the label provider and content provider this.currentFunctionTableViewer.setLabelProvider(new SharedLabelProvider(this.currentFunctionTable)); this.currentFunctionTableViewer.setContentProvider(new ArrayContentProvider()); this.currentFunctionTableViewer.setSorter(new SharedSorter()); table = this.currentFunctionTable; table.setRedraw(false); // give the table a heading for use in copying and exported table.setData(Messages.getString("CallVisualiser.selectedFunction")); //$NON-NLS-1$ // create the other table entries when a row in this table is selected table.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent event) { if (!(event.item instanceof TableItem)) return; // set the other tables based on this selection if (!(event.item.getData() instanceof GfcFunctionItem)) return; updateCallerCalleeTables((GfcFunctionItem) event.item.getData()); } public void widgetDefaultSelected(SelectionEvent e) { widgetSelected(e); } }); // data associated with the TableViewer will note which columns contain hex values // Keep this in the order in which columns have been created boolean[] isHex = { false, false, false, true, false, false, false }; this.currentFunctionTable.setData("isHex", isHex); //$NON-NLS-1$ // is called percent column column = new TableColumn(table, SWT.RIGHT); column.setText(COLUMN_HEAD_IS_CALLED); column.setWidth(COLUMN_WIDTH_IS_CALLED); column.setData(Integer.valueOf(COLUMN_ID_IS_CALLED)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CheckboxColumnSelectionHandler()); // is caller percent column column = new TableColumn(table, SWT.RIGHT); column.setText(COLUMN_HEAD_IS_CALLER); column.setWidth(COLUMN_WIDTH_IS_CALLER); column.setData(Integer.valueOf(COLUMN_ID_IS_CALLER)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CheckboxColumnSelectionHandler()); // function name column column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_HEAD_FUNCTION); column.setWidth(COLUMN_WIDTH_FUNCTION_NAME); column.setData(Integer.valueOf(COLUMN_ID_FUNCTION)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CheckboxColumnSelectionHandler()); // function start address column column = new TableColumn(table, SWT.CENTER); column.setText(COLUMN_HEAD_START_ADDR); column.setWidth(COLUMN_WIDTH_START_ADDRESS); column.setData(Integer.valueOf(COLUMN_ID_START_ADDR)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CheckboxColumnSelectionHandler()); // binary containing function column column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_HEAD_IN_BINARY); column.setWidth(COLUMN_WIDTH_IN_BINARY); column.setData(Integer.valueOf(COLUMN_ID_IN_BINARY)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CheckboxColumnSelectionHandler()); // path to binary containing function column column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_HEAD_IN_BINARY_PATH); column.setWidth(COLUMN_WIDTH_IN_BINARY_PATH); column.setData(Integer.valueOf(COLUMN_ID_IN_BINARY_PATH)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CheckboxColumnSelectionHandler()); // sample count column column = new TableColumn(table, SWT.CENTER); column.setText(COLUMN_HEAD_IS_CALLED_COUNT); column.setWidth(COLUMN_WIDTH_IS_CALLED_COUNT); column.setData(Integer.valueOf(COLUMN_ID_IS_CALLED_COUNT)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CheckboxColumnSelectionHandler()); // set the default sort column to COLUMN_ID_IS_CALLED_COUNT currentFunctionDefaultColumn = column; // sample count column column = new TableColumn(table, SWT.CENTER); column.setText(COLUMN_HEAD_IS_CALLER_COUNT); column.setWidth(COLUMN_WIDTH_IS_CALLER_COUNT); column.setData(Integer.valueOf(COLUMN_ID_IS_CALLER_COUNT)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CheckboxColumnSelectionHandler()); table.setLayoutData(new GridData(GridData.FILL_BOTH)); table.setHeaderVisible(true); table.setLinesVisible(true); table.setRedraw(true); // listen for mouse clicks: to select a row, pop up a menu, etc. table.addMouseListener(new CurrentFunctionMouseListener()); table.addFocusListener(new FocusListener() { IAction oldCopyAction = null; public void focusGained(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); // modify what is executed when Copy is called from the Edit menu oldCopyAction = bars.getGlobalActionHandler(ActionFactory.COPY.getId()); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction); copyAction.setEnabled(currentFunctionTable.getSelectionCount() > 0); bars.updateActionBars(); // add to the Edit menu IMenuManager editMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_EDIT); if (editMenuManager instanceof SubMenuManager) { IContributionManager editManager = ((SubMenuManager) editMenuManager).getParent(); ActionContributionItem item; editMenuManager.remove("PICopyFunction"); //$NON-NLS-1$ functionCopyFunctionAction.setEnabled(currentFunctionTable.getSelectionCount() > 0); item = new ActionContributionItem(functionCopyFunctionAction); item.setVisible(true); editManager.prependToGroup(IIDEActionConstants.CUT_EXT, item); editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ copyTableAction.setEnabled(currentFunctionTable.getItemCount() > 0); item = new ActionContributionItem(copyTableAction); item.setVisible(true); editManager.prependToGroup(IIDEActionConstants.CUT_EXT, item); } // add to the File menu IMenuManager fileMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_FILE); if (fileMenuManager instanceof SubMenuManager) { IContributionManager fileManager = ((SubMenuManager) fileMenuManager).getParent(); ActionContributionItem item; fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ saveTableAction.setEnabled(currentFunctionTable.getItemCount() > 0); item = new ActionContributionItem(saveTableAction); item.setVisible(true); fileManager.insertAfter("saveAll", item); //$NON-NLS-1$ fileMenuManager.remove("PISaveFunction"); //$NON-NLS-1$ functionSaveFunctionAction.setEnabled(currentFunctionTable.getSelectionCount() > 0); item = new ActionContributionItem(functionSaveFunctionAction); item.setVisible(true); fileManager.insertAfter("PISaveTable", item); //$NON-NLS-1$ } } public void focusLost(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), oldCopyAction); bars.updateActionBars(); SubMenuManager editMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_EDIT); editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ editMenuManager.remove("PICopyFunction"); //$NON-NLS-1$ SubMenuManager fileMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_FILE); fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ fileMenuManager.remove("PISaveFunction"); //$NON-NLS-1$ } }); }
From source file:com.nokia.carbide.cpp.pi.call.CallVisualiser.java
License:Open Source License
private void createCallerTableViewer(SashForm sashForm) { /*//from ww w . j ava 2 s . c o m * Functions called by * * percent of calls * total percent * caller percent * function name * function start address * binary containing function * sample count */ Label label; Composite holder; Table table; TableColumn column; // top functionTable and title holder = new Composite(sashForm, SWT.NONE); // holder.setLayout(new FillLayout(SWT.VERTICAL)); GridLayout gridLayout = new GridLayout(1, true); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; holder.setLayout(gridLayout); label = new Label(holder, SWT.CENTER | SWT.BORDER); label.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_CYAN)); label.setFont(PIPageEditor.helvetica_10); label.setText(Messages.getString("CallVisualiser.callingSelectedFunction")); //$NON-NLS-1$ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.callerTableViewer = new TableViewer(holder, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); this.callerTable = callerTableViewer.getTable(); // add the label provider and content provider this.callerTableViewer.setLabelProvider(new SharedLabelProvider(this.callerTable)); this.callerTableViewer.setContentProvider(new ArrayContentProvider()); this.callerTableViewer.setSorter(new SharedSorter()); table = this.callerTable; table.setRedraw(false); // give the table a heading for possible use in copying and exported table.setData(Messages.getString("CallVisualiser.callerFunctions")); //$NON-NLS-1$ // data associated with the TableViewer will note which columns contain hex values // Keep this in the order in which columns have been created boolean[] isHex = { false, false, false, true, false, false, false }; this.callerTable.setData("isHex", isHex); //$NON-NLS-1$ // percent of calls column column = new TableColumn(table, SWT.RIGHT); column.setText(COLUMN_HEAD_CALLER_PERCENT); column.setWidth(COLUMN_WIDTH_CALLER_PERCENT); column.setData(Integer.valueOf(COLUMN_ID_CALLER_PERCENT)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledByColumnSelectionHandler()); // sample count column column = new TableColumn(table, SWT.CENTER); column.setText(COLUMN_HEAD_IS_CALLER_COUNT2); column.setWidth(COLUMN_WIDTH_IS_CALLER_COUNT2); column.setData(Integer.valueOf(COLUMN_ID_IS_CALLER_COUNT)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledByColumnSelectionHandler()); // function name column column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_HEAD_FUNCTION); column.setWidth(COLUMN_WIDTH_FUNCTION_NAME); column.setData(Integer.valueOf(COLUMN_ID_FUNCTION)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledByColumnSelectionHandler()); // function start address column column = new TableColumn(table, SWT.CENTER); column.setText(COLUMN_HEAD_START_ADDR); column.setWidth(COLUMN_WIDTH_START_ADDRESS); column.setData(Integer.valueOf(COLUMN_ID_START_ADDR)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledByColumnSelectionHandler()); // binary containing function column column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_HEAD_IN_BINARY); column.setWidth(COLUMN_WIDTH_IN_BINARY); column.setData(Integer.valueOf(COLUMN_ID_IN_BINARY)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledByColumnSelectionHandler()); // path to binary containing function column column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_HEAD_IN_BINARY_PATH); column.setWidth(COLUMN_WIDTH_IN_BINARY_PATH); column.setData(Integer.valueOf(COLUMN_ID_IN_BINARY_PATH)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledByColumnSelectionHandler()); // is caller percent column column = new TableColumn(table, SWT.RIGHT); column.setText(COLUMN_HEAD_IS_CALLER); column.setWidth(COLUMN_WIDTH_IS_CALLER); column.setData(Integer.valueOf(COLUMN_ID_IS_CALLER)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledByColumnSelectionHandler()); table.setLayoutData(new GridData(GridData.FILL_BOTH)); // table.setLayout(new FillLayout()); table.setHeaderVisible(true); table.setLinesVisible(true); table.setRedraw(true); // when a row is selected, allow the user to double-click or right click and make that function the selected function table.addSelectionListener(new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent se) { TableItem item = (TableItem) se.item; Table table = (Table) se.widget; CallerCalleeItem callerCalleeItem = (CallerCalleeItem) item.getData(); // deselect this line table.deselectAll(); // choose this row's function chooseNewFunction(callerCalleeItem); } }); table.addMouseListener(new CallerMouseListener()); table.addFocusListener(new FocusListener() { IAction oldCopyAction = null; public void focusGained(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); // modify what is executed when Copy is called from the Edit menu oldCopyAction = bars.getGlobalActionHandler(ActionFactory.COPY.getId()); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction); copyAction.setEnabled(callerTable.getSelectionCount() > 0); bars.updateActionBars(); // add to the Edit menu IMenuManager editMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_EDIT); if (editMenuManager instanceof SubMenuManager) { IContributionManager editManager = ((SubMenuManager) editMenuManager).getParent(); ActionContributionItem item; editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ copyTableAction.setEnabled(callerTable.getItemCount() > 0); item = new ActionContributionItem(copyTableAction); item.setVisible(true); editManager.prependToGroup(IIDEActionConstants.CUT_EXT, item); } // add to the File menu IMenuManager fileMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_FILE); if (fileMenuManager instanceof SubMenuManager) { IContributionManager fileManager = ((SubMenuManager) fileMenuManager).getParent(); ActionContributionItem item; fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ saveTableAction.setEnabled(callerTable.getItemCount() > 0); item = new ActionContributionItem(saveTableAction); item.setVisible(true); fileManager.insertAfter("saveAll", item); //$NON-NLS-1$ } } public void focusLost(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), oldCopyAction); bars.updateActionBars(); SubMenuManager editMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_EDIT); editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ SubMenuManager fileMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_FILE); fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ } }); }
From source file:com.nokia.carbide.cpp.pi.call.CallVisualiser.java
License:Open Source License
private void createCalleeTableViewer(SashForm sashForm) { /*// w ww. j a v a 2 s . co m * Functions called * * percent of calls * total percent * caller percent * function name * function start address * binary containing function * sample count */ Label label; Composite holder; Table table; TableColumn column; // bottom functionTable and title holder = new Composite(sashForm, SWT.NONE); // holder.setLayout(new FillLayout(SWT.VERTICAL)); GridLayout gridLayout = new GridLayout(1, true); gridLayout.marginWidth = 0; gridLayout.marginHeight = 0; holder.setLayout(gridLayout); label = new Label(holder, SWT.CENTER | SWT.BORDER); label.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_CYAN)); label.setFont(PIPageEditor.helvetica_10); label.setText(Messages.getString("CallVisualiser.calledBySelectedFunction")); //$NON-NLS-1$ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.calleeTableViewer = new TableViewer(holder, SWT.BORDER | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); this.calleeTable = calleeTableViewer.getTable(); // add the label provider and content provider this.calleeTableViewer.setLabelProvider(new SharedLabelProvider(this.calleeTable)); this.calleeTableViewer.setContentProvider(new ArrayContentProvider()); this.calleeTableViewer.setSorter(new SharedSorter()); table = this.calleeTable; table.setRedraw(false); // give the table a heading for possible use in copying and exported table.setData(Messages.getString("CallVisualiser.calleeFunctions")); //$NON-NLS-1$ // data associated with the TableViewer will note which columns contain hex values // Keep this in the order in which columns have been created boolean[] isHex = { false, false, false, true, false, false, false }; this.calleeTable.setData("isHex", isHex); //$NON-NLS-1$ // percent of calls column column = new TableColumn(table, SWT.RIGHT); column.setText(COLUMN_HEAD_CALLEE_PERCENT); column.setWidth(COLUMN_WIDTH_CALLEE_PERCENT); column.setData(Integer.valueOf(COLUMN_ID_CALLEE_PERCENT)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledColumnSelectionHandler()); // sample count column column = new TableColumn(table, SWT.CENTER); column.setText(COLUMN_HEAD_IS_CALLED_COUNT2); column.setWidth(COLUMN_WIDTH_IS_CALLED_COUNT2); column.setData(Integer.valueOf(COLUMN_ID_IS_CALLED_COUNT)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledColumnSelectionHandler()); // function name column column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_HEAD_FUNCTION); column.setWidth(COLUMN_WIDTH_FUNCTION_NAME); column.setData(Integer.valueOf(COLUMN_ID_FUNCTION)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledColumnSelectionHandler()); // function start address column column = new TableColumn(table, SWT.CENTER); column.setText(COLUMN_HEAD_START_ADDR); column.setWidth(COLUMN_WIDTH_START_ADDRESS); // column.setData(Integer.valueOf(COLUMN_ID_START_ADDR3)); column.setData(Integer.valueOf(COLUMN_ID_START_ADDR)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledColumnSelectionHandler()); // binary containing function column column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_HEAD_IN_BINARY); column.setWidth(COLUMN_WIDTH_IN_BINARY); // column.setData(Integer.valueOf(COLUMN_ID_IN_BINARY3)); column.setData(Integer.valueOf(COLUMN_ID_IN_BINARY)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledColumnSelectionHandler()); // path to binary containing function column column = new TableColumn(table, SWT.LEFT); column.setText(COLUMN_HEAD_IN_BINARY_PATH); column.setWidth(COLUMN_WIDTH_IN_BINARY_PATH); // column.setData(Integer.valueOf(COLUMN_ID_IN_BINARY_PATH3)); column.setData(Integer.valueOf(COLUMN_ID_IN_BINARY_PATH)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledColumnSelectionHandler()); // percent of calls column column = new TableColumn(table, SWT.RIGHT); column.setText(COLUMN_HEAD_IS_CALLED); column.setWidth(COLUMN_WIDTH_IS_CALLED); // column.setData(Integer.valueOf(COLUMN_ID_IS_CALLED3)); column.setData(Integer.valueOf(COLUMN_ID_IS_CALLED)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new CalledColumnSelectionHandler()); table.setLayoutData(new GridData(GridData.FILL_BOTH)); // table.setLayout(new FillLayout()); table.setHeaderVisible(true); table.setLinesVisible(true); table.setRedraw(true); // when a row is selected, allow the user to double-click or right click and make that function the selected function table.addSelectionListener(new SelectionAdapter() { public void widgetDefaultSelected(SelectionEvent se) { TableItem item = (TableItem) se.item; Table table = (Table) se.widget; CallerCalleeItem callerCallee = (CallerCalleeItem) item.getData(); // deselect this row table.deselectAll(); // choose this row's function chooseNewFunction(callerCallee); } }); table.addMouseListener(new CalleeMouseListener()); table.addFocusListener(new FocusListener() { IAction oldCopyAction = null; public void focusGained(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); // modify what is executed when Copy is called from the Edit menu oldCopyAction = bars.getGlobalActionHandler(ActionFactory.COPY.getId()); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction); copyAction.setEnabled(calleeTable.getSelectionCount() > 0); bars.updateActionBars(); // add to the Edit menu IMenuManager editMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_EDIT); if (editMenuManager instanceof SubMenuManager) { IContributionManager editManager = ((SubMenuManager) editMenuManager).getParent(); ActionContributionItem item; editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ copyTableAction.setEnabled(calleeTable.getItemCount() > 0); item = new ActionContributionItem(copyTableAction); item.setVisible(true); editManager.prependToGroup(IIDEActionConstants.CUT_EXT, item); } // add to the File menu IMenuManager fileMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_FILE); if (fileMenuManager instanceof SubMenuManager) { IContributionManager fileManager = ((SubMenuManager) fileMenuManager).getParent(); ActionContributionItem item; fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ saveTableAction.setEnabled(calleeTable.getItemCount() > 0); item = new ActionContributionItem(saveTableAction); item.setVisible(true); fileManager.insertAfter("saveAll", item); //$NON-NLS-1$ } } public void focusLost(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), oldCopyAction); bars.updateActionBars(); SubMenuManager editMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_EDIT); editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ SubMenuManager fileMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_FILE); fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ } }); }
From source file:com.nokia.carbide.cpp.pi.graphicsmemory.GraphicsMemoryProcessTable.java
License:Open Source License
public GraphicsMemoryProcessTable(GraphicsMemoryTraceGraph myGraph, Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gl = new GridLayout(); gl.marginHeight = 0;//from w w w . j a v a 2 s . com gl.marginWidth = 0; gl.marginLeft = 0; gl.marginRight = 0; composite.setLayout(gl); this.myGraph = myGraph; this.parent = composite; Label label = new Label(composite, SWT.CENTER); label.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_WHITE)); label.setFont(PIPageEditor.helvetica_8); label.setText(Messages.getString("GraphicsMemoryProcessTable.title")); //$NON-NLS-1$ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.tableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); this.table = this.tableViewer.getTable(); this.table.setLayoutData(new GridData(GridData.FILL_BOTH)); // add the check state handler, label provider and content provider this.tableViewer.addCheckStateListener(new CheckHandler()); this.tableViewer.setLabelProvider(new SharedLabelProvider(this.table)); this.tableViewer.setContentProvider(new MemoryTableContentProvider()); this.tableViewer.setSorter(new SharedSorter()); // give the table a heading for possible use in copying and exported this.table.setData(Messages.getString("GraphicsMemoryProcessTable.memory")); //$NON-NLS-1$ // create the columns TableColumn column; // data associated with the TableViewer will note which columns contain // hex values // Keep this in the order in which columns have been created boolean[] isHex = { false, false, false, false }; this.table.setData("isHex", isHex); //$NON-NLS-1$ // select/deselect column column = new TableColumn(this.table, SWT.CENTER); column.setText(COLUMN_HEAD_GRAPHICS_MEMORY_NAME); column.setWidth(COLUMN_WIDTH_GRAPHICS_MEMORY_NAME); column.setData(Integer.valueOf(COLUMN_ID_GRAPHICS_MEMORY_NAME)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); column = new TableColumn(tableViewer.getTable(), SWT.RIGHT); column.setText(COLUMN_HEAD_GRAPHICS_MEMORY_PRIVATE); column.setWidth(COLUMN_WIDTH_GRAPHICS_MEMORY_PRIVATE); column.setData(Integer.valueOf(COLUMN_ID_GRAPHICS_MEMORY_PRIVATE)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); column = new TableColumn(tableViewer.getTable(), SWT.RIGHT); column.setText(COLUMN_HEAD_GRAPHICS_MEMORY_SHARED); column.setWidth(COLUMN_WIDTH_GRAPHICS_MEMORY_SHARED); column.setData(Integer.valueOf(COLUMN_ID_GRAPHICS_MEMORY_SHARED)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); column = new TableColumn(tableViewer.getTable(), SWT.RIGHT); column.setText(COLUMN_HEAD_MEMORY_TOTAL); column.setWidth(COLUMN_WIDTH_MEMORY_TOTAL); column.setData(Integer.valueOf(COLUMN_ID_GRAPHICS_MEMORY_TOTAL)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); // initially, all rows are checked this.tableViewer.setAllChecked(true); this.table.addMouseListener(new TableMouseListener()); this.table.setHeaderVisible(true); this.table.setLinesVisible(true); this.table.setRedraw(true); updateItemData(true); ((SharedSorter) tableViewer.getSorter()).doSort(COLUMN_ID_GRAPHICS_MEMORY_NAME); // initially, all rows are checked this.tableViewer.setAllChecked(true); createDefaultActions(); // listen for key sequences such as Ctrl-A and Ctrl-C table.addKeyListener(new TableKeyListener()); table.addFocusListener(new FocusListener() { IAction oldSelectAllAction = null; IAction oldCopyAction = null; public void focusGained(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); oldSelectAllAction = PIPageEditor.getActionBars() .getGlobalActionHandler(ActionFactory.SELECT_ALL.getId()); oldCopyAction = PIPageEditor.getActionBars().getGlobalActionHandler(ActionFactory.COPY.getId()); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction); bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), selectAllAction); copyAction.setEnabled(table.getSelectionCount() > 0); selectAllAction.setEnabled(table.getItemCount() > 0); bars.updateActionBars(); // add to the Edit menu IMenuManager editMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_EDIT); if (editMenuManager instanceof SubMenuManager) { IContributionManager editManager = ((SubMenuManager) editMenuManager).getParent(); ActionContributionItem item; editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ copyTableAction.setEnabled(table.getItemCount() > 0); item = new ActionContributionItem(copyTableAction); item.setVisible(true); editManager.prependToGroup(IIDEActionConstants.CUT_EXT, item); } // add to the File menu IMenuManager fileMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_FILE); if (fileMenuManager instanceof SubMenuManager) { IContributionManager fileManager = ((SubMenuManager) fileMenuManager).getParent(); ActionContributionItem item; fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ saveTableAction.setEnabled(table.getItemCount() > 0); item = new ActionContributionItem(saveTableAction); item.setVisible(true); fileManager.insertAfter("saveAll", item); //$NON-NLS-1$ } } public void focusLost(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), oldCopyAction); bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), oldSelectAllAction); bars.updateActionBars(); SubMenuManager editMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_EDIT); editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ editMenuManager.update(); SubMenuManager fileMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_FILE); fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ fileMenuManager.update(); } }); tableViewer.refresh(); table.redraw(); }
From source file:com.nokia.carbide.cpp.pi.memory.MemLibraryEventTable.java
License:Open Source License
public MemLibraryEventTable(MemTraceGraph myGraph, Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gl = new GridLayout(); gl.marginHeight = 0;// www. j av a 2s. c o m gl.marginWidth = 0; gl.marginLeft = 0; gl.marginRight = 0; composite.setLayout(gl); this.myGraph = myGraph; this.parent = composite; Label label = new Label(composite, SWT.CENTER); label.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_WHITE)); label.setFont(PIPageEditor.helvetica_8); label.setText(Messages.getString("MemLibraryEventTable.title")); //$NON-NLS-1$ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.tableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); this.table = this.tableViewer.getTable(); this.table.setLayoutData(new GridData(GridData.FILL_BOTH)); // add the check state handler, label provider and content provider this.tableViewer.addCheckStateListener(new CheckHandler()); this.tableViewer.setLabelProvider(new SharedLabelProvider(this.table)); this.tableViewer.setContentProvider(new MemoryTableContentProvider()); this.tableViewer.setSorter(new SharedSorter()); // give the table a heading for possible use in copying and exported this.table.setData(Messages.getString("MemLibraryEventTable.library")); //$NON-NLS-1$ // create the columns TableColumn column; // data associated with the TableViewer will note which columns contain hex values // Keep this in the order in which columns have been created boolean[] isHex = { false, false, false, false }; this.table.setData("isHex", isHex); //$NON-NLS-1$ // select/deselect column column = new TableColumn(this.table, SWT.CENTER); column.setText(COLUMN_HEAD_SHOW); column.setWidth(COLUMN_WIDTH_SHOW); column.setData(Integer.valueOf(COLUMN_ID_SHOW)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); column = new TableColumn(this.table, SWT.LEFT); column.setText(COLUMN_HEAD_LIBRARY_NAME); column.setWidth(COLUMN_WIDTH_LIBRARY_NAME); column.setData(Integer.valueOf(COLUMN_ID_LIB_NAME)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); column = new TableColumn(tableViewer.getTable(), SWT.RIGHT); column.setText(COLUMN_HEAD_LIBRARY_LOAD_SIZE); column.setWidth(COLUMN_WIDTH_LIBRARY_LOAD_SIZE); column.setData(Integer.valueOf(COLUMN_ID_LIB_LOAD_SIZE)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); column = new TableColumn(tableViewer.getTable(), SWT.RIGHT); column.setText(COLUMN_HEAD_LIBRARY_SELECTION_LOAD_COUNT); column.setWidth(COLUMN_WIDTH_LIBRARY_SELECTION_COUNT); column.setData(Integer.valueOf(COLUMN_ID_LIB_SELECTION_COUNT)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); // initially, all rows are checked this.tableViewer.setAllChecked(true); this.table.addMouseListener(new TableMouseListener()); // set background color for the first column this.table.addListener(SWT.EraseItem, new Listener() { public void handleEvent(Event event) { TableItem item = (TableItem) event.item; ProfiledLibraryEvent ple = (ProfiledLibraryEvent) item.getData(); GC gc = event.gc; gc.setForeground(ple.getColor()); gc.setBackground(ple.getColor()); gc.fillRectangle(item.getBounds(COLOR_COLUMN_INDEX)); } }); this.table.setHeaderVisible(true); this.table.setLinesVisible(true); this.table.setRedraw(true); updateItemData(true); ((SharedSorter) tableViewer.getSorter()).doSort(COLUMN_ID_LIB_NAME); // initially, all rows are checked this.tableViewer.setAllChecked(true); createDefaultActions(); // listen for key sequences such as Ctrl-A and Ctrl-C table.addKeyListener(new TableKeyListener()); table.addFocusListener(new FocusListener() { IAction oldSelectAllAction = null; IAction oldCopyAction = null; public void focusGained(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); oldSelectAllAction = PIPageEditor.getActionBars() .getGlobalActionHandler(ActionFactory.SELECT_ALL.getId()); oldCopyAction = PIPageEditor.getActionBars().getGlobalActionHandler(ActionFactory.COPY.getId()); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction); bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), selectAllAction); copyAction.setEnabled(table.getSelectionCount() > 0); selectAllAction.setEnabled(table.getItemCount() > 0); bars.updateActionBars(); // add to the Edit menu IMenuManager editMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_EDIT); if (editMenuManager instanceof SubMenuManager) { IContributionManager editManager = ((SubMenuManager) editMenuManager).getParent(); ActionContributionItem item; editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ copyTableAction.setEnabled(table.getItemCount() > 0); item = new ActionContributionItem(copyTableAction); item.setVisible(true); editManager.prependToGroup(IIDEActionConstants.CUT_EXT, item); } // add to the File menu IMenuManager fileMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_FILE); if (fileMenuManager instanceof SubMenuManager) { IContributionManager fileManager = ((SubMenuManager) fileMenuManager).getParent(); ActionContributionItem item; fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ saveTableAction.setEnabled(table.getItemCount() > 0); item = new ActionContributionItem(saveTableAction); item.setVisible(true); fileManager.insertAfter("saveAll", item); //$NON-NLS-1$ } } public void focusLost(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), oldCopyAction); bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), oldSelectAllAction); bars.updateActionBars(); SubMenuManager editMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_EDIT); editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ editMenuManager.update(); SubMenuManager fileMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_FILE); fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ fileMenuManager.update(); } }); tableViewer.refresh(); table.redraw(); }
From source file:com.nokia.carbide.cpp.pi.memory.MemThreadTable.java
License:Open Source License
public MemThreadTable(MemTraceGraph myGraph, Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout gl = new GridLayout(); gl.marginHeight = 0;/*from www. j a va2 s .c o m*/ gl.marginWidth = 0; gl.marginLeft = 0; gl.marginRight = 0; composite.setLayout(gl); this.myGraph = myGraph; this.parent = composite; Label label = new Label(composite, SWT.CENTER); label.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_WHITE)); label.setFont(PIPageEditor.helvetica_8); label.setText(Messages.getString("MemThreadTable.title")); //$NON-NLS-1$ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); this.tableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); this.table = this.tableViewer.getTable(); this.table.setLayoutData(new GridData(GridData.FILL_BOTH)); // add the check state handler, label provider and content provider this.tableViewer.addCheckStateListener(new CheckHandler()); this.tableViewer.setLabelProvider(new SharedLabelProvider(this.table)); this.tableViewer.setContentProvider(new MemoryTableContentProvider()); this.tableViewer.setSorter(new SharedSorter()); // give the table a heading for possible use in copying and exported this.table.setData(Messages.getString("MemThreadTable.memory")); //$NON-NLS-1$ // create the columns TableColumn column; // data associated with the TableViewer will note which columns contain hex values // Keep this in the order in which columns have been created boolean[] isHex = { false, false, false, false }; this.table.setData("isHex", isHex); //$NON-NLS-1$ // select/deselect column column = new TableColumn(this.table, SWT.CENTER); column.setText(COLUMN_HEAD_MEMORY_NAME); column.setWidth(COLUMN_WIDTH_MEMORY_NAME + 15); // extra space for the checkbox column.setData(Integer.valueOf(COLUMN_ID_MEMORY_NAME)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); column = new TableColumn(tableViewer.getTable(), SWT.RIGHT); column.setText(COLUMN_HEAD_MEMORY_CHUNKS); column.setWidth(COLUMN_WIDTH_MEMORY_CHUNKS); column.setData(Integer.valueOf(COLUMN_ID_MEMORY_CHUNKS)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); column = new TableColumn(tableViewer.getTable(), SWT.RIGHT); column.setText(COLUMN_HEAD_MEMORY_STACK); column.setWidth(COLUMN_WIDTH_MEMORY_STACK); column.setData(Integer.valueOf(COLUMN_ID_MEMORY_STACK)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); column = new TableColumn(tableViewer.getTable(), SWT.RIGHT); column.setText(COLUMN_HEAD_MEMORY_TOTAL); column.setWidth(COLUMN_WIDTH_MEMORY_TOTAL); column.setData(Integer.valueOf(COLUMN_ID_MEMORY_TOTAL)); column.setMoveable(true); column.setResizable(true); column.addSelectionListener(new ColumnSelectionHandler()); // initially, all rows are checked this.tableViewer.setAllChecked(true); this.table.addMouseListener(new TableMouseListener()); this.table.setHeaderVisible(true); this.table.setLinesVisible(true); this.table.setRedraw(true); updateItemData(true); ((SharedSorter) tableViewer.getSorter()).doSort(COLUMN_ID_MEMORY_NAME); // initially, all rows are checked this.tableViewer.setAllChecked(true); createDefaultActions(); // listen for key sequences such as Ctrl-A and Ctrl-C table.addKeyListener(new TableKeyListener()); table.addFocusListener(new FocusListener() { IAction oldSelectAllAction = null; IAction oldCopyAction = null; public void focusGained(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); oldSelectAllAction = PIPageEditor.getActionBars() .getGlobalActionHandler(ActionFactory.SELECT_ALL.getId()); oldCopyAction = PIPageEditor.getActionBars().getGlobalActionHandler(ActionFactory.COPY.getId()); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), copyAction); bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), selectAllAction); copyAction.setEnabled(table.getSelectionCount() > 0); selectAllAction.setEnabled(table.getItemCount() > 0); bars.updateActionBars(); // add to the Edit menu IMenuManager editMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_EDIT); if (editMenuManager instanceof SubMenuManager) { IContributionManager editManager = ((SubMenuManager) editMenuManager).getParent(); ActionContributionItem item; editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ copyTableAction.setEnabled(table.getItemCount() > 0); item = new ActionContributionItem(copyTableAction); item.setVisible(true); editManager.prependToGroup(IIDEActionConstants.CUT_EXT, item); } // add to the File menu IMenuManager fileMenuManager = bars.getMenuManager().findMenuUsingPath(IIDEActionConstants.M_FILE); if (fileMenuManager instanceof SubMenuManager) { IContributionManager fileManager = ((SubMenuManager) fileMenuManager).getParent(); ActionContributionItem item; fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ saveTableAction.setEnabled(table.getItemCount() > 0); item = new ActionContributionItem(saveTableAction); item.setVisible(true); fileManager.insertAfter("saveAll", item); //$NON-NLS-1$ } } public void focusLost(org.eclipse.swt.events.FocusEvent arg0) { IActionBars bars = PIPageEditor.getActionBars(); bars.setGlobalActionHandler(ActionFactory.COPY.getId(), oldCopyAction); bars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), oldSelectAllAction); bars.updateActionBars(); SubMenuManager editMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_EDIT); editMenuManager.remove("PICopyTable"); //$NON-NLS-1$ editMenuManager.update(); SubMenuManager fileMenuManager = (SubMenuManager) PIPageEditor.getMenuManager() .find(IIDEActionConstants.M_FILE); fileMenuManager.remove("PISaveTable"); //$NON-NLS-1$ fileMenuManager.update(); } }); tableViewer.refresh(); table.redraw(); }
From source file:org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider.java
License:Open Source License
/** * Contributes the given item to the given manager in the given path/group. * /*from w ww . jav a2 s. com*/ * @param contributionItem * The item to be contributed * @param contributionManager * The manager to be contributed to * @param path * The path of contribution within the manager * @param group * The group of contribution within the path */ private void contributeItem(IAdaptable contributionItemAdapter, IContributionManager contributionManager, String path, String group) { // Find parent menu. if (path == null) return; IContributionManager parent = contributionManager; if (path.length() > 1) { // if path is more than '/' parent = findMenuUsingPath(parent, path.substring(1)); if (parent == null) { Log.info(CommonUIServicesActionPlugin.getDefault(), CommonUIServicesActionStatusCodes.SERVICE_FAILURE, "The contribution item path is invalid"); //$NON-NLS-1$ return; } } //if contributing a menu group if (contributionItemAdapter instanceof MenuGroupContributionItemAdapter) { IContributionItem contributionItem = (IContributionItem) contributionItemAdapter .getAdapter(IContributionItem.class); parent.add(contributionItem); return; } //if contributing an action group if (contributionItemAdapter instanceof ActionGroupContributionItemAdapter) { try { ActionGroup actionGroup = (ActionGroup) contributionItemAdapter.getAdapter(ActionGroup.class); if (parent instanceof IMenuManager) { actionGroup.fillContextMenu((IMenuManager) parent); } } catch (IllegalArgumentException e) { Trace.catching(CommonUIServicesActionPlugin.getDefault(), CommonUIServicesActionDebugOptions.EXCEPTIONS_CATCHING, CommonUIServicesActionPlugin.getDefault().getClass(), "Error adding contribution item", e); //$NON-NLS-1$ Log.error(CommonUIServicesActionPlugin.getDefault(), CommonUIServicesActionStatusCodes.SERVICE_FAILURE, "Error adding contribution item", e); //$NON-NLS-1$ } return; } // Find reference group. if (group == null) return; IContributionItem sep = parent.find(group); if (sep == null) { if (group.equals(ContributionItemConstants.GROUP_ADDITIONS)) { sep = new Separator(group); parent.add(sep); } if (sep == null) { Log.info(CommonUIServicesActionPlugin.getDefault(), CommonUIServicesActionStatusCodes.SERVICE_FAILURE, "The contribution item group is invalid"); //$NON-NLS-1$ return; } } // Add contribution to group try { IContributionItem contributionItem = (IContributionItem) contributionItemAdapter .getAdapter(IContributionItem.class); if (contributionItem != null) { if (sep.isGroupMarker()) parent.appendToGroup(group, contributionItem); else parent.insertAfter(group, contributionItem); } else Log.info(CommonUIServicesActionPlugin.getDefault(), CommonUIServicesActionStatusCodes.SERVICE_FAILURE, "Failed to create the contribution with id: " //$NON-NLS-1$ + (String) contributionItemAdapter.getAdapter(String.class)); } catch (IllegalArgumentException e) { Trace.catching(CommonUIServicesActionPlugin.getDefault(), CommonUIServicesActionDebugOptions.EXCEPTIONS_CATCHING, CommonUIServicesActionPlugin.getDefault().getClass(), "Error adding contribution item", e); //$NON-NLS-1$ Log.error(CommonUIServicesActionPlugin.getDefault(), CommonUIServicesActionStatusCodes.SERVICE_FAILURE, "Error adding contribution item", e); //$NON-NLS-1$ } }
From source file:org.eclipse.ui.texteditor.BasicTextEditorActionContributor.java
License:Open Source License
/** * The <code>item</code> is {@link IContributionManager#add(IContributionItem) added} to * <code>menu</code> if no item with the same id currently exists. If there already is an * contribution item with the same id, the new item gets * {@link IContributionManager#insertAfter(String, IContributionItem) inserted after} it. * * @param menu the contribution manager//from ww w . j av a 2s.c o m * @param item the contribution item * @since 3.2 */ private void addOrInsert(IContributionManager menu, IContributionItem item) { String id = item.getId(); if (menu.find(id) == null) menu.add(item); else menu.insertAfter(id, item); }
From source file:org.nightlabs.base.ui.search.SearchContributionItem.java
License:Open Source License
@Override public void fill(Menu menu, int index) { if (logger.isDebugEnabled()) logger.debug("fill called for menu " + menu); //$NON-NLS-1$ String id = SearchContributionItem.class.getName(); if (getParent() != null) { IContributionManager parent = getParent(); IContributionItem removedItem = parent.remove(id); if (removedItem != null) { if (logger.isDebugEnabled()) logger.debug("item " + removedItem + " was removed from contributionManager " + parent); //$NON-NLS-1$ //$NON-NLS-2$ }/*from w w w . j av a 2 s. c om*/ IMenuManager menuManager = new MenuManager( Messages.getString("org.nightlabs.base.ui.search.SearchContributionItem.menu.search.title"), //$NON-NLS-1$ id); Map<ISearchResultProviderFactory, ISearchResultProvider> factory2Instance = getUseCase() .getFactory2Instance(); for (Map.Entry<ISearchResultProviderFactory, ISearchResultProvider> entry : factory2Instance .entrySet()) { ISearchResultProviderFactory factory = entry.getKey(); MenuContributionItem item = new MenuContributionItem(factory); menuManager.add(item); } if (parent != null) { if (parent.find(IWorkbenchActionConstants.M_FILE) != null) { parent.insertAfter(IWorkbenchActionConstants.M_FILE, menuManager); if (logger.isDebugEnabled()) logger.debug("added contribution after file menu of contributionManager " + getParent()); //$NON-NLS-1$ } else { parent.add(menuManager); if (logger.isDebugEnabled()) logger.debug("added contribution to the end of the contributionManager " + getParent()); //$NON-NLS-1$ } } else { if (logger.isDebugEnabled()) logger.info("getParent() == null, nothing contributed"); //$NON-NLS-1$ } } if (logger.isDebugEnabled()) logger.info("getParent() == null, nothing contributed"); //$NON-NLS-1$ // createMenu(menu); }