import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.NotEnabledException;
-import org.eclipse.core.commands.NotHandledException;
-import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.commands.operations.IOperationHistory;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
import org.eclipse.ui.progress.IProgressConstants;
-import org.eclipse.ui.progress.IProgressService;
-import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
import eu.etaxonomy.cdm.io.common.ExportDataWrapper;
import eu.etaxonomy.cdm.io.common.ExportResult;
import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator;
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;
*/
public abstract class AbstractUtility {
- private static final Logger logger = Logger.getLogger(AbstractUtility.class);
+ protected static final Logger logger = Logger.getLogger(AbstractUtility.class);
/** Constant <code>statusLineManager</code> */
protected static IStatusLineManager statusLineManager;
String statusString = status.equals(Status.OK_STATUS) ? "completed"
: "cancelled";
setStatusLine(operationlabel + " " + statusString + ".");
+ IPostOperationEnabled postOperationEnabled = operation
+ .getPostOperationEnabled();
+ if (postOperationEnabled != null) {
+ postOperationEnabled.onComplete();
+ }
});
});
job.setUser(true);
job.schedule();
} catch (Exception e) {
- MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
+ MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occurred while executing " + operation.getLabel(), e);
}
- IPostOperationEnabled postOperationEnabled = operation
- .getPostOperationEnabled();
- if (postOperationEnabled != null) {
- postOperationEnabled.onComplete();
- }
return Status.OK_STATUS;
}
return executeOperation_internal(operation, handler, sync);
}
- public static IStatus executeOperation(final AbstractOperation operation, final RemotingCdmHandler handler, UISynchronize sync) {
- return executeOperation_internal(operation, handler, sync);
- }
-
- private static IStatus executeOperation_internal(final AbstractOperation operation, final Object handler,
+ private static IStatus executeOperation_internal(final AbstractOperation operation, final RemotingCdmHandlerE4 handler,
UISynchronize sync) {
if (getOperationHistory() == null) {
throw new IllegalArgumentException(
operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
status = operation.execute(monitor,
uiInfoAdapter);
- if(handler instanceof RemotingCdmHandler) {
- ((RemotingCdmHandler) handler).postOperation(status);
- }
- else if(handler instanceof RemotingCdmHandlerE4) {
- ((RemotingCdmHandlerE4) handler).postOperation(status);
- }
+ handler.postOperation(status);
} catch (ExecutionException e) {
MessagingUtils.operationDialog(AbstractUtility.class, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
} finally {
job.setUser(true);
sync.syncExec(()->job.schedule());
} catch (Exception e) {
- MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
+ MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occurred while executing " + operation.getLabel(), e);
}
return Status.OK_STATUS;
// get the remoting monitor the first time to make sure that the
// operation is valid
final IProgressMonitorService progressMonitorService = CdmApplicationState.getCurrentAppConfig().getProgressMonitorService();
- final IRemotingProgressMonitor firstRemotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
- if(firstRemotingMonitor == null) {
- throw new IllegalStateException("Remoting progress monitor is null");
- }
+// final IRemotingProgressMonitor firstRemotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
+// if(firstRemotingMonitor == null) {
+// throw new IllegalStateException("Remoting progress monitor is null");
+// }
Job job = new Job(label) {
ZipOutputStream zos = new ZipOutputStream(stream);
for (String key: keySet){
byte[] fileData = resultMap.get(key);
- ZipEntry entry = new ZipEntry( key + fileEnding);
+ ZipEntry entry = new ZipEntry( key);
zos.putNextEntry(entry);
zos.write(fileData);
zos.closeEntry();
} catch (Exception e) {
MessagingUtils.errorDialog("Error executing operation",
AbstractUtility.class,
- "An error occured while executing " + label,
+ "An error occurred while executing " + label,
TaxeditorStorePlugin.PLUGIN_ID,
e,
true);
newMonitor.worked(steps);
}
- public static IProgressService getProgressService() {
- IWorkbench workbench = PlatformUI.getWorkbench();
- return workbench.getProgressService();
- }
-
- public static IWorkbenchSiteProgressService getProgressService2() {
- return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
- }
-
public static String getPluginId() {
return "eu.taxeditor";
}
}
}
-
- public static void executeCommand(String commandId, Object source, String pluginId) {
- IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
- Exception exception = null;
- try {
- handlerService.executeCommand(commandId, null);
- } catch (ExecutionException e) {
- exception = e;
- } catch (NotDefinedException e) {
- exception = e;
- } catch (NotEnabledException e) {
- exception = e;
- } catch (NotHandledException e) {
- exception = e;
- } finally {
- if(exception != null) {
- MessagingUtils.errorDialog("Error executing command",
- source,
- "Could not execute command with id " + commandId ,
- pluginId,
- exception,
- true);
- }
- }
- }
-
public static Object getElementsFromSelectionChangedEvent(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
Object selectionToSet = selection;
if(selection.size() == 1){
selectionToSet = selection.getFirstElement();
+ if (selectionToSet instanceof Object[]){
+ Object[] selectionArray = (Object[])selectionToSet;
+ selectionToSet = selectionArray;
+ }
}
else if(!selection.isEmpty()){
selectionToSet = selection.toArray();
final StringBuilder reportSb = new StringBuilder();
// collect reports
// for(String report : remotingMonitor.getResult()) {
+ if (remotingMonitor.getResult() instanceof ExportResult) {
reportSb.append(((ExportResult)remotingMonitor.getResult()).createReport());
+ }else if (remotingMonitor.getResult() instanceof UpdateResult){
+ reportSb.append(((UpdateResult)remotingMonitor.getResult()).getExceptions().toString());
+ }
// }
if(!StringUtils.isBlank(reportSb.toString())) {
Display.getDefault().asyncExec(new Runnable() {
} catch (Exception e) {
MessagingUtils.errorDialog("Error executing operation",
AbstractUtility.class,
- "An error occured while executing " + label,
+ "An error occurred while executing " + label,
TaxeditorStorePlugin.PLUGIN_ID,
e,
true);