diff options
author | jphillips | 2010-08-02 17:43:24 +0000 |
---|---|---|
committer | jphillips | 2010-08-02 17:43:24 +0000 |
commit | 26a9b4107515ea822b2a16c59f7fcf3eff60ca2e (patch) | |
tree | d9bacc8f91e040d74e24525aa81db15e05e6885d /plugins/org.eclipse.osee.framework.ui.skynet | |
parent | eafa5c02880684169317ae174e551c31dc2e236a (diff) | |
download | org.eclipse.osee-26a9b4107515ea822b2a16c59f7fcf3eff60ca2e.tar.gz org.eclipse.osee-26a9b4107515ea822b2a16c59f7fcf3eff60ca2e.tar.xz org.eclipse.osee-26a9b4107515ea822b2a16c59f7fcf3eff60ca2e.zip |
Split artifactPropmtChange in to GUI and non GUI classes for testing
Diffstat (limited to 'plugins/org.eclipse.osee.framework.ui.skynet')
3 files changed, 94 insertions, 241 deletions
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF index e86ca8f0971..d4e64799493 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.ui.skynet/META-INF/MANIFEST.MF @@ -31,7 +31,8 @@ Require-Bundle: javax.mail.glassfish, org.eclipse.zest.core, org.eclipse.osee.framework.jdk.core, org.eclipse.osee.framework.ui.ws, - org.eclipse.osee.framework.help.ui;bundle-version="0.9.4";resolution:=optional + org.eclipse.osee.framework.help.ui;bundle-version="0.9.4";resolution:=optional, + org.eclipse.osee.framework.access;bundle-version="0.9.5" Bundle-ActivationPolicy: lazy Bundle-Vendor: Eclipse Open System Engineering Environment Import-Package: com.lowagie.text;version="2.1.7", @@ -84,6 +85,7 @@ Export-Package: org.eclipse.osee.framework.ui.skynet, org.eclipse.osee.framework.ui.skynet.artifact.editor.parts, org.eclipse.osee.framework.ui.skynet.artifact.editor.sections, org.eclipse.osee.framework.ui.skynet.artifact.massEditor, + org.eclipse.osee.framework.ui.skynet.artifact.prompt, org.eclipse.osee.framework.ui.skynet.ats, org.eclipse.osee.framework.ui.skynet.blam, org.eclipse.osee.framework.ui.skynet.blam.operation, diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPromptChange.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPromptChange.java index 89dad9f0950..97292f01daf 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPromptChange.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/ArtifactPromptChange.java @@ -12,20 +12,17 @@ package org.eclipse.osee.framework.ui.skynet.artifact;
import java.text.NumberFormat;
-import java.text.ParseException;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.dialogs.MessageDialogWithToggle;
-import org.eclipse.jface.window.Window;
+import org.eclipse.osee.framework.access.AccessControlManager; +import org.eclipse.osee.framework.core.enums.PermissionEnum; import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.exception.OseeExceptions;
+import org.eclipse.osee.framework.core.model.IBasicArtifact; +import org.eclipse.osee.framework.core.model.access.AccessDataQuery; +import org.eclipse.osee.framework.core.model.access.PermissionStatus; +import org.eclipse.osee.framework.core.services.IAccessControlService; import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.skynet.core.UserManager; import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.attribute.AttributeTypeManager;
import org.eclipse.osee.framework.skynet.core.attribute.BooleanAttribute;
@@ -34,256 +31,100 @@ import org.eclipse.osee.framework.skynet.core.attribute.EnumeratedAttribute; import org.eclipse.osee.framework.skynet.core.attribute.FloatingPointAttribute;
import org.eclipse.osee.framework.skynet.core.attribute.IntegerAttribute;
import org.eclipse.osee.framework.skynet.core.attribute.StringAttribute;
-import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.SkynetGuiPlugin;
-import org.eclipse.osee.framework.ui.skynet.artifact.EnumSelectionDialog.Selection;
-import org.eclipse.osee.framework.ui.skynet.widgets.dialog.DateSelectionDialog;
-import org.eclipse.osee.framework.ui.skynet.widgets.dialog.EntryDialog;
-import org.eclipse.osee.framework.ui.swt.Displays;
+import org.eclipse.osee.framework.ui.skynet.artifact.prompt.BooleanHandlePromptChange; +import org.eclipse.osee.framework.ui.skynet.artifact.prompt.DateHandlePromptChange; +import org.eclipse.osee.framework.ui.skynet.artifact.prompt.EnumeratedHandlePromptChange; +import org.eclipse.osee.framework.ui.skynet.artifact.prompt.IHandlePromptChange; +import org.eclipse.osee.framework.ui.skynet.artifact.prompt.StringHandlePromptChange; /**
* @author Donald G. Dunne
*/
-public class ArtifactPromptChange {
+public final class ArtifactPromptChange { - public static boolean promptChangeAttribute(String attributeName, String displayName, final Collection<? extends Artifact> artifacts, boolean persist) {
- try {
- if (AttributeTypeManager.isBaseTypeCompatible(DateAttribute.class, attributeName)) {
- return ArtifactPromptChange.promptChangeDate(attributeName, displayName, artifacts, persist);
- } else if (AttributeTypeManager.isBaseTypeCompatible(FloatingPointAttribute.class, attributeName)) {
- return ArtifactPromptChange.promptChangeFloatAttribute(attributeName, displayName, artifacts, persist);
- } else if (AttributeTypeManager.isBaseTypeCompatible(IntegerAttribute.class, attributeName)) {
- return ArtifactPromptChange.promptChangeIntegerAttribute(attributeName, displayName, artifacts, persist);
- } else if (AttributeTypeManager.isBaseTypeCompatible(BooleanAttribute.class, attributeName)) {
- return ArtifactPromptChange.promptChangeBoolean(attributeName, displayName, artifacts, null, persist);
- } else if (AttributeTypeManager.isBaseTypeCompatible(EnumeratedAttribute.class, attributeName)) {
- return ArtifactPromptChange.promptChangeEnumeratedAttribute(attributeName, displayName, artifacts, persist);
- } else if (AttributeTypeManager.isBaseTypeCompatible(StringAttribute.class, attributeName)) {
- return ArtifactPromptChange.promptChangeStringAttribute(attributeName, displayName, artifacts, persist,
- true);
- } else {
- AWorkbench.popup("ERROR", "Unhandled attribute type. Can't edit through this view");
- }
- } catch (Exception ex) {
- OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
- }
- return false;
- }
-
- public static boolean promptChangeIntegerAttribute(String attributeName, String displayName, final Collection<? extends Artifact> artifacts, boolean persist) throws OseeCoreException {
- return promptChangeStringAttribute(attributeName, displayName, NumberFormat.getIntegerInstance(), artifacts,
- persist, false);
- }
-
- public static boolean promptChangeIntegerAttribute(String attributeName, String displayName, final Artifact artifact, boolean persist) throws OseeCoreException {
- return promptChangeStringAttribute(attributeName, displayName, NumberFormat.getIntegerInstance(),
- Arrays.asList(artifact), persist, false);
- }
-
- public static boolean promptChangePercentAttribute(String attributeName, String displayName, final Artifact artifact, boolean persist) throws OseeCoreException {
- return promptChangeStringAttribute(attributeName, displayName, NumberFormat.getPercentInstance(),
- Arrays.asList(artifact), persist, false);
- }
-
- public static boolean promptChangePercentAttribute(String attributeName, String displayName, final Collection<? extends Artifact> artifacts, boolean persist) throws OseeCoreException {
- return promptChangeStringAttribute(attributeName, displayName, NumberFormat.getPercentInstance(), artifacts,
- persist, false);
- }
-
- public static boolean promptChangeFloatAttribute(String attributeName, String displayName, final Artifact artifact, boolean persist) throws OseeCoreException {
- return promptChangeFloatAttribute(attributeName, displayName, Arrays.asList(artifact), persist);
- }
-
- public static boolean promptChangeFloatAttribute(String attributeName, String displayName, final Collection<? extends Artifact> smas, boolean persist) throws OseeCoreException {
- return promptChangeStringAttribute(attributeName, displayName, NumberFormat.getInstance(), smas, persist, false);
- }
-
- public static boolean promptChangeStringAttribute(String attributeName, String displayName, final Artifact artifact, boolean persist, boolean multiLine) throws OseeCoreException {
- return promptChangeStringAttribute(attributeName, displayName, null, Arrays.asList(artifact), persist, multiLine);
- }
-
- public static boolean promptChangeStringAttribute(String attributeName, String displayName, final Collection<? extends Artifact> smas, boolean persist, boolean multiLine) throws OseeCoreException {
- return promptChangeStringAttribute(attributeName, displayName, null, smas, persist, multiLine);
- }
-
- public static boolean promptChangeDate(String attributeName, String displayName, Artifact artifact, boolean persist) throws OseeCoreException {
- return promptChangeDate(attributeName, displayName, Arrays.asList(artifact), persist);
- }
-
- public static boolean promptChangeDate(String attributeName, String displayName, final Collection<? extends Artifact> artifacts, boolean persist) throws OseeCoreException {
- String diagTitle = "Select " + displayName;
- Date currentDate =
- artifacts.size() == 1 ? artifacts.iterator().next().getSoleAttributeValue(attributeName, null, Date.class) : null;
- DateSelectionDialog diag = new DateSelectionDialog(diagTitle, diagTitle, currentDate);
- if (diag.open() == Window.OK) {
- for (Artifact artifact : artifacts) {
- if (diag.isNoneSelected()) {
- artifact.deleteSoleAttribute(attributeName);
- } else {
- artifact.setSoleAttributeValue(attributeName, diag.getSelectedDate());
- }
- }
-
- if (persist) {
- SkynetTransaction transaction =
- new SkynetTransaction(artifacts.iterator().next().getBranch(), "Persist artifact date change");
- for (Artifact artifact : artifacts) {
- artifact.persist(transaction);
- }
- transaction.execute();
- }
- }
-
- return true;
+ public static boolean promptChangeAttribute(String attributeName, String displayName, final Collection<? extends Artifact> artifacts, boolean persist) throws OseeCoreException { + return promptChangeAttribute(attributeName, displayName, artifacts, persist, true); }
- public static boolean promptChangeEnumeratedAttribute(String attributeName, String displayName, Artifact artifact, boolean persist) throws Exception {
- return promptChangeEnumeratedAttribute(attributeName, displayName, Arrays.asList(artifact), persist);
+ public static boolean promptChangeAttribute(String attributeName, String displayName, final Collection<? extends Artifact> artifacts, boolean persist, boolean multiLine) throws OseeCoreException { + return promptChangeAttribute(UserManager.getUser(), AccessControlManager.getService(), null, attributeName, + displayName, artifacts, persist, multiLine); }
- public static boolean promptChangeEnumeratedAttribute(String attributeName, String displayName, final Collection<? extends Artifact> artifacts, boolean persist) throws Exception {
- String type = artifacts.iterator().next().getArtifactTypeName();
- for (Artifact art : artifacts) {
- if (!type.equals(art.getArtifactTypeName())) {
- AWorkbench.popup("ERROR", "Artifact types must all match to change enumerated type.");
- return false;
- }
- }
- EnumSelectionDialog diag = new EnumSelectionDialog(attributeName, artifacts);
- if (diag.open() == 0) {
- Set<String> selected = new HashSet<String>();
- for (Object obj : diag.getResult()) {
- selected.add((String) obj);
- }
- if (artifacts.size() > 0) {
- SkynetTransaction transaction =
- !persist ? null : new SkynetTransaction(artifacts.iterator().next().getBranch(),
- "Change enumerated attribute");
- for (Artifact artifact : artifacts) {
- List<String> current = artifact.getAttributesToStringList(attributeName);
- if (diag.getSelected() == Selection.AddSelection) {
- current.addAll(selected);
- artifact.setAttributeValues(attributeName, current);
- } else if (diag.getSelected() == Selection.DeleteSelected) {
- current.removeAll(selected);
- artifact.setAttributeValues(attributeName, current);
- } else if (diag.getSelected() == Selection.ReplaceAll) {
- artifact.setAttributeValues(attributeName, selected);
- } else {
- AWorkbench.popup("ERROR", "Unhandled selection type => " + diag.getSelected().name());
- return false;
- }
- if (persist) {
- artifact.persist(transaction);
- }
+ public static boolean promptChangeAttribute(IBasicArtifact<?> userArtifact, IAccessControlService accessControlService, IHandlePromptChange promptChange, String attributeName, String displayName, final Collection<? extends Artifact> artifacts, boolean persist, boolean multiLine) { + boolean toReturn = false; + try { + PermissionStatus permissionStatus = + hasWritePermission(userArtifact, accessControlService, attributeName, artifacts); + toReturn = permissionStatus.matches(); + + if (toReturn) { + //For testing a testPromptChange can be passed + if (promptChange == null) { + promptChange = createHandlePrompt(attributeName, displayName, artifacts, persist, multiLine); }
- if (persist) {
- transaction.execute();
+ if (promptChange != null) { + toReturn = handlePromptChange(promptChange); + } else { + AWorkbench.popup("ERROR", "Unhandled attribute type. Can't edit through this view"); }
+ } else { + AWorkbench.popup("No Permission", permissionStatus.getReason()); }
+ } catch (Exception ex) { + OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex); }
- return true;
- }
-
- private static String formatObject(Object src, NumberFormat format) {
- if (format == null) {
- return String.valueOf(src);
- } else {
- return format.format(src);
- }
- }
-
- private static void setInitialText(Collection<? extends Artifact> smas, EntryDialog ed, NumberFormat format, String attributeName) throws OseeCoreException {
- if (smas.size() == 1) {
- Object smaObj = smas.iterator().next().getSoleAttributeValue(attributeName, "");
- String initialText = smaObj.equals("") ? "" : formatObject(smaObj, format);
- ed.setEntry(initialText);
- } else {
- ed.setEntry("");
+ return toReturn; + }
+
+ private static IHandlePromptChange createHandlePrompt(String attributeName, String displayName, final Collection<? extends Artifact> artifacts, boolean persist, boolean multiLine) throws OseeCoreException, Exception { + IHandlePromptChange promptChange = null; + + if (AttributeTypeManager.isBaseTypeCompatible(DateAttribute.class, attributeName)) { + promptChange = new DateHandlePromptChange(artifacts, attributeName, displayName, persist); + } else if (AttributeTypeManager.isBaseTypeCompatible(FloatingPointAttribute.class, attributeName)) { + promptChange = + new StringHandlePromptChange(attributeName, persist, displayName, artifacts, NumberFormat.getInstance(), + false); + } else if (AttributeTypeManager.isBaseTypeCompatible(IntegerAttribute.class, attributeName)) { + promptChange = + new StringHandlePromptChange(attributeName, persist, displayName, artifacts, + NumberFormat.getIntegerInstance(), false); + } else if (AttributeTypeManager.isBaseTypeCompatible(BooleanAttribute.class, attributeName)) { + promptChange = new BooleanHandlePromptChange(artifacts, attributeName, displayName, persist, null); + } else if (AttributeTypeManager.isBaseTypeCompatible(EnumeratedAttribute.class, attributeName)) { + promptChange = new EnumeratedHandlePromptChange(artifacts, attributeName, displayName, persist); + } else if (AttributeTypeManager.isBaseTypeCompatible(StringAttribute.class, attributeName)) { + promptChange = new StringHandlePromptChange(attributeName, persist, displayName, artifacts, null, multiLine); }
+ return promptChange; }
- public static boolean promptChangeStringAttribute(String attributeName, String displayName, NumberFormat format, final Collection<? extends Artifact> smas, boolean persist, boolean multiLine) throws OseeCoreException {
- EntryDialog ed = new EntryDialog("Enter " + displayName, "Enter " + displayName);
-
- ed.setFillVertically(multiLine);
- setInitialText(smas, ed, format, attributeName);
- ed.setNumberFormat(format);
-
- int result = ed.open();
- if (result == Window.OK) {
- updateSmaAttributes(smas, attributeName, format, ed);
+ private static PermissionStatus hasWritePermission(IBasicArtifact<?> userArtifact, IAccessControlService accessControlService, String attributeName, final Collection<? extends Artifact> artifacts) throws OseeCoreException { + AccessDataQuery query = accessControlService.getAccessData(userArtifact, artifacts); + PermissionStatus permissionStatus = new PermissionStatus(); - if (persist) {
- persistSmaAttributes(smas);
- }
- return true;
- }
- return false;
- }
+ if (artifacts != null) { + for (Artifact artifact : artifacts) { + query.attributeTypeMatches(PermissionEnum.WRITE, artifact, AttributeTypeManager.getType(attributeName), + permissionStatus); - private static String getSafeValue(String value, NumberFormat format) throws OseeCoreException {
- String toReturn = value;
- if (format != null) {
- try {
- toReturn = String.valueOf(format.parse(value).doubleValue()); // TODO check for dot in integers
- } catch (ParseException ex) {
- OseeExceptions.wrapAndThrow(ex);
+ if (!permissionStatus.matches()) { + break; + } }
}
- return toReturn;
+ return permissionStatus; }
- private static void updateSmaAttributes(final Collection<? extends Artifact> smas, String attributeName, NumberFormat format, EntryDialog ed) throws OseeCoreException {
- for (Artifact sma : smas) {
- String value = ed.getEntry();
- String safeValue = getSafeValue(value, format);
- sma.setSoleAttributeFromString(attributeName, safeValue);
- }
- }
-
- private static void persistSmaAttributes(final Collection<? extends Artifact> smas) throws OseeCoreException {
- SkynetTransaction transaction =
- new SkynetTransaction(smas.iterator().next().getBranch(), "Persist SMA attributes");
- for (Artifact sma : smas) {
- sma.persist(transaction);
- }
-
- transaction.execute();
- }
-
- public static boolean promptChangeBoolean(String attributeName, String displayName, final Artifact artifact, String toggleMessage, boolean persist) throws OseeCoreException {
- return promptChangeBoolean(attributeName, displayName, Arrays.asList(artifact), toggleMessage, persist);
- }
+ private static boolean handlePromptChange(IHandlePromptChange promptChange) throws OseeCoreException { + boolean toReturn = false; - public static boolean promptChangeBoolean(String attributeName, String displayName, final Collection<? extends Artifact> smas, String toggleMessage, boolean persist) throws OseeCoreException {
- boolean set = false;
- if (smas.size() == 1) {
- set = smas.iterator().next().getSoleAttributeValue(attributeName, false);
+ if (promptChange.promptOk()) { + toReturn = promptChange.store(); }
- MessageDialogWithToggle md =
- new MessageDialogWithToggle(Displays.getActiveShell(), displayName, null, displayName, MessageDialog.QUESTION,
- new String[] {"Ok", "Cancel"}, Window.OK, toggleMessage != null ? toggleMessage : displayName, set);
-
- int result = md.open();
- if (result == 256) {
- if (smas.size() > 0) {
- SkynetTransaction transaction =
- !persist ? null : new SkynetTransaction(smas.iterator().next().getBranch(), "Prompt change boolean");
- for (Artifact sma : smas) {
- sma.setSoleAttributeValue(attributeName, md.getToggleState());
- if (persist) {
- sma.persist();
- }
- }
- if (persist) {
- transaction.execute();
- }
- }
- return true;
- }
- return false;
+ return toReturn; }
-
}
diff --git a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/massEditor/MassXViewer.java b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/massEditor/MassXViewer.java index f249fe691ff..e4a1bf5119e 100644 --- a/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/massEditor/MassXViewer.java +++ b/plugins/org.eclipse.osee.framework.ui.skynet/src/org/eclipse/osee/framework/ui/skynet/artifact/massEditor/MassXViewer.java @@ -90,9 +90,13 @@ public class MassXViewer extends XViewer implements IMassViewerEventHandler, IFr for (TreeItem item : treeItems) {
useArts.add((Artifact) item.getData());
}
- if (ArtifactPromptChange.promptChangeAttribute(colName, colName, useArts, false)) {
- refresh();
- editor.onDirtied();
+ try { + if (ArtifactPromptChange.promptChangeAttribute(colName, colName, useArts, false)) { + refresh(); + editor.onDirtied(); + } + } catch (OseeCoreException ex) { + OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex); }
}
@@ -111,10 +115,16 @@ public class MassXViewer extends XViewer implements IMassViewerEventHandler, IFr @Override
public boolean handleAltLeftClick(TreeColumn treeColumn, TreeItem treeItem) {
- return handleAltLeftClick(treeColumn, treeItem, false);
+ boolean toReturn = false; + try { + toReturn = handleAltLeftClick(treeColumn, treeItem, false); + } catch (OseeCoreException ex) { + OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex); + } + return toReturn; }
- public boolean handleAltLeftClick(TreeColumn treeColumn, TreeItem treeItem, boolean persist) {
+ public boolean handleAltLeftClick(TreeColumn treeColumn, TreeItem treeItem, boolean persist) throws OseeCoreException { super.handleAltLeftClick(treeColumn, treeItem);
String colName = treeColumn.getText();
if (EXTRA_COLUMNS.contains(colName)) {
|