List of usage examples for org.eclipse.jface.util Policy TRACE_ACTIONS
boolean TRACE_ACTIONS
To view the source code for org.eclipse.jface.util Policy TRACE_ACTIONS.
Click Source Link
From source file:com.github.haixing_hu.swt.action.ActionContributionItemEx.java
License:Open Source License
/** * Handles a widget selection event.// www. j a v a 2 s . c o m */ private void handleWidgetSelection(Event e, boolean selection) { final Widget item = e.widget; if (item != null) { final int style = item.getStyle(); if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) { if (action.getStyle() == IAction.AS_CHECK_BOX) { action.setChecked(selection); } } else if ((style & SWT.RADIO) != 0) { if (action.getStyle() == IAction.AS_RADIO_BUTTON) { action.setChecked(selection); } } else if ((style & SWT.DROP_DOWN) != 0) { if (e.detail == 4) { // on drop-down button if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) { final IMenuCreator mc = action.getMenuCreator(); menuCreatorCalled = true; final ToolItem ti = (ToolItem) item; // we create the menu as a sub-menu of "dummy" so that // we can use // it in a cascading menu too. // If created on a SWT control we would get an SWT // error... // Menu dummy= new Menu(ti.getParent()); // Menu m= mc.getMenu(dummy); // dummy.dispose(); if (mc != null) { final Menu m = mc.getMenu(ti.getParent()); if (m != null) { // position the menu below the drop down item final Point point = ti.getParent().toDisplay(new Point(e.x, e.y)); m.setLocation(point.x, point.y); // waiting // for SWT // 0.42 m.setVisible(true); return; // we don't fire the action } } } } } ExternalActionManager.IExecuteCallback callback = null; final String actionDefinitionId = action.getActionDefinitionId(); if (actionDefinitionId != null) { final Object obj = ExternalActionManager.getInstance().getCallback(); if (obj instanceof ExternalActionManager.IExecuteCallback) { callback = (ExternalActionManager.IExecuteCallback) obj; } } // Ensure action is enabled first. // See 1GAN3M6: ITPUI:WINNT - Any IAction in the workbench can be // executed while disabled. if (action.isEnabled()) { final boolean trace = Policy.TRACE_ACTIONS; long ms = 0L; if (trace) { ms = System.currentTimeMillis(); System.out.println("Running action: " + action.getText()); //$NON-NLS-1$ } IPropertyChangeListener resultListener = null; if (callback != null) { resultListener = new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { // Check on result if (event.getProperty().equals(IAction.RESULT)) { if (event.getNewValue() instanceof Boolean) { result = (Boolean) event.getNewValue(); } } } }; action.addPropertyChangeListener(resultListener); callback.preExecute(action, e); } action.runWithEvent(e); if (callback != null) { if ((result == null) || result.equals(Boolean.TRUE)) { callback.postExecuteSuccess(action, Boolean.TRUE); } else { callback.postExecuteFailure(action, new ExecutionException(action.getText() + " returned failure.")); //$NON-NLS-1$ } } if (resultListener != null) { result = null; action.removePropertyChangeListener(resultListener); } if (trace) { System.out .println((System.currentTimeMillis() - ms) + " ms to run action: " + action.getText()); //$NON-NLS-1$ } } else { if (callback != null) { callback.notEnabled(action, new NotEnabledException(action.getText() + " is not enabled.")); //$NON-NLS-1$ } } } }
From source file:fede.workspace.tool.view.menu.MenuActionContributionItem.java
License:Apache License
/** * Handles a widget selection event.//from w w w .j ava 2 s .c o m */ protected void handleWidgetSelection(Event e, boolean selection) { Widget item = e.widget; if (item == null) { return; } if (widget == null) { return; } boolean trace = Policy.TRACE_ACTIONS; IMenuAction aMenuAction = (IMenuAction) item.getData(REF); if (aMenuAction == null) { return; } long ms = System.currentTimeMillis(); if (trace) { System.out.println("Running action: " + aMenuAction.getLabel()); //$NON-NLS-1$ } try { aMenuAction.run(this.selection); } catch (CadseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (trace) { System.out.println((System.currentTimeMillis() - ms) + " ms to run action: " + aMenuAction.getLabel()); //$NON-NLS-1$ } }
From source file:org.eclipse.ui.internal.JFaceUtil.java
License:Open Source License
/** * Initializes JFace for use by Eclipse. *//*from www.j a va 2s.c o m*/ public static void initializeJFace() { // Set the SafeRunner to run all SafeRunnables SafeRunnable.setRunner(new ISafeRunnableRunner() { public void run(ISafeRunnable code) { SafeRunner.run(code); } }); // Pass all errors and warnings to the status handling facility // and the rest to the main runtime log Policy.setLog(new ILogger() { public void log(IStatus status) { if (status.getSeverity() == IStatus.WARNING || status.getSeverity() == IStatus.ERROR) { StatusManager.getManager().handle(status); } else { WorkbenchPlugin.log(status); } } }); Policy.setStatusHandler(new StatusHandler() { public void show(IStatus status, String title) { StatusAdapter statusAdapter = new StatusAdapter(status); statusAdapter.setProperty(StatusAdapter.TITLE_PROPERTY, title); StatusManager.getManager().handle(statusAdapter, StatusManager.SHOW); } }); // Get all debug options from Platform if ("true".equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug"))) { //$NON-NLS-1$ //$NON-NLS-2$ Policy.DEBUG_DIALOG_NO_PARENT = "true" //$NON-NLS-1$ .equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/dialog/noparent")); //$NON-NLS-1$ Policy.TRACE_ACTIONS = "true" //$NON-NLS-1$ .equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/actions")); //$NON-NLS-1$ Policy.TRACE_TOOLBAR = "true" //$NON-NLS-1$ .equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/trace/toolbarDisposal")); //$NON-NLS-1$ InternalPolicy.DEBUG_LOG_REENTRANT_VIEWER_CALLS = "true".equalsIgnoreCase( //$NON-NLS-1$ Platform.getDebugOption(Policy.JFACE + "/debug/viewers/reentrantViewerCalls")); //$NON-NLS-1$ InternalPolicy.DEBUG_LOG_EQUAL_VIEWER_ELEMENTS = "true" //$NON-NLS-1$ .equalsIgnoreCase(Platform.getDebugOption(Policy.JFACE + "/debug/viewers/equalElements")); //$NON-NLS-1$ } }
From source file:org.springframework.ide.eclipse.boot.dash.util.ToolbarPulldownContributionItem.java
License:Open Source License
/** * Handles a widget selection event./*from w w w . j a v a 2 s . co m*/ */ private void handleWidgetSelection(Event e, boolean selection) { Widget item = e.widget; if (item != null) { int style = item.getStyle(); if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) { if (action.getStyle() == IAction.AS_CHECK_BOX) { action.setChecked(selection); } } else if ((style & SWT.RADIO) != 0) { if (action.getStyle() == IAction.AS_RADIO_BUTTON) { action.setChecked(selection); } } else if ((style & SWT.DROP_DOWN) != 0) { //HACK CHANGE start //if (e.detail == 4) { // on drop-down button //HACK CHANGE end if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) { IMenuCreator mc = action.getMenuCreator(); menuCreatorCalled = true; ToolItem ti = (ToolItem) item; // we create the menu as a sub-menu of "dummy" so that // we can use // it in a cascading menu too. // If created on a SWT control we would get an SWT // error... // Menu dummy= new Menu(ti.getParent()); // Menu m= mc.getMenu(dummy); // dummy.dispose(); if (mc != null) { Menu m = mc.getMenu(ti.getParent()); if (m != null) { // position the menu below the drop down item //Point point = ti.getParent().toDisplay( // new Point(e.x, e.y)); //HACK CHANGE start //When clicking the button the event position is actually 0,0 // use something better. Point point = new Point(e.x, e.y); if (point.x == 0 && point.y == 0) { Rectangle bnds = ti.getBounds(); point.x = bnds.x; point.y = bnds.y + bnds.height; } point = ti.getParent().toDisplay(point); //HACK CHANGE end m.setLocation(point.x, point.y); // waiting // for SWT // 0.42 m.setVisible(true); return; // we don't fire the action } } } //HACK CHANGE: } } ExternalActionManager.IExecuteCallback callback = null; String actionDefinitionId = action.getActionDefinitionId(); if (actionDefinitionId != null) { Object obj = ExternalActionManager.getInstance().getCallback(); if (obj instanceof ExternalActionManager.IExecuteCallback) { callback = (ExternalActionManager.IExecuteCallback) obj; } } // Ensure action is enabled first. // See 1GAN3M6: ITPUI:WINNT - Any IAction in the workbench can be // executed while disabled. if (action.isEnabled()) { boolean trace = Policy.TRACE_ACTIONS; long ms = 0L; if (trace) { ms = System.currentTimeMillis(); System.out.println("Running action: " + action.getText()); //$NON-NLS-1$ } IPropertyChangeListener resultListener = null; if (callback != null) { resultListener = new IPropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { // Check on result if (event.getProperty().equals(IAction.RESULT)) { if (event.getNewValue() instanceof Boolean) { result = (Boolean) event.getNewValue(); } } } }; action.addPropertyChangeListener(resultListener); callback.preExecute(action, e); } action.runWithEvent(e); if (callback != null) { if (result == null || result.equals(Boolean.TRUE)) { callback.postExecuteSuccess(action, Boolean.TRUE); } else { callback.postExecuteFailure(action, new ExecutionException(action.getText() + " returned failure.")); //$NON-NLS-1$ } } if (resultListener != null) { result = null; action.removePropertyChangeListener(resultListener); } if (trace) { System.out .println((System.currentTimeMillis() - ms) + " ms to run action: " + action.getText()); //$NON-NLS-1$ } } else { if (callback != null) { callback.notEnabled(action, new NotEnabledException(action.getText() + " is not enabled.")); //$NON-NLS-1$ } } } }
From source file:org.xmind.ui.color.ColorPicker.java
License:Open Source License
/** * Handles a widget selection event.// w ww . j a va 2 s . com */ private void handleWidgetSelection(Event e, boolean selection) { Widget item = e.widget; if (item != null) { int style = item.getStyle(); if ((style & (SWT.TOGGLE | SWT.CHECK)) != 0) { if (action.getStyle() == IAction.AS_CHECK_BOX) { action.setChecked(selection); } } else if ((style & SWT.RADIO) != 0) { if (action.getStyle() == IAction.AS_RADIO_BUTTON) { action.setChecked(selection); } } else if ((style & SWT.DROP_DOWN) != 0) { if (e.detail == 4) { // on drop-down button if (action.getStyle() == IAction.AS_DROP_DOWN_MENU) { // IMenuCreator mc = action.getMenuCreator(); // ToolItem ti = (ToolItem) item; // // we create the menu as a sub-menu of "dummy" so that we can use // // it in a cascading menu too. // // If created on a SWT control we would get an SWT error... // //Menu dummy= new Menu(ti.getParent()); // //Menu m= mc.getMenu(dummy); // //dummy.dispose(); // if (mc != null) { // Menu m = mc.getMenu(ti.getParent()); // if (m != null) { // // position the menu below the drop down item // Rectangle b = ti.getBounds(); // Point p = ti.getParent().toDisplay( // new Point(b.x, b.y + b.height)); // m.setLocation(p.x, p.y); // waiting for SWT 0.42 // m.setVisible(true); // return; // we don't fire the action // } // } } } } // Ensure action is enabled first. // See 1GAN3M6: ITPUI:WINNT - Any IAction in the workbench can be executed while disabled. if (action.isEnabled()) { boolean trace = Policy.TRACE_ACTIONS; long ms = System.currentTimeMillis(); if (trace) { System.out.println("Running action: " + action.getText()); //$NON-NLS-1$ } action.runWithEvent(e); if (trace) { System.out .println((System.currentTimeMillis() - ms) + " ms to run action: " + action.getText()); //$NON-NLS-1$ } } } }