- /** Constant <code>statusLineManager</code> */
- protected static IStatusLineManager statusLineManager;
-
- /**
- * <p>
- * closeAll
- * </p>
- *
- * @return a boolean.
- */
- public static boolean closeAll() {
- return getActivePage().closeAllEditors(true);
- }
-
- /**
- * Close the given editor.
- *
- * @param editor
- * The <tt>MultipageTaxonEditor</tt> to close.
- * @return <tt>true</tt> on success
- */
- public static boolean close(EditorPart editor) {
- return getActivePage().closeEditor(editor, true);
- }
-
- /**
- * <p>
- * getShell
- * </p>
- *
- * @return a {@link org.eclipse.swt.widgets.Shell} object.
- */
- public static Shell getShell() {
-
- return TaxeditorStorePlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow().getShell();
- }
-
- /**
- * <p>
- * getActivePage
- * </p>
- *
- * @return a {@link org.eclipse.ui.IWorkbenchPage} object.
- */
- public static IWorkbenchPage getActivePage() {
-
- return TaxeditorStorePlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- }
-
- /**
- * <p>
- * getActivePart
- * </p>
- *
- * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
- */
- public static IWorkbenchPart getActivePart() {
- return getActivePage() != null ? getActivePage().getActivePart() : null;
- }
-
- public static IWorkbench getWorkbench() {
- return TaxeditorStorePlugin.getDefault().getWorkbench();
- }
-
- /**
- * <p>
- * getWorkbenchWindow
- * </p>
- *
- * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
- */
- public static ApplicationWindow getWorkbenchWindow() {
- if (getWorkbench().getWorkbenchWindowCount() > 1) {
- throw new IllegalStateException("More than one workbench window");
- }
- return (ApplicationWindow) getWorkbench().getWorkbenchWindows()[0];
- }
-
- /**
- * <p>
- * showView
- * </p>
- *
- * @param id
- * a {@link java.lang.String} object.
- * @return a {@link org.eclipse.ui.IViewPart} object.
- */
- public static IViewPart showView(String id) {
- try {
- return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
- .getActivePage()
- .showView(id, null, IWorkbenchPage.VIEW_VISIBLE);
- } catch (PartInitException e) {
- errorDialog("Error opening view", AbstractUtility.class, "Could not open view: " + id, e);
- return null;
- }
- }
-
- /**
- * <p>
- * hideView
- * </p>
- *
- * @param view
- * a {@link org.eclipse.ui.IViewPart} object.
- */
- public static void hideView(IViewPart view) {
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
- .hideView(view);
- }
-
- /**
- * <p>
- * getView
- * </p>
- *
- * @param id
- * a {@link java.lang.String} object.
- * @param restore
- * a boolean.
- * @return a {@link org.eclipse.ui.IViewPart} object.
- */
- public static IViewPart getView(String id, boolean restore) {
- IViewReference[] references = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage().getViewReferences();
- for (IViewReference reference : references) {
- if (reference.getId().equals(id)) {
- return reference.getView(restore);
- }
- }
- return null;
- }
-
- /**
- * <p>
- * getService
- * </p>
- *
- * @param api
- * a {@link java.lang.Class} object.
- * @return a {@link java.lang.Object} object.
- */
- public static Object getService(Class api) {
- return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api);
- }
-
- /**
- * <p>
- * getCurrentTheme
- * </p>
- *
- * @return a {@link org.eclipse.ui.themes.ITheme} object.
- */
- public static ITheme getCurrentTheme() {
- IThemeManager themeManager = TaxeditorStorePlugin.getDefault()
- .getWorkbench().getThemeManager();
- return themeManager.getCurrentTheme();
- }
-
- /**
- * Fonts registered to the plugin may be obtained with the Eclipse themeing
- * functionality. Thus fonts are chooseable by the user via
- * Preferences->General->Appearance->Colors and Fonts
- *
- * @return the FontRegistry for the current theme
- */
- public static FontRegistry getFontRegistry() {
- return getCurrentTheme().getFontRegistry();
- }
-
- /**
- * <p>
- * getFont
- * </p>
- *
- * @param symbolicName
- * a {@link java.lang.String} object.
- * @return a {@link org.eclipse.swt.graphics.Font} object.
- */
- public static Font getFont(String symbolicName) {
- return getFontRegistry().get(symbolicName);
- }
-
- /**
- * Color registered to the plugin may be obtained with the Eclipse themeing
- * functionality. Thus colors are editable by the user via
- * Preferences->General->Appearance->Colors and Fonts
- *
- * @return the ColorRegistry for the current theme
- */
- public static ColorRegistry getColorRegistry() {
- return getCurrentTheme().getColorRegistry();
- }
-
- /**
- * <p>
- * getColor
- * </p>
- *
- * @param symbolicName
- * a {@link java.lang.String} object.
- * @return a {@link org.eclipse.swt.graphics.Color} object.
- */
- public static Color getColor(String symbolicName) {
- return getColorRegistry().get(symbolicName);
- }
-
- /**
- * Open a message box that informs the user about unimplemented
- * functionality. This method is for developer convenience.
- *
- * @param source
- * a {@link java.lang.Object} object.
- */
- public static void notImplementedMessage(Object source) {
- warningDialog("Not yet implemented", source,
- "This functionality is not yet implemented.");
- }
-
- /**
- * <p>
- * informationDialog
- * </p>
- *
- * @param title
- * a {@link java.lang.String} object.
- * @param message
- * a {@link java.lang.String} object.
- */
- public static void informationDialog(final String title,
- final String message) {
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- MessageDialog.openInformation(getShell(), title, message);
- }
- });
- }
-
- public static void informationDialog(final String title,
- final IStatus status) {
- informationDialog(title, status.getMessage());
- }
-
- /**
- * <p>
- * warningDialog
- * </p>
- *
- * @param title
- * The dialogs title
- * @param source
- * The object where the warning was generated (used by log4j)
- * @param message
- * An informative String to be presented to the user
- */
- public static void warningDialog(final String title, final Object source,
- final String message) {
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- MessageDialog.openWarning(getShell(), title, message);
- Class<? extends Object> clazz = source != null ? source
- .getClass() : AbstractUtility.class;
- warn(clazz, message);
- }
- });
- }
-
- /**
- * @param title
- * @param termBase
- * @param status
- */
- public static void warningDialog(String title, Object source,
- IStatus status) {
- warningDialog(title, source, status.getMessage());
- }
-
- /**
- * <p>
- * errorDialog
- * </p>
- *
- * @param title
- * The dialogs title
- * @param source
- * The object where the warning was generated (used by log4j)
- * @param message
- * An informative String to be presented to the user
- * @param title
- * The dialogs title
- * @param t
- * a Throwable if one exists or null
- */
- public static void errorDialog(final String title, final Object source,
- final String message, final Throwable t) {
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- MessageDialog.openError(getShell(), title, message + getCauseRecursively(t));
- Class<? extends Object> clazz = source != null ? source
- .getClass() : this.getClass();
- error(clazz, message, t);
- }
-
- private String getCauseRecursively(Throwable t) {
- if(t == null){
- return null;
- }
-
- if(t.getCause() != null){
- return getCauseRecursively(t.getCause());
- }else{
- return String.format("\n\nException: %s\nMessage: %s", t.getClass().getSimpleName(), t.getMessage());
- }
-
- }
- });
- }
-
- public static void errorDialog(final String title, final Object source,
- final String message){
- errorDialog(title, source, message, null);
- }
-
- /**
- * <p>
- * errorDialog
- * </p>
- *
- * @param title
- * a {@link java.lang.String} object.
- * @param source
- * a {@link java.lang.Object} object.
- * @param status
- * a {@link org.eclipse.core.runtime.IStatus} object.
- */
- public static void errorDialog(final String title, final Object source,
- final IStatus status) {
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- MessageDialog.openError(getShell(), title, status.getMessage());
- Class<? extends Object> clazz = source != null ? source
- .getClass() : this.getClass();
- error(clazz, status.getMessage(), status.getException());
- }
- });
- }
-
- /**
- * <p>
- * confirmDialog
- * </p>
- *
- * @param title
- * a {@link java.lang.String} object.
- * @param message
- * a {@link java.lang.String} object.
- * @return a boolean.
- */
- public static boolean confirmDialog(String title, String message) {
- return MessageDialog.openQuestion(getShell(), title, message);
- }
-
- /**
- * <p>
- * executeOperation
- * </p>
- *
- * @param operation
- * a
- * {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation}
- * object.
- * @return a {@link org.eclipse.core.runtime.IStatus} object.
- */
- public static IStatus executeOperation(final AbstractPostOperation operation) {
- if (getOperationHistory() == null) {
- throw new IllegalArgumentException(
- "There is no operation history for this context");
- }
-
- final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
- .getUIInfoAdapter(getShell());
-
- IRunnableWithProgress runnable = new IRunnableWithProgress() {
-
- @Override
+ private static final Logger logger = Logger.getLogger(AbstractUtility.class);
+
+ /** Constant <code>statusLineManager</code> */
+ protected static IStatusLineManager statusLineManager;
+
+
+ public static boolean closeAll() {
+ if(getActivePage()!=null){
+ return getActivePage().closeAllEditors(true);
+ }
+ return false;
+ }
+
+ /**
+ * Close the given editor.
+ *
+ * @param editor
+ * The <tt>MultipageTaxonEditor</tt> to close.
+ * @return <tt>true</tt> on success
+ */
+ public static boolean close(EditorPart editor) {
+ return getActivePage() != null ? getActivePage().closeEditor(editor, true):false;
+ }
+
+ public static Shell getShell() {
+
+ return TaxeditorStorePlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getShell();
+ }
+
+ public static IWorkbenchPage getActivePage() {
+ try{
+ return TaxeditorStorePlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ } catch(NullPointerException npe){
+ return null;
+ }
+ }
+
+ public static IWorkbenchPart getActiveWorkbenchPart() {
+ IWorkbenchPage activePage = getActivePage();
+ if(activePage!=null){
+ IWorkbenchPart activePart = activePage.getActivePart();
+ if(activePart!=null){
+ return activePart;
+ }
+ }
+ return null;
+ }
+
+ public static Object getActiveE4Part() {
+ IWorkbenchPage activePage = getActivePage();
+ if(activePage!=null){
+ IWorkbenchPart activePart = activePage.getActivePart();
+ Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
+ return e4WrappedPart!=null?e4WrappedPart:activePart;
+ }
+ return null;
+ }
+
+ public static IWorkbench getWorkbench() {
+ return TaxeditorStorePlugin.getDefault().getWorkbench();
+ }
+
+ public static IWorkbenchWindow getWorkbenchWindow() {
+ if (getWorkbench().getWorkbenchWindowCount() > 1) {
+ throw new IllegalStateException("More than one workbench window");
+ }
+ return getWorkbench().getWorkbenchWindows()[0];
+ }
+
+ public static IViewPart showView(String id) {
+ try {
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getActivePage()
+ .showView(id, null, IWorkbenchPage.VIEW_VISIBLE);
+ } catch (PartInitException e) {
+ MessagingUtils.messageDialog("Error opening view", AbstractUtility.class, "Could not open view: " + id, e);
+ return null;
+ }
+ }
+
+ public static void hideView(IViewPart view) {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .hideView(view);
+ }
+
+ public static IViewPart getView(String id, boolean restore) {
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
+ IViewReference[] references = null;
+ if(activeWorkbenchWindow!=null && activeWorkbenchWindow.getActivePage()!=null){
+ references = activeWorkbenchWindow.getActivePage().getViewReferences();
+ }
+ else if(workbench.getWorkbenchWindows().length>0 && workbench.getWorkbenchWindows()[0].getActivePage()!=null){
+ references = workbench.getWorkbenchWindows()[0].getActivePage().getViewReferences();
+ }
+ if(references!=null){
+ for (IViewReference reference : references) {
+ if (reference.getId().equals(id)) {
+ return reference.getView(restore);
+ }
+ }
+ }
+ return null;
+ }
+
+ public static Object getService(Class api) {
+ return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api);
+ }
+
+ public static ITheme getCurrentTheme() {
+ IThemeManager themeManager = TaxeditorStorePlugin.getDefault()
+ .getWorkbench().getThemeManager();
+ return themeManager.getCurrentTheme();
+ }
+
+ /**
+ * Fonts registered to the plugin may be obtained with the Eclipse themeing
+ * functionality. Thus fonts are chooseable by the user via
+ * Preferences->General->Appearance->Colors and Fonts
+ *
+ * @return the FontRegistry for the current theme
+ */
+ public static FontRegistry getFontRegistry() {
+ return getCurrentTheme().getFontRegistry();
+ }
+
+ public static Font getFont(String symbolicName) {
+ return getFontRegistry().get(symbolicName);
+ }
+
+ /**
+ * Color registered to the plugin may be obtained with the Eclipse themeing
+ * functionality. Thus colors are editable by the user via
+ * Preferences->General->Appearance->Colors and Fonts
+ *
+ * @return the ColorRegistry for the current theme
+ */
+ public static ColorRegistry getColorRegistry() {
+ return getCurrentTheme().getColorRegistry();
+ }
+
+ public static Color getColor(String symbolicName) {
+ return getColorRegistry().get(symbolicName);
+ }
+
+ public static IStatus executeOperation(final AbstractPostOperation operation) {
+ if (getOperationHistory() == null) {
+ throw new IllegalArgumentException(
+ "There is no operation history for this context");
+ }
+
+ final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
+ .getUIInfoAdapter(getShell());
+
+ IRunnableWithProgress runnable = new IRunnableWithProgress() {
+
+ @Override
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ String operationlabel = operation.getLabel();
+ monitor.beginTask(operationlabel, 100);
+ IStatus status = Status.CANCEL_STATUS;
+ try {
+ operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
+ status = getOperationHistory().execute(operation, monitor,
+ uiInfoAdapter);
+ } catch (ExecutionException e) {
+
+ MessagingUtils.operationDialog(this, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
+
+ } finally {
+ monitor.done();
+ }
+
+ String statusString = status.equals(Status.OK_STATUS) ? "completed"
+ : "cancelled";
+ setStatusLine(operationlabel + " " + statusString + ".");
+
+ }
+ };
+
+ try {
+ runInUI(runnable, null);
+ } catch (Exception e) {
+ MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
+ }
+
+ IPostOperationEnabled postOperationEnabled = operation
+ .getPostOperationEnabled();
+ if (postOperationEnabled != null) {
+ postOperationEnabled.onComplete();
+ }
+ return Status.OK_STATUS;
+ }
+
+ public static IStatus executeOperation(final AbstractOperation operation, final RemotingCdmHandlerE4 handler) {
+ return executeOperation(operation, handler);
+ }
+
+ public static IStatus executeOperation(final AbstractOperation operation, final RemotingCdmHandler handler) {
+ return executeOperation(operation, handler);
+ }
+
+ public static IStatus executeOperation(final AbstractOperation operation, final Object handler) {
+ if (getOperationHistory() == null) {
+ throw new IllegalArgumentException(
+ "There is no operation history for this context");
+ }
+
+ final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
+ .getUIInfoAdapter(getShell());
+
+ IRunnableWithProgress runnable = new IRunnableWithProgress() {
+
+ @Override