*/
package eu.etaxonomy.taxeditor.ui.selection;
+import java.util.EnumSet;
+import java.util.Observable;
+import java.util.Observer;
+
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.ISources;
import org.springframework.security.core.GrantedAuthority;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.Group;
import eu.etaxonomy.cdm.model.common.ICdmBase;
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionClass;
import eu.etaxonomy.taxeditor.model.ImageResources;
import eu.etaxonomy.taxeditor.preference.Resources;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.LoginManager;
import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
* @param <T>
*/
public class EntitySelectionElement<T extends ICdmBase> extends
- AbstractCdmFormElement implements SelectionListener, IEnableableFormElement, ISelectableElement, IEntityElement<T>, ILabeledElement, IConversationEnabled {
+ AbstractCdmFormElement implements SelectionListener, IEnableableFormElement, ISelectableElement, IEntityElement<T>, ILabeledElement, IConversationEnabled, Observer {
+ private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE);
+ private static final EnumSet<CRUD> DELETE = EnumSet.of(CRUD.DELETE);
+ private static final EnumSet<CRUD> CREATE = EnumSet.of(CRUD.CREATE);
+
/**
* Bitmask for configuring functionality of selection element
*/
protected T entity;
protected Label label;
- protected Label text;
+ protected Text text;
protected Button button_selection;
private SelectionArbitrator selectionArbitrator;
addControl(selectableComposite);
- text = formFactory.createLabel(selectableComposite, null, SWT.WRAP);
+ text = formFactory.createText(selectableComposite, null, SWT.WRAP);
+ text.setEditable(false);
addControl(text);
text.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
public void setEnabled(boolean enabled) {
button_selection.setEnabled(enabled);
if (isEditable) {
- button_edit.setEnabled(enabled && entity != null);
+ updateButtonStates();
}
}
title = title.replace("&", "&&");
text.setText(title); // title can be null
if (isEditable) {
- button_edit.setEnabled(entity != null);
+ updateButtonStates();
}
}
@Override
public void update(CdmDataChangeMap changeEvents) {
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement#removeElements()
+ */
+ @Override
+ public void removeElements(){
+ super.removeElements();
+ LoginManager loginManager = CdmStore.getLoginManager();
+ loginManager.addObserver(this);
+ }
+
+ @Override
+ public void update(Observable o, Object arg) {
+ if(o instanceof LoginManager){
+ updateButtonStates();
+ }
+ }
+
+ private void updateButtonStates() {
+ button_edit.setEnabled(isEditable && button_selection.isEnabled() && getEntity() != null && CdmStore.currentAuthentiationHasPermission((CdmBase) getEntity(), UPDATE));
+ }
}