import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.FontRegistry;
-import org.eclipse.jface.window.ApplicationWindow;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
+import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog;
import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
+import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
/**
- * <p>
- * Abstract AbstractUtility class.
- * </p>
*
* @author n.hoffmann
* @created 11.05.2009
protected static IStatusLineManager statusLineManager;
- /**
- * <p>
- * closeAll
- * </p>
- *
- * @return a boolean.
- */
public static boolean closeAll() {
if(getActivePage()!=null){
return getActivePage().closeAllEditors(true);
* @return <tt>true</tt> on success
*/
public static boolean close(EditorPart editor) {
- return getActivePage().closeEditor(editor, true);
+ return getActivePage() != null ? getActivePage().closeEditor(editor, true):false;
}
- /**
- * <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() {
+ try{
+ return TaxeditorStorePlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ } catch(NullPointerException npe){
+ return null;
+ }
+ }
- return TaxeditorStorePlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
+ public static IWorkbenchPart getActiveWorkbenchPart() {
+ IWorkbenchPage activePage = getActivePage();
+ if(activePage!=null){
+ IWorkbenchPart activePart = activePage.getActivePart();
+ if(activePart!=null){
+ return activePart;
+ }
+ }
+ return null;
}
- /**
- * <p>
- * getActivePart
- * </p>
- *
- * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
- */
- public static IWorkbenchPart getActivePart() {
- return getActivePage() != null ? getActivePage().getActivePart() : 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();
}
- /**
- * <p>
- * getWorkbenchWindow
- * </p>
- *
- * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
- */
- public static ApplicationWindow getWorkbenchWindow() {
+ public static IWorkbenchWindow getWorkbenchWindow() {
if (getWorkbench().getWorkbenchWindowCount() > 1) {
throw new IllegalStateException("More than one workbench window");
}
- return (ApplicationWindow) getWorkbench().getWorkbenchWindows()[0];
+ return 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()
}
}
- /**
- * <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) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
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 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);
}
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);
}
- /**
- * <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(
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");
operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
status = getOperationHistory().execute(operation, monitor,
uiInfoAdapter);
- if(handler != null) {
- handler.postOperation(status);
+ if(handler instanceof RemotingCdmHandler) {
+ ((RemotingCdmHandler) handler).postOperation(status);
+ }
+ else if(handler instanceof RemotingCdmHandlerE4) {
+ ((RemotingCdmHandlerE4) handler).postOperation(status);
}
} catch (ExecutionException e) {
MessagingUtils.operationDialog(this, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
return Status.OK_STATUS;
}
-
- /**
- * <p>
- * getOperationHistory
- * </p>
- *
- * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
- * object.
- */
public static IOperationHistory getOperationHistory() {
return getWorkbench().getOperationSupport().getOperationHistory();
}
- /**
- * <p>
- * setStatusLine
- * </p>
- *
- * @param message
- * a {@link java.lang.String} object.
- */
public static void setStatusLine(final String message) {
Display.getDefault().asyncExec(new Runnable() {
}
- /**
- * <p>
- * getMonitor
- * </p>
- *
- * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
- */
public static IProgressMonitor getMonitor() {
statusLineManager.setCancelEnabled(false);
return statusLineManager.getProgressMonitor();
getProgressService().busyCursorWhile(runnable);
}
- /**
- * <p>
- * runInUI
- * </p>
- *
- * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
- * @param runnable
- * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
- * object.
- * @param rule
- * a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
- * object.
- * @throws java.lang.reflect.InvocationTargetException
- * if any.
- * @throws java.lang.InterruptedException
- * if any.
- */
public static void runInUI(IRunnableWithProgress runnable,
ISchedulingRule rule) throws InvocationTargetException,
InterruptedException {
getProgressService().runInUI(getWorkbenchWindow(), runnable, rule);
}
- /**
- * <p>
- * run
- * </p>
- *
- * @param fork
- * a boolean.
- * @param cancelable
- * a boolean.
- * @param runnable
- * a {@link org.eclipse.jface.operation.IRunnableWithProgress}
- * object.
- * @throws java.lang.reflect.InvocationTargetException
- * if any.
- * @throws java.lang.InterruptedException
- * if any.
- */
public static void run(boolean fork, boolean cancelable,
IRunnableWithProgress runnable) throws InvocationTargetException,
InterruptedException {
getProgressService().run(fork, cancelable, runnable);
}
- /**
- * <p>
- * getProgressService
- * </p>
- *
- * @return a {@link org.eclipse.ui.progress.IProgressService} object.
- */
public static IProgressService getProgressService() {
IWorkbench workbench = PlatformUI.getWorkbench();
return workbench.getProgressService();
}
- /**
- * <p>
- * getProgressService2
- * </p>
- *
- * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
- * object.
- */
public static IWorkbenchSiteProgressService getProgressService2() {
return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
}
- /**
- * <p>
- * getPluginId
- * </p>
- *
- * @return a {@link java.lang.String} object.
- */
public static String getPluginId() {
return "eu.taxeditor";
}
- /**
- * <p>
- * getActiveEditor
- * </p>
- *
- * @return a {@link org.eclipse.ui.IEditorPart} object.
- */
public static IEditorPart getActiveEditor() {
return getActivePage() != null ? getActivePage().getActiveEditor()
: null;
}
- /**
- * <p>
- * getDetailsView
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
- * object.
- */
+ public static Object getActiveE4Editor() {
+ //FIXME E4 this can be simplified/removed when fully migrated
+ if(getActivePage()!=null){
+ IEditorPart activeEditor = getActivePage().getActiveEditor();
+ Object activePart = getActivePage().getActivePart();
+ if(activeEditor==null){
+ activePart = TaxeditorStorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class).getActivePart();
+ }
+ Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
+ return wrappedPart!=null?wrappedPart:activeEditor;
+ }
+ return null;
+ }
+
public static DetailsViewPart getDetailsView() {
return (DetailsViewPart) getView(DetailsViewPart.ID, false);
}
- /**
- * <p>
- * refreshDetailsViewer
- * </p>
- */
public static void refreshDetailsViewer() {
if (getDetailsView() != null) {
((AbstractCdmDataViewer) getDetailsView().getViewer()).refresh();
}
}
- /**
- * <p>
- * reflowDetailsViewer
- * </p>
- */
public static void reflowDetailsViewer() {
if (getDetailsView() != null) {
((AbstractCdmDataViewer) getDetailsView().getViewer()).reflow();
private final T term;
private final TreeSet<TermNode<T>> children;
- /**
- * @param term
- * @param children
- */
public TermNode(T term) {
super();
this.term = term;
this.children.add(child);
}
- /**
- * @return the children
- */
public TreeSet<TermNode<T>> getChildren() {
return children;
}
- /**
- * @return the term
- */
public T getTerm() {
return term;
}
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
@Override
public int hashCode() {
final int prime = 31;
return result;
}
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
- /* (non-Javadoc)
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
@Override
public int compareTo(TermNode<T> that) {
return this.term.getMessage().compareTo(that.term.getMessage());
}
}
}
+
+ public static Object getElementsFromSelectionChangedEvent(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ Object selectionToSet = selection;
+ if(selection.size() == 1){
+ selectionToSet = selection.getFirstElement();
+ }
+ else if(!selection.isEmpty()){
+ selectionToSet = selection.toArray();
+ }
+ return selectionToSet;
+ }
}