package eu.etaxonomy.taxeditor.bulkeditor.preference;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
+import org.eclipse.jface.preference.BooleanFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import eu.etaxonomy.cdm.model.common.MarkerType;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.TermStore;
/**
- * <p>BulkEditorMarkerPreferenceComposite class.</p>
- *
* @author p.ciardelli
* @created 17.08.2009
* @version 1.0
*/
-public class BulkEditorMarkerPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+public class BulkEditorMarkerPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
- private Map<MarkerType, Boolean> markerTypeEditingMap = new HashMap<MarkerType, Boolean>();
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(PreferencesUtil.getPreferenceStore());
if(!CdmStore.isActive()) {
MessagingUtils.noDataSourceWarningDialog(null);
- }else{
- markerTypeEditingMap = PreferencesUtil.getEditMarkerTypePreferences();
}
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
- */
- @Override
- protected Control createContents(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
- container.setLayout(new GridLayout());
+ @Override
+ protected void createFieldEditors() {
if(CdmStore.isActive()){
for (final MarkerType markerType : TermStore.getTerms(MarkerType.class)) {
- final Button button = new Button(container, SWT.CHECK);
- button.setText(String.format("Edit '%s' markers", markerType.getLabel()));
-
- button.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- markerTypeEditingMap.put(markerType, button.getSelection());
- }
- });
-
- boolean edit = markerTypeEditingMap.get(markerType) == null ? true : markerTypeEditingMap.get(markerType);
-
- button.setSelection(edit);
+ addField(new BooleanFieldEditor(IPreferenceKeys.EDIT_MARKER_TYPE_PREFIX
+ + markerType.getClass().getName() + markerType.getLabel(), String.format("Edit '%s' markers",
+ markerType.getLabel()), getFieldEditorParent()));
}
}
- return container;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#performOk()
- */
- @Override
- public boolean performOk() {
- PreferencesUtil.setEditMarkerTypePreferences(markerTypeEditingMap);
- return super.performOk();
- }
+ }
}
<!-- name="eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor"> -->
<!-- <level value="info" /> -->
<!-- </logger> -->
+<!-- <logger -->
+<!-- name="eu.etaxonomy.taxeditor.session.DefaultNewEntityListener"> -->
+<!-- <level value="info" /> -->
+<!-- </logger> -->
+<!-- <logger -->
+<!-- name="eu.etaxonomy.taxeditor.util.ProgressMonitorClientManager"> -->
+<!-- <level value="info" /> -->
+<!-- </logger> -->
</log4j:configuration>
\ No newline at end of file
package eu.etaxonomy.taxeditor.editor.name.handler;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
import org.apache.log4j.Logger;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.handlers.HandlerUtil;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.taxon.Synonym;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
editor = (MultiPageTaxonEditor) HandlerUtil.getActiveEditor(event);
Shell shell = HandlerUtil.getActiveShell(event);
IEditorInput input = editor.getEditorInput();
+ // Get synonym from selection before possible save dialog
+ // because the selection will be null if save dialog is shown
+ StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
+
if (!EditorUtil.forceUserSave(editor, shell)) {
return null;
}
return null;
}
- // Get synonym from selection
- StructuredSelection selection = (StructuredSelection) HandlerUtil.getCurrentSelection(event);
- if (!(selection.getFirstElement() instanceof Synonym)) {
+ if (selection==null || !(selection.getFirstElement() instanceof Synonym)) {
+ MessagingUtils.warningDialog("No selection", this, "No synonym selected");
logger.error("Selection does not contain a Synonym");
return null;
}
Taxon oldParent = ((TaxonEditorInput)input).getTaxon();
List<UUID> excludeTaxa = new ArrayList<UUID>();
excludeTaxa.add(oldParent.getUuid());
+
TaxonNode newParentNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), "Select new accepted taxon", excludeTaxa, null, ((TaxonEditorInput)input).getTaxonNode().getClassification());
+
if(newParentNode!=null){
MoveSynonymToAnotherAcceptedTaxonOperation operation = new MoveSynonymToAnotherAcceptedTaxonOperation("Change accepted Taxon of Synonym", EditorUtil.getUndoContext(),
oldParent.getUuid(), synonym.getUuid(), newParentNode.getTaxon(), editor);
"Choose the accepted taxon",
excludeTaxa,
null,
- null);
+ sourceTaxonNode.getClassification());
if(targetTaxonNode == null) {
return new Status(IStatus.CANCEL,
TaxonNode parentTaxonNode;
List<UUID> excludeTaxa = new ArrayList<UUID>();
- excludeTaxa.add(((TaxonNode)oldTaxonNode).getTaxon().getUuid());
+ excludeTaxa.add(oldTaxonNode.getTaxon().getUuid());
boolean moveToNewParent = true;
if (PreferencesUtil.getSortNodesNaturally()){
- if(!MessageDialog.openQuestion(activeShell, "Target node", "The choosen target node should be the parent?")){
+ if(!MessageDialog.openQuestion(activeShell, "Target node", "Should the choosen target node be the parent of this taxon node?")){
moveToNewParent = false;
}
parentTaxonNode = TaxonNodeSelectionDialog.select(activeShell,
"Choose the taxon above the moved taxon.",
excludeTaxa,
null,
- null);
+ oldTaxonNode.getClassification());
} else {
parentTaxonNode = TaxonNodeSelectionDialog.select(activeShell,
new ConversationHolderMock(),
"Choose new parent",
excludeTaxa,
null,
- null);
+ oldTaxonNode.getClassification());
}
uuid,
1000,
false,
- ImportManager.this);
+ ImportManager.this,
+ null);
}
});
import org.eclipse.wb.swt.ResourceManager;
import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
/**
btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
btnClear.addListener(SWT.Selection, this);
- //report
- Label labelReportFile = new Label(composite, SWT.NONE);
- labelReportFile.setText("Report File");
+ if(!CdmStore.getCurrentSessionManager().isRemoting()) {
+ //report
+ Label labelReportFile = new Label(composite, SWT.NONE);
+ labelReportFile.setText("Report File");
- fileDialogReport = new FileDialog(parent.getShell());
+ fileDialogReport = new FileDialog(parent.getShell());
- fileDialogReport.setFilterExtensions(new String[]{"*.*"});
+ fileDialogReport.setFilterExtensions(new String[]{"*.*"});
- textFileReport = new Text(composite, SWT.BORDER);
- textFileReport.setEditable(false);
- textFileReport.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ textFileReport = new Text(composite, SWT.BORDER);
+ textFileReport.setEditable(false);
+ textFileReport.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- Button buttonReport = new Button(composite, SWT.PUSH);
- buttonReport.setText("Browse...");
+ Button buttonReport = new Button(composite, SWT.PUSH);
+ buttonReport.setText("Browse...");
- buttonReport.addSelectionListener(new SelectionAdapter(){
+ buttonReport.addSelectionListener(new SelectionAdapter(){
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetSelected(SelectionEvent e) {
- String path = fileDialogReport.open();
- if(path!=null){
- textFileReport.setText(path);
- setPageComplete(true);
- }
- }
-
- });
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
+ */
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String path = fileDialogReport.open();
+ if(path!=null){
+ textFileReport.setText(path);
+ setPageComplete(true);
+ }
+ }
+ });
+ }
setControl(composite);
}
}
public URI getReportUri(){
+ if(textFileReport == null) {
+ return null;
+ }
String text = textFileReport.getText();
if(text==null || text.isEmpty()){
return null;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IStatusLineManager;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.FontRegistry;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
import org.eclipse.ui.part.EditorPart;
+import org.eclipse.ui.progress.IProgressConstants;
import org.eclipse.ui.progress.IProgressService;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import org.eclipse.ui.themes.ITheme;
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
import eu.etaxonomy.cdm.model.common.IEnumTerm;
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
+import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator;
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
final UUID uuid,
final int pollInterval,
final boolean cancelable,
- final IPostMoniteredOperationEnabled postOp) {
+ final IPostMoniteredOperationEnabled postOp,
+ final IFeedbackGenerator feedbackGenerator) {
try {
// get the remoting monitor the first time to make sure that the
throw new IllegalStateException("Remoting progress monitor is null");
}
- final ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell());
- IRunnableWithProgress runnable = new IRunnableWithProgress() {
+ Job job = new Job(label) {
+
@Override
- public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
- // run the monitor untilthe operation is finished
- IRemotingProgressMonitor remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor(label, uuid, pollInterval, postOp, monitor);
+ public IStatus run(IProgressMonitor monitor) {
+ // run the monitor until the operation is finished
+ IRemotingProgressMonitor remotingMonitor;
+ try {
+ remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor(label,
+ uuid,
+ pollInterval,
+ postOp,
+ feedbackGenerator,
+ monitor);
+ } catch (Exception ex) {
+ return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
+ }
final StringBuilder reportSb = new StringBuilder();
// collect reports
for(String report : remotingMonitor.getReports()) {
@Override
public void run() {
// display reports with possibility to save
- ReportTextDialog dialog = new ReportTextDialog(progressDialog.getShell());
+ ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
dialog.setTitle(label + " Report");
dialog.setReportText(reportSb.toString());
dialog.open();
}
});
}
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ protected void canceling() {
+ CdmStore.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid);
}
};
- progressDialog.run(true, cancelable, runnable);
+ // configure the job
+ job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
+ job.setUser(true);
+ // schedule job
+ job.schedule();
+
} catch (Exception e) {
MessagingUtils.errorDialog("Error executing operation",
AbstractUtility.class,
/**
- *
+ *
*/
package eu.etaxonomy.taxeditor.model;
+import java.io.Serializable;
+
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
* @version 1.0
*/
public class CdmProgressMonitorAdapter implements eu.etaxonomy.cdm.common.monitor.IProgressMonitor {
-
+
private IProgressMonitor progressMonitor;
private CdmProgressMonitorAdapter (IProgressMonitor monitor){
if(monitor == null){
monitor = new NullProgressMonitor();
}
-
+
this.progressMonitor = monitor;
}
-
+
/**
* <p>CreateMonitor</p>
*
public static CdmProgressMonitorAdapter CreateMonitor (IProgressMonitor monitor){
return new CdmProgressMonitorAdapter(monitor);
}
-
+
/**
* <p>CreateSubMonitor</p>
*
IProgressMonitor subMonitor = StoreUtil.getSubProgressMonitor(monitor, ticks);
return new CdmProgressMonitorAdapter(subMonitor);
}
-
+
/** {@inheritDoc} */
@Override
public void beginTask(String name, int totalWork) {
public void internalWorked(double arg0) {
progressMonitor.internalWorked(arg0);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Serializable getFeedback() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean getIsWaitingForFeedback() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFeedback(Serializable arg0) {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void waitForFeedback() {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getOwner() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean hasFeedbackWaitTimedOut() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void interrupt() {
+
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setOwner(String arg0) {
+
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void waitForFeedback(long arg0) {
+
+ }
+
}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.operation;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+import org.eclipse.swt.widgets.Display;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+
+/**
+ * Default implementation of the {@link IFeedbackGenerator} interface.
+ *
+ * @author cmathew
+ * @date 29 Oct 2015
+ *
+ */
+public abstract class FeedbackGenerator implements IFeedbackGenerator {
+
+
+ /**
+ * Generates feedback for a waiting remoting progress monitor
+ *
+ * @return feedback object
+ */
+ public abstract Serializable generateFeedback();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFeedbackForMonitor(final UUID uuid) {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ CdmApplicationState.getCurrentAppConfig().getProgressMonitorService().setFeedback(uuid, generateFeedback());
+ }
+ });
+ }
+
+}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.operation;
+
+import java.util.UUID;
+
+/**
+ * Generates feeback for waiting remoting progress monitors.
+ * The default implementation of this interface is {@link FeedbackGenerator}
+ *
+ * @author cmathew
+ * @date 28 Oct 2015
+ *
+ */
+public interface IFeedbackGenerator {
+
+ /**
+ * Generates and sets feedback for a waiting remoting progress
+ * monitor corresponding to the given uuid.
+ *
+ * @param uuid of target waiting remoting progress monitor
+ */
+ public void setFeedbackForMonitor(UUID uuid);
+
+}
public static final String SEARCH_OPEN_RESULTS_IN_SEPARATE_WINDOWS = "eu.etaxonomy.taxeditor.navigation.search.openResultInSeparateWindows";
+ public static final String DISABLE_SERVICES_API_TIMESTAMP_CHECK = "eu.etaxonomy.taxeditor.cdmlib.remoting.disableServicesApiTimestampCheck";
+
public static final String ADD_TYPES_TO_ALL_NAMES = "eu.etaxonomy.taxeditor.store.addTypeToAllNames";
public static final String DETERMINATION_ONLY_FOR_FIELD_UNITS = "eu.etaxonomy.taxeditor.specimen.determinationOnlyOnFieldUnitLevel";
// $Id$
/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
- *
+ *
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
package eu.etaxonomy.taxeditor.preference;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Text;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.IntegerFieldEditor;
+import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
* @created Feb 4, 2011
* @version 1.0
*/
-public class MobotOpenUrlPreferences extends PreferencePage implements
+public class MobotOpenUrlPreferences extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {
- private String openUrlServiceAccessPoint;
- private String openUrlImageMaxWidth;
- private String openUrlImageMaxHeight;
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
- @Override
- public void init(IWorkbench workbench) {
- setPreferenceStore(PreferencesUtil.getPreferenceStore());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse
- * .swt.widgets.Composite)
- */
- @Override
- protected Control createContents(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
- final GridLayout gridLayout = new GridLayout();
- container.setLayout(gridLayout);
-
- creatOpenUrlServiceAccessPoint(container);
-
- createOpenUrlImageSize(container);
-
- return container;
- }
-
- /**
- * @param container
- */
- private void createOpenUrlImageSize(Composite container) {
- openUrlImageMaxWidth = getPreferenceStore().getString(
- IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH);
- openUrlImageMaxHeight = getPreferenceStore().getString(
- IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT);
-
- Composite composite = new Composite(container, SWT.NULL);
- final GridLayout gridLayout = new GridLayout(2, false);
- composite.setLayout(gridLayout);
-
- final CLabel labelWidth = new CLabel(composite, SWT.NULL);
- labelWidth.setText("Image Maximum Width: ");
-
- final Text textWidth = new Text(composite, SWT.BORDER);
- textWidth.setText(openUrlImageMaxWidth);
- textWidth.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
-
- textWidth.addModifyListener(new ModifyListener() {
-
- public void modifyText(ModifyEvent e) {
- openUrlImageMaxWidth = textWidth.getText();
- }
- });
-
- final CLabel labelHeight = new CLabel(composite, SWT.NULL);
- labelHeight.setText("Image Maximum Height: ");
-
- final Text textHeight = new Text(composite, SWT.BORDER);
- textHeight.setText(openUrlImageMaxHeight);
- textHeight.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
-
- textHeight.addModifyListener(new ModifyListener() {
-
- public void modifyText(ModifyEvent e) {
- openUrlImageMaxHeight = textHeight.getText();
- }
- });
- }
-
- private void creatOpenUrlServiceAccessPoint(Composite composite) {
- openUrlServiceAccessPoint = getPreferenceStore().getString(
- IPreferenceKeys.OPENURL_ACCESS_POINT);
-
- final CLabel label = new CLabel(composite, SWT.NULL);
- label.setText("Mobot Open Url Service Access Point:");
-
- final Text text = new Text(composite, SWT.BORDER);
- text.setText(openUrlServiceAccessPoint);
- text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
-
- text.addModifyListener(new ModifyListener() {
-
- public void modifyText(ModifyEvent e) {
- openUrlServiceAccessPoint = text.getText();
- }
- });
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.PreferencePage#performOk()
- */
- @Override
- public boolean performOk() {
- getPreferenceStore().setValue(IPreferenceKeys.OPENURL_ACCESS_POINT,
- openUrlServiceAccessPoint);
- getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH,
- openUrlImageMaxWidth);
- getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT,
- openUrlImageMaxHeight);
-
- return super.performOk();
- }
+ @Override
+ protected void createFieldEditors() {
+ addField(new StringFieldEditor(
+ IPreferenceKeys.OPENURL_ACCESS_POINT,
+ "Mobot Open Url Service Access Point:", getFieldEditorParent()));
+ addField(new IntegerFieldEditor(
+ IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH,
+ "Image Maximum Width:",
+ getFieldEditorParent()));
+ addField(new IntegerFieldEditor(
+ IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT,
+ "Image Maximum Height:",
+ getFieldEditorParent()));
+
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(PreferencesUtil.getPreferenceStore());
+ }
}
addField(new BooleanFieldEditor(IPreferenceKeys.SEARCH_OPEN_RESULTS_IN_SEPARATE_WINDOWS,
"Open search results in separate windows",
getFieldEditorParent()));
+ addField(new BooleanFieldEditor(IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK,
+ "Disable services api timestamp check",
+ getFieldEditorParent()));
}
/*
import java.util.List;
import java.util.Map;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
- * <p>Abstract AbstractMatchingPreferences class.</p>
- *
* @author n.hoffmann
* @created Jan 22, 2010
* @version 1.0
*/
-public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends PreferencePage implements
+public abstract class AbstractMatchingPreferences<T extends IdentifiableEntity> extends FieldEditorPreferencePage implements
IWorkbenchPreferencePage {
/**
protected Map<String, Combo> matchModeCombos = new HashMap<String, Combo>();
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(PreferencesUtil.getPreferenceStore());
+ }
+
+ /**
+ * {@inheritDoc}
*/
- /** {@inheritDoc} */
@Override
- protected Control createContents(Composite parent) {
- final Composite composite = new Composite(parent, SWT.NULL);
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 2;
- composite.setLayout(gridLayout);
-
- if(!CdmStore.isActive()) {
+ protected void createFieldEditors() {
+ if(!CdmStore.isActive()) {
MessagingUtils.noDataSourceWarningDialog(null);
}else{
for(String fieldName : getFieldNames()){
- createFieldWidget(composite, fieldName);
+ String[][] comboValues = new String[getMatchModeList().size()][2];
+ for (int i=0;i<getMatchModeList().size();i++) {
+ comboValues[i][0] = getMatchModeList().get(i).name();
+ comboValues[i][1] = getMatchModeList().get(i).name();
+ }
+ addField(new ComboFieldEditor(this.getClass().getCanonicalName()+fieldName,
+ fieldName, comboValues,
+ getFieldEditorParent()));
}
}
-
- return composite;
- }
-
- /**
- * Creates a widget for a field consisting of the label and a combo
- *
- * @see {@link #createMatchModeCombo(Composite, String, MatchMode)}
- * @param composite
- * @param fieldName
- */
- private void createFieldWidget(Composite parent, String fieldName) {
- CLabel label = new CLabel(parent, SWT.NONE);
- label.setText(fieldName);
- MatchMode matchMode = matchStrategy.getMatchMode(fieldName);
-
- createMatchModeCombo(parent, fieldName, matchMode);
- }
-
- /**
- * Creates a combo for a field with the currently selected match mode for that field preselected
- *
- * @param parent
- * @param matchMode
- */
- private void createMatchModeCombo(Composite parent, String fieldName, MatchMode selectedMatchMode) {
- Combo matchModeCombo = new Combo(parent, SWT.NULL);
-
- for (MatchMode matchMode : getMatchModeList()) {
- matchModeCombo.add(matchMode.name());
- }
-
- int index = getMatchModeList().indexOf(selectedMatchMode);
-
- matchModeCombo.select(index);
-
- matchModeCombo.addSelectionListener(new MatchModeComboSelectionListener(matchModeCombo, fieldName));
-
- matchModeCombos.put(fieldName, matchModeCombo);
- }
-
- /**
- * This listener updates the cache strategy when a value was changed in one of the combos
- *
- * @author n.hoffmann
- * @created Jan 28, 2010
- * @version 1.0
- */
- private class MatchModeComboSelectionListener extends SelectionAdapter{
-
- private final Combo matchModeCombo;
- private final String fieldName;
-
- MatchModeComboSelectionListener(Combo matchModeCombo, String fieldName){
- this.matchModeCombo = matchModeCombo;
- this.fieldName = fieldName;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetSelected(SelectionEvent event) {
- super.widgetSelected(event);
- MatchMode matchMode = getMatchModeList().get(matchModeCombo.getSelectionIndex());
- try {
- matchStrategy.setMatchMode(fieldName, matchMode);
- } catch (MatchException e) {
- MessagingUtils.error(this.getClass(), e);
- throw new RuntimeException(e);
- }
- }
}
/**
return fields;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#performApply()
- */
- /** {@inheritDoc} */
- @Override
- protected void performApply() {
- PreferencesUtil.setMatchStrategy(matchStrategy);
- super.performApply();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
- */
- /** {@inheritDoc} */
- @Override
- protected void performDefaults() {
- try {
- // set match strategy to default
- matchStrategy = getDefaultMatchStrategy();
-
- // set combos to their default values
- for(String fieldName : matchModeCombos.keySet()){
- Combo combo = matchModeCombos.get(fieldName);
- MatchMode matchMode = matchStrategy.getMatchMode(fieldName);
- combo.select(matchModeList.indexOf(matchMode));
- }
-
- } catch (MatchException e) {
- MessagingUtils.error(this.getClass(), e);
- throw new RuntimeException(e);
- }
- super.performDefaults();
- }
-
/**
* Returns the default match strategy for the respective class
*
*/
public class NonViralNameMatchingPreference extends AbstractMatchingPreferences<NonViralName>{
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
/** {@inheritDoc} */
@Override
public void init(IWorkbench workbench) {
+ super.init(workbench);
clazz = NonViralName.class;
try {
}
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
- */
/** {@inheritDoc} */
@Override
protected IMatchStrategy getDefaultMatchStrategy() throws MatchException {
import eu.etaxonomy.taxeditor.model.MessagingUtils;
/**
- * <p>ReferenceMatchingPreference class.</p>
- *
* @author n.hoffmann
* @created Jan 22, 2010
* @version 1.0
*/
public class ReferenceMatchingPreference extends AbstractMatchingPreferences<Reference> {
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
/** {@inheritDoc} */
@Override
public void init(IWorkbench workbench) {
+ super.init(workbench);
clazz = Reference.class;
try {
}
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
- */
/** {@inheritDoc} */
@Override
protected IMatchStrategy getDefaultMatchStrategy() throws MatchException {
import eu.etaxonomy.taxeditor.model.MessagingUtils;
/**
- * <p>TeamOrPersonMatchingPreference class.</p>
- *
* @author n.hoffmann
* @created Jan 22, 2010
* @version 1.0
public class TeamOrPersonMatchingPreference extends
AbstractMatchingPreferences<TeamOrPersonBase> {
- /* (non-Javadoc)
- * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
- */
/** {@inheritDoc} */
@Override
public void init(IWorkbench workbench) {
-
+ super.init(workbench);
clazz = TeamOrPersonBase.class;
try {
}
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.preference.matching.AbstractMatchingPreferences#getDefaultMatchStrategy()
- */
/** {@inheritDoc} */
@Override
protected IMatchStrategy getDefaultMatchStrategy() throws MatchException {
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.ui.dialog;
+
+import java.io.Serializable;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+
+import eu.etaxonomy.taxeditor.operation.FeedbackGenerator;
+
+/**
+ * Feedback Generator corresponding to a {@link MessageBox}
+ *
+ * @author cmathew
+ * @date 29 Oct 2015
+ *
+ */
+public class FeedbackMessageBox extends FeedbackGenerator {
+
+ private Shell shell;
+ /**
+ * @param parent
+ */
+ public FeedbackMessageBox(Shell parent) {
+ this.shell = parent;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Serializable generateFeedback() {
+
+ // create a dialog with ok and cancel buttons and a question icon
+ MessageBox dialog =
+ new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK| SWT.CANCEL);
+ dialog.setText("Monitor Feedback");
+ dialog.setMessage("Do you really want to continue?");
+
+ // open dialog and await user selection
+ return dialog.open();
+ }
+}
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
if(available) {
txtServerCDMVersion.setText(selectedCsii.getCdmRemoteSource(selectedCdmInstance, getPort()).getDbSchemaVersion());
int compareDbSchemaVersion = selectedCsii.compareDbSchemaVersion(selectedCdmInstance, getPort());
- int compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
-
+ int compareCdmlibServicesVersion = 0;
+ boolean disableServicesApiTimestampCheck =
+ PreferencesUtil.getPreferenceStore().getBoolean((IPreferenceKeys.DISABLE_SERVICES_API_TIMESTAMP_CHECK));
+ if(!disableServicesApiTimestampCheck) {
+ compareCdmlibServicesVersion = selectedCsii.compareCdmlibServicesVersion();
+ }
if(compareDbSchemaVersion > 0 || compareCdmlibServicesVersion > 0) {
status = STATUS_NOT_COMPATIBLE;
available = false;
available = true;
message = "";
}
-
-
}
-
} catch (Exception e) {
txtCdmInstanceStatus.setToolTipText(e.getMessage());
} finally {
// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import org.eclipse.ui.forms.widgets.TableWrapData;
import eu.etaxonomy.cdm.common.UriUtils;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
/**
- * <p>ImageElement class.</p>
- *
* @author n.hoffmann
* @created Sep 24, 2010
* @version 1.0
private URI imageUri;
private Image image;
-
+
private Composite container;
- /**
- * <p>Constructor for ImageElement.</p>
- *
- * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
- * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
- * @param imageUri a {@link java.net.URI} object.
- * @param style a int.
- */
+ private final Runnable postRunnable = new Runnable(){
+ @Override
+ public void run() {
+ AbstractUtility.reflowDetailsViewer();
+ AbstractUtility.reflowSupplementalViewer();
+ }
+ };
+
protected ImageElement(CdmFormFactory formFactory, ICdmFormElement parentElement, URI imageUri, int style) {
super(formFactory, parentElement);
-
+
container = new Composite(getLayoutComposite(), style);
container.setLayoutData(LayoutConstants.FILL(2, 1));
-
+
container.addPaintListener(this);
}
- /**
- * <p>Setter for the field <code>imageUri</code>.</p>
- *
- * @param uri a {@link java.net.URI} object.
- * @throws HttpException
- * @throws IOException
- */
public void initImageUri(URI uri) throws IOException, HttpException {
this.imageUri = uri;
InputStream imageStream = UriUtils.getInputStream(imageUri);
image = new Image(Display.getCurrent(), imageStream);
}
-
-
- /**
- * <p>Getter for the field <code>imageUri</code>.</p>
- *
- * @return the imageUri
- */
+
+
public URI getImageUri() {
return imageUri;
}
-
+
public void loadImage(){
- loadImage(null);
- }
-
-
-
- public void loadImage(final Runnable postRunnable){
if(getImageUri() != null){
Job job = new Job("Loading image") {
-
+
@Override
protected IStatus run(IProgressMonitor monitor) {
IRunnableWithProgress runnable = getLoadImageRunnable(postRunnable);
} catch (Exception e) {
MessagingUtils.messageDialog("Could not load image", getClass(), e.getMessage() + ": " + getImageUri(), e);
}
-
+
return Status.OK_STATUS;
}
};
job.schedule();
}
}
-
-
- public void unloadImage(final Runnable postRunnable) {
+ public void unloadImage() {
Job job = new Job("Unloading image") {
-
+
@Override
protected IStatus run(IProgressMonitor monitor) {
IRunnableWithProgress runnable = getLoadImageRunnable(postRunnable);
} catch (Exception e) {
MessagingUtils.messageDialog("Could not unload image", getClass(), e.getMessage() + ": " + getImageUri(), e);
}
-
+
return Status.OK_STATUS;
}
};
job.schedule();
-
+
}
-
+
public IRunnableWithProgress getLoadImageRunnable(final Runnable postRunnable){
-
- final Display display = getLayoutComposite().getDisplay();
-
+
+ final Display display = getLayoutComposite().getDisplay();
+
IRunnableWithProgress runnable = new IRunnableWithProgress(){
-
+
@Override
public void run(IProgressMonitor monitor) {
monitor.beginTask("Loading: " + getImageUri(), IProgressMonitor.UNKNOWN);
-
+
// redraw the image container
display.asyncExec(new Runnable(){
@Override
public void run() {
- if(! getLayoutComposite().isDisposed()){
+ if(! getLayoutComposite().isDisposed() && container!=null){
Event untypedEvent = new Event();
untypedEvent.widget = container;
PaintEvent event = new PaintEvent(untypedEvent);
}
}
});
-
+
// execute the external runnable
if(postRunnable != null){
display.asyncExec(postRunnable);
}
- monitor.done();
+ monitor.done();
}
};
-
+
return runnable;
}
-
+
private Rectangle calculateImageBounds(Image image, Control control){
Rectangle imageBounds = image.getBounds();
Rectangle containerBounds = control.getBounds();
-
+
Integer imgWidth = imageBounds.width;
Integer imgHeight = imageBounds.height;
-
+
Float ratio = imgHeight.floatValue()/imgWidth.floatValue();
Integer width = containerBounds.width;
Integer height = ((Float) (width * ratio)).intValue();
-
+
return new Rectangle(containerBounds.x, containerBounds.y, width, height);
}
+ public void dispose(){
+ if(image!=null){
+ image.dispose();
+ image = null;
+ }
+ imageUri = null;
+ if(container!=null){
+ container.dispose();
+ container = null;
+ }
+ }
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
- */
/** {@inheritDoc} */
@Override
public void paintControl(PaintEvent e) {
import eu.etaxonomy.cdm.common.media.ImageInfo;
import eu.etaxonomy.cdm.model.media.ImageFile;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
private KeyValueViewerElement element_keyValue;
private ImageElement element_image;
-
- private final Runnable postRunnable = new Runnable(){
- @Override
- public void run() {
- AbstractUtility.reflowDetailsViewer();
- AbstractUtility.reflowSupplementalViewer();
- }
- };
-
-
public ImageFileElement(CdmFormFactory cdmFormFactory,
AbstractFormSection section, ImageFile element,
SelectionListener removeListener, int style) {
private void loadImage(URI uri, boolean updateDimensions) throws IOException, HttpException{
element_image.initImageUri(uri);
- element_image.loadImage(postRunnable );
+ element_image.loadImage();
if(uri == null){
}
protected void handleException(Exception e) {
- element_image.unloadImage(postRunnable);
+ element_image.unloadImage();
text_height.setNumber(0);
text_width.setNumber(0);
- element_image.loadImage(new Runnable(){
- @Override
- public void run() {
- AbstractUtility.reflowDetailsViewer();
- AbstractUtility.reflowSupplementalViewer();
- }
- });
+ element_image.loadImage();
}
}
*/
package eu.etaxonomy.taxeditor.ui.section.media;
+import java.io.IOException;
import java.net.URI;
import java.util.List;
import java.util.Set;
+import org.apache.http.HttpException;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Label;
+
+import eu.etaxonomy.cdm.common.media.ImageInfo;
import eu.etaxonomy.cdm.model.media.Media;
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.ImageElement;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
* Used to store the URI even if it is invalid and thus cannot be stored in CDM
*/
private String uriBuffer;
+ private ImageElement element_image;
+ private Label lblNoImage;
public MediaDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
super(formFactory, formElement);
if(uri==null){
uriBuffer=textUri.getText();
}
+ else{
+
+ ImageInfo imageInfo;
+ try {
+ imageInfo = ImageInfo.NewInstance(uri, 10000);
+ singleMediaRepresentationPart.getMediaRepresentation().setMimeType(imageInfo.getMimeType());
+ singleMediaRepresentationPart.getMediaRepresentation().setSuffix(imageInfo.getSuffix());
+ element_image = formFactory.createImageElement(parentFormElement, uri, style);
+ loadImage(singleMediaRepresentationPart.getUri());
+ } catch (Exception e) {
+ handleException();
+ }
+ }
}
}
if(textUri!=null){
removeElementsAndControls(textUri);
}
+ if(element_image!=null){
+ element_image.dispose();
+ element_image = null;
+ }
section_mediaRepresentation = formFactory.createMediaRepresentationSection(getConversationHolder(), parentFormElement, style);
section_mediaRepresentation.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
section_mediaRepresentation.setEntity(getEntity());
textUri.parseText();
}
textUri.getLayoutComposite().layout();
+
+ element_image = formFactory.createImageElement(parentFormElement, null, style);
+ try {
+ loadImage(singleMediaRepresentationPart.getUri());
+ } catch (Exception e) {
+ handleException();
+ }
}
}
isAdvancedMediaView = false;
}
+ private void loadImage(URI uri) throws IOException, HttpException{
+ element_image.initImageUri(uri);
+ element_image.loadImage();
+ if(uri == null){
+ return;
+ }
+ lblNoImage.dispose();
+ lblNoImage = null;
+ }
+
+ private void handleException() {
+ element_image.unloadImage();
+ element_image.loadImage();
+ element_image.dispose();
+ if(lblNoImage==null){
+ lblNoImage = formFactory.createLabel(getLayoutComposite(), "No Image found");
+ lblNoImage.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ lblNoImage.setAlignment(SWT.CENTER);
+ }
+ }
+
public boolean isAdvancedMediaView() {
return isAdvancedMediaView;
}
//TODO add context menu for deleting associations
- Label associationsLabel = formFactory.createLabel(getLayoutComposite(), "Individuals Associations");
- associationsLabel.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
-
- associationsViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
- associationsViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- associationsViewer.setContentProvider(new ArrayContentProvider());
Collection<TaxonBase<?>> associatedTaxa = CdmStore.getService(IOccurrenceService.class).listAssociatedTaxa(entity.innerDerivedUnit(), null, null, null, null);
- associationsViewer.setInput(associatedTaxa);
- associationsViewer.addDoubleClickListener(this);
+ Collection<SpecimenTypeDesignation> typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(entity.innerDerivedUnit(), null, null, null, null);
- Label typeLabel = formFactory.createLabel(getLayoutComposite(), "Type Designations");
- typeLabel.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ if(!associatedTaxa.isEmpty()){
+ associationsViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
+ associationsViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ associationsViewer.setContentProvider(new ArrayContentProvider());
+ associationsViewer.setInput(associatedTaxa);
+ associationsViewer.addDoubleClickListener(this);
+ }
+ else{
+ Label label = formFactory.createLabel(getLayoutComposite(), "No associations");
+ label.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ }
- typeDesignationViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
- typeDesignationViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
- typeDesignationViewer.setContentProvider(new ArrayContentProvider());
- Collection<SpecimenTypeDesignation> typeDesignations = CdmStore.getService(IOccurrenceService.class).listTypeDesignations(entity.innerDerivedUnit(), null, null, null, null);
//TODO implement service method for this which is just used in the label provider
Collection<TaxonBase<?>> typedTaxa = new HashSet<TaxonBase<?>>();
for (SpecimenTypeDesignation specimenTypeDesignation : typeDesignations) {
}
}
}
- typeDesignationViewer.setInput(typedTaxa);
- typeDesignationViewer.addDoubleClickListener(this);
+ if(!typedTaxa.isEmpty()){
+ Label typeLabel = formFactory.createLabel(getLayoutComposite(), "Type Designations");
+ typeLabel.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+
+ typeDesignationViewer = new TableViewer(getLayoutComposite(), SWT.FULL_SELECTION);
+ typeDesignationViewer.getTable().setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+ typeDesignationViewer.setContentProvider(new ArrayContentProvider());
+ typeDesignationViewer.setInput(typedTaxa);
+ typeDesignationViewer.addDoubleClickListener(this);
+ }
}
/** {@inheritDoc} */
//empty
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
- */
@Override
public void doubleClick(DoubleClickEvent event) {
if(event.getSelection() instanceof IStructuredSelection){
package eu.etaxonomy.taxeditor.util;
import java.text.DecimalFormat;
+import java.util.Arrays;
+import java.util.List;
import java.util.UUID;
import org.apache.log4j.Logger;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
+import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator;
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
/**
public class ProgressMonitorClientManager {
private static final Logger logger = Logger.getLogger(ProgressMonitorClientManager.class);
+ /**
+ * Polls the progress monitor service for the progress status of a monitor
+ * corresponding to the given uuid.
+ *
+ * @param label for the operation
+ * @param uuid of the remoting monitor already started on the server
+ * @param pollInterval in milliseconds
+ * @param cancelable flag which determines whether the operation can be cancelled
+ * @param postOp callback for running post operation logic
+ * @param feedbackGenerator feedback generator corresponding to the
+ * 'wait on feedback' request made on the remoting monitor
+ * @param monitor to be updated
+ * @return a final progress monitor after the operation is completed
+ * @throws InterruptedException
+ */
+ public IRemotingProgressMonitor pollMonitor(final String label,
+ final UUID uuid,
+ final int pollInterval,
+ final IPostMoniteredOperationEnabled postOp,
+ IFeedbackGenerator feedbackGenerator,
+ IProgressMonitor monitor) throws InterruptedException {
+ return pollMonitor(label, uuid, pollInterval, postOp, Arrays.asList(feedbackGenerator), monitor);
+ }
/**
* Polls the progress monitor service for the progress status of a monitor
* corresponding to the given uuid.
* @param pollInterval in milliseconds
* @param cancelable flag which determines whether the operation can be cancelled
* @param postOp callback for running post operation logic
+ * @param feedbackGenerators list of feedback generators corresponding to the
+ * size and exact order of the 'wait on feedback' requests made on the
+ * remoting monitor
* @param monitor to be updated
* @return a final progress monitor after the operation is completed
* @throws InterruptedException
final UUID uuid,
final int pollInterval,
final IPostMoniteredOperationEnabled postOp,
+ List<IFeedbackGenerator> feedbackGenerators,
IProgressMonitor monitor) throws InterruptedException {
IProgressMonitorService progressMonitorService = CdmApplicationState.getCurrentAppConfig().getProgressMonitorService();
IRemotingProgressMonitor remotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
try {
final int START_DELAY=10;
- // wait about 10 seconds for the remoting monitor to be initialised (i.e. for the begin task method to be called)
+ // wait about 10 seconds for the remoting monitor to be initialised
+ // (i.e. for the begin task method to be called ON THE REMOTING MONITOR)
for(int i=0;i<START_DELAY;i++) {
Thread.sleep(1000);
logger.info("Waiting for monitered work to start ..");
int editorTotalWorkDone = 0;
int serverTotalWorkDone = 0;
// loop until the operation is done
+ int feedbackCount = 0;
while(!(remotingMonitor.isCanceled() || remotingMonitor.isFailed() || remotingMonitor.isDone())) {
// wait for pollInterval, then
// .... retrieve remoting monitor, then
// .... set client monitor info
Thread.sleep(pollInterval);
remotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
+ // check if remoting monitor is waiting for feedback
+ if(remotingMonitor.getIsWaitingForFeedback()) {
+ if(feedbackGenerators != null) {
+ // if we have run out of feedback generators while
+ // the remoting monitor is waiting on feedback
+ // then throw exception
+ if(feedbackCount + 1 > feedbackGenerators.size()) {
+ throw new IllegalStateException("Remoting monitor waiting on feedback that does not exist");
+ }
+ feedbackGenerators.get(feedbackCount).setFeedbackForMonitor(uuid);
+ feedbackCount++;
+ }
+ }
serverTotalWorkDone = (int) remotingMonitor.getWorkDone();
- logger.warn("Work done from start: " + serverTotalWorkDone);
+ logger.info("Work done from start: " + serverTotalWorkDone);
String percentage = new DecimalFormat("#.##").format(remotingMonitor.getPercentage());
+ // set dialog text
monitor.setTaskName(label + " " + percentage + "% done ");
monitor.subTask(remotingMonitor.getSubTask());
int worked = serverTotalWorkDone - editorTotalWorkDone;
}
editorTotalWorkDone = serverTotalWorkDone;
}
+ if(remotingMonitor.getResult() instanceof Exception) {
+ throw new IllegalStateException((Exception)remotingMonitor.getResult());
+ }
return remotingMonitor;
} finally {
- if(postOp != null) {
+ if(postOp != null && remotingMonitor.isDone()) {
postOp.postOperation(remotingMonitor);
}
}
FieldUnitDetailSection fieldUnitDetailSection = formFactory.createFieldUnitDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE);
addPart(fieldUnitDetailSection);
}
+ else{
+ if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS)){
+ formFactory.createHorizontalSeparator(parent, SWT.BORDER);
+ TaxonAssociationDetailSection taxonAssociationDetailSection = formFactory.createTaxonAssociationDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+ addPart(taxonAssociationDetailSection);
+ }
+ formFactory.createHorizontalSeparator(parent, SWT.BORDER);
+ IdentifierDetailSection identifierDetailSection = formFactory.createIdentifierDetailSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
+ addPart(identifierDetailSection);
+ }
if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.DETERMINATION_ONLY_FOR_FIELD_UNITS)){
formFactory.createHorizontalSeparator(parent, SWT.BORDER);
DeterminationDetailSection determinationDetailSection = formFactory.createDeterminationDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE);
addPart(determinationDetailSection);
}
- if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_TAXON_ASSOCIATIONS)){
- formFactory.createHorizontalSeparator(parent, SWT.BORDER);
- TaxonAssociationDetailSection taxonAssociationDetailSection = formFactory.createTaxonAssociationDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
- addPart(taxonAssociationDetailSection);
- }
-
- formFactory.createHorizontalSeparator(parent, SWT.BORDER);
- IdentifierDetailSection identifierDetailSection = formFactory.createIdentifierDetailSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
- addPart(identifierDetailSection);
}
cacher = getCacher(sessionOwner);
UserDetails extraUser = null;
+
try {
extraUser = userService.loadUserByUsername(extraUsername);
} catch (UsernameNotFoundException unfe) {
*/
package eu.etaxonomy.taxeditor.service;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.UUID;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.Test;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
import eu.etaxonomy.cdm.api.service.ITestService;
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
import eu.etaxonomy.cdm.common.monitor.RemotingProgressMonitor;
import eu.etaxonomy.taxeditor.httpinvoker.RemotingSessionAwareTest;
+import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator;
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
import eu.etaxonomy.taxeditor.store.CdmStore;
@Test
public void testMonitLongRunningMethod() throws InterruptedException {
- UUID uuid = testService.monitLongRunningMethod(null);
+ UUID uuid = testService.monitLongRunningMethod(null, null, 0);
int pollInterval = 1000;
RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
expectedMonitor.setResult("Success");
expectedMonitor.addReport("Report");
expectedMonitor.done();
- IRemotingProgressMonitor remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
+ CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
uuid,
pollInterval,
new MockPostMoniteredOperationEnabled(expectedMonitor, uuid),
+ (IFeedbackGenerator)null,
new NullProgressMonitor());
}
public void testMonitLongRunningMethodByChangingUser() throws InterruptedException {
IllegalStateException ise = new IllegalStateException("IllegalStateException");
- UUID uuid = testService.monitLongRunningMethod(ise);
+ UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
authenticateExtraUser();
IRemotingProgressMonitor monitor = progressMonitorService.getRemotingMonitor(uuid);
Assert.assertNull(monitor);
@Test
public void testMonitLongRunningMethodWithException() throws InterruptedException {
IllegalStateException ise = new IllegalStateException("IllegalStateException");
- UUID uuid = testService.monitLongRunningMethod(ise);
+ UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
int pollInterval = 1000;
RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
expectedMonitor.setResult(ise);
expectedMonitor.setIsFailed(true);
expectedMonitor.done();
- IRemotingProgressMonitor remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
- uuid,
- pollInterval,
- new MockPostMoniteredOperationEnabled(expectedMonitor, uuid),
- new NullProgressMonitor());
+ try {
+ CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
+ uuid,
+ pollInterval,
+ new MockPostMoniteredOperationEnabled(expectedMonitor, uuid),
+ (IFeedbackGenerator)null,
+ new NullProgressMonitor());
+ Assert.fail("Exception due to inconsistent number of feedback generators not thrown");
+ } catch(IllegalStateException e) {
+
+ }
}
@Test
- public void testMonitLongRunningMethodWithCancellation() throws InterruptedException {
- IllegalStateException ise = new IllegalStateException("Cancelled Exception");
- final UUID uuid = testService.monitLongRunningMethod(ise);
+ public void testMonitLongRunningMethodWithInterrupt() {
+ IllegalStateException ise = new IllegalStateException("Interrupted Exception");
+ final UUID uuid = testService.monitLongRunningMethod(ise, null, 0);
final int pollInterval = 1000;
final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
expectedMonitor.setResult(ise);
@Override
public void run() {
try {
- IRemotingProgressMonitor remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
+ CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
uuid,
pollInterval,
null,
+ (IFeedbackGenerator)null,
new NullProgressMonitor());
+ Assert.fail("InterruptedException wrapped in an IllegalStateException should be thrown");
} catch (InterruptedException e) {
+ } catch (IllegalStateException e) {
+
}
}
-
};
thread.start();
while(!progressMonitorService.isMonitorThreadRunning(uuid)) {}
}
+ @Test
+ public void testMonitLongRunningMethodWithCancellation() throws InterruptedException {
+
+ final UUID uuid = testService.monitLongRunningMethod(null, null, 0);
+ final int pollInterval = 1000;
+ final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
+ expectedMonitor.setResult("Cancelled");
+ expectedMonitor.setCanceled(true);
+ expectedMonitor.done();
+
+ Thread thread = new Thread() {
+ @Override
+ public void run() {
+ try {
+ CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
+ uuid,
+ pollInterval,
+ null,
+ (IFeedbackGenerator)null,
+ new NullProgressMonitor());
+ } catch (InterruptedException e) {
+
+ }
+ }
+
+ };
+ thread.start();
+ while(!progressMonitorService.isMonitorThreadRunning(uuid)) {}
+ progressMonitorService.cancel(uuid);
+ while(progressMonitorService.isMonitorThreadRunning(uuid)) {}
+ IRemotingProgressMonitor remotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
+ new MockPostMoniteredOperationEnabled(expectedMonitor, uuid).postOperation(remotingMonitor);
+
+ }
+
+ @Test
+ public void testMonitLongRunningMethodWithWaitForFeedback() throws InterruptedException {
+
+ List<String> feedbacks = Arrays.asList("feedback1", "feedback2");
+ List<IFeedbackGenerator> feebackGenerators = new ArrayList<IFeedbackGenerator>();
+ final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
+ expectedMonitor.setResult("Success");
+ for(String feedback : feedbacks) {
+ feebackGenerators.add(new MockFeedbackGenerator(feedback, 0));
+ expectedMonitor.addReport(feedback);
+ }
+ expectedMonitor.addReport("Report");
+ expectedMonitor.done();
+
+ final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 0);
+ final int pollInterval = 1000;
+
+ CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
+ uuid,
+ pollInterval,
+ new MockPostMoniteredOperationEnabled(expectedMonitor, uuid),
+ feebackGenerators,
+ new NullProgressMonitor());
+
+ }
+
+ @Test
+ public void testMonitLongRunningMethodWithInconsistentWaitForFeedback() throws InterruptedException {
+
+ List<String> feedbacks = Arrays.asList("feedback1", "feedback2");
+ List<IFeedbackGenerator> feebackGenerators = new ArrayList<IFeedbackGenerator>();
+ final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
+ expectedMonitor.setResult("Success");
+ for(String feedback : feedbacks) {
+ feebackGenerators.add(new MockFeedbackGenerator(feedback, 0));
+ expectedMonitor.addReport(feedback);
+ }
+ expectedMonitor.addReport("Report");
+ expectedMonitor.done();
+
+ final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 0);
+ final int pollInterval = 1000;
+
+ feebackGenerators.remove(1);
+
+ final UUID newUuid = testService.monitLongRunningMethod(null, feedbacks, 0);
+
+ try {
+ CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
+ newUuid,
+ pollInterval,
+ new MockPostMoniteredOperationEnabled(expectedMonitor, newUuid),
+ feebackGenerators,
+ new NullProgressMonitor());
+ Assert.fail("Exception due to inconsistent number of feedback generators not thrown");
+ } catch(IllegalStateException ise) {
+
+ }
+ }
+
+ @Test
+ public void testMonitLongRunningMethodWithWaitForFeedbackTimeout() throws InterruptedException {
+
+ List<String> feedbacks = Arrays.asList("feedback1");
+ List<IFeedbackGenerator> feebackGenerators = new ArrayList<IFeedbackGenerator>();
+ final RemotingProgressMonitor expectedMonitor = new RemotingProgressMonitor();
+ expectedMonitor.setResult(new IllegalStateException(new InterruptedException()));
+ for(String feedback : feedbacks) {
+ feebackGenerators.add(new MockFeedbackGenerator(feedback, 1000 * 15));
+
+ }
+ expectedMonitor.setCanceled(true);
+ expectedMonitor.setIsFailed(true);
+ expectedMonitor.done();
+
+ expectedMonitor.done();
+
+ final UUID uuid = testService.monitLongRunningMethod(null, feedbacks, 1000 * 5);
+ final int pollInterval = 1000;
+
+
+ try {
+ CdmStore.getProgressMonitorClientManager().pollMonitor("Testing Progress Monitor",
+ uuid,
+ pollInterval,
+ new MockPostMoniteredOperationEnabled(expectedMonitor, uuid),
+ feebackGenerators,
+ new NullProgressMonitor());
+ Assert.fail("Exception due to inconsistent number of feedback generators not thrown");
+ } catch(IllegalStateException ise) {
+
+ }
+ }
+
class MockPostMoniteredOperationEnabled implements IPostMoniteredOperationEnabled {
Assert.assertEquals(expectedMonitor.isDone(), monitor.isDone());
Assert.assertTrue(!progressMonitorService.isMonitorThreadRunning(monitorUuid));
}
+ }
+
+ class MockFeedbackGenerator implements IFeedbackGenerator {
+
+ private String feedback;
+ private long waitTime;
+
+ public MockFeedbackGenerator(String feedback, long waitTime) {
+ this.feedback = feedback;
+ this.waitTime = waitTime;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setFeedbackForMonitor(UUID uuid) {
+ if(waitTime > 0) {
+ try {
+ Thread.sleep(waitTime);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ CdmApplicationState.getCurrentAppConfig().getProgressMonitorService().setFeedback(uuid, feedback);
+ }
}
}