Skip to content

Commit

Permalink
Changed List->Directory; Descendants->Browse; added save all actions …
Browse files Browse the repository at this point in the history
…under Objects and This. The save all action saves all *related* objects provided by the target object.
  • Loading branch information
NijaShi committed May 25, 2013
1 parent b85ac58 commit 770df79
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 7 deletions.
Expand Up @@ -1157,5 +1157,23 @@ private synchronized void removeComponent(AbstractComponent component) {
*/
public List<PropertyDescriptor> getFieldDescriptors() {
return null;
}
}

/**
* For Save All action. This method should return a set of modified objects
* to be saved. These modified objects are not required to be related to this object.
* The save all action automatically includes saving changes for this object, so this
* method does not need to include this object to be saved.
*
* @return a set of <code>AbstractComponent</code> that have been modified and are ready to be saved
*/
public Set<AbstractComponent> getAllModifiedObjects() {
return Collections.emptySet();
}

/**
* This is a template method, which is called when the save all action was successful.
*/
public void notifiedSaveAllSuccessful() {
}
}
@@ -0,0 +1,82 @@
package gov.nasa.arc.mct.gui.actions;

import gov.nasa.arc.mct.api.persistence.OptimisticLockException;
import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.gui.ActionContext;
import gov.nasa.arc.mct.gui.ContextAwareAction;
import gov.nasa.arc.mct.gui.impl.ActionContextImpl;
import gov.nasa.arc.mct.platform.spi.PlatformAccess;
import gov.nasa.arc.mct.services.internal.component.Updatable;

import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import java.util.Set;

public class ObjectsSaveAllAction extends ContextAwareAction{
private static final long serialVersionUID = 3940626077815919451L;
private static final ResourceBundle BUNDLE =
ResourceBundle.getBundle(
ObjectsSaveAllAction.class.getName().substring(0,
ObjectsSaveAllAction.class.getName().lastIndexOf("."))+".Bundle");
private ActionContextImpl actionContext;

public ObjectsSaveAllAction() {
super(BUNDLE.getString("SaveAllAction.label"));
}

@Override
public boolean canHandle(ActionContext context) {
actionContext = (ActionContextImpl) context;
return actionContext.getInspectorComponent() != null;
}

// private boolean isComponentWriteableByUser(AbstractComponent component) {
// Platform p = PlatformAccess.getPlatform();
// PolicyContext policyContext = new PolicyContext();
// policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), component);
// policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w');
// String inspectionKey = PolicyInfo.CategoryType.OBJECT_INSPECTION_POLICY_CATEGORY.getKey();
// return p.getPolicyManager().execute(inspectionKey, policyContext).getStatus();
// }

private AbstractComponent getInspectorComponent() {
return actionContext.getInspectorComponent();
}

@Override
public boolean isEnabled() {
AbstractComponent ac = getInspectorComponent();
return !ac.isStale() && ac.isDirty() || !ac.getAllModifiedObjects().isEmpty();
}

/**
* This method is invoked when the client side object is stale. This can occur when another client
* even another window in the same application instance has saved the component after it has been loaded.
* This implementation will try again, which will overwrite the previous change; however, this is where
* configuration could be added to display a message instead.
*/
private void handleStaleObject(AbstractComponent ac) {
overwritePreviousChanges(ac);
}

private void overwritePreviousChanges(AbstractComponent ac) {
AbstractComponent updatedComp = PlatformAccess.getPlatform().getPersistenceProvider().getComponentFromStore(ac.getComponentId());
ac.getCapability(Updatable.class).setVersion(updatedComp.getVersion());
actionPerformed(null);
}

@Override
public void actionPerformed(ActionEvent e) {
AbstractComponent ac = getInspectorComponent();
Set<AbstractComponent> allModifiedObjects = ac.getAllModifiedObjects();
if (ac.isDirty())
allModifiedObjects.add(ac);
try {
PlatformAccess.getPlatform().getPersistenceProvider().persist(allModifiedObjects);
} catch (OptimisticLockException ole) {
handleStaleObject(ac);
}
ac.notifiedSaveAllSuccessful();
}

}
@@ -0,0 +1,86 @@
package gov.nasa.arc.mct.gui.actions;

import gov.nasa.arc.mct.api.persistence.OptimisticLockException;
import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.gui.ActionContext;
import gov.nasa.arc.mct.gui.ContextAwareAction;
import gov.nasa.arc.mct.gui.housing.MCTContentArea;
import gov.nasa.arc.mct.gui.housing.MCTHousing;
import gov.nasa.arc.mct.gui.impl.ActionContextImpl;
import gov.nasa.arc.mct.platform.spi.PlatformAccess;
import gov.nasa.arc.mct.services.internal.component.Updatable;

import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import java.util.Set;

public class ThisSaveAllAction extends ContextAwareAction{
private static final long serialVersionUID = 3940626077815919451L;
private static final ResourceBundle BUNDLE =
ResourceBundle.getBundle(
ThisSaveAllAction.class.getName().substring(0,
ThisSaveAllAction.class.getName().lastIndexOf("."))+".Bundle");
private ActionContextImpl actionContext;


public ThisSaveAllAction() {
super(BUNDLE.getString("SaveAllAction.label"));
}

@Override
public boolean canHandle(ActionContext context) {
actionContext = (ActionContextImpl) context;
return getCenterPaneComponent() != null;
}

// private boolean isComponentWriteableByUser(AbstractComponent component) {
// Platform p = PlatformAccess.getPlatform();
// PolicyContext policyContext = new PolicyContext();
// policyContext.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), component);
// policyContext.setProperty(PolicyContext.PropertyName.ACTION.getName(), 'w');
// String inspectionKey = PolicyInfo.CategoryType.OBJECT_INSPECTION_POLICY_CATEGORY.getKey();
// return p.getPolicyManager().execute(inspectionKey, policyContext).getStatus();
// }

private AbstractComponent getCenterPaneComponent() {
MCTHousing housing = actionContext.getTargetHousing();
MCTContentArea contentArea = housing.getContentArea();
return contentArea == null ? null : contentArea.getHousedViewManifestation().getManifestedComponent();
}

@Override
public boolean isEnabled() {
AbstractComponent ac = getCenterPaneComponent();
return !ac.isStale() && ac.isDirty() || !ac.getAllModifiedObjects().isEmpty();
}

/**
* This method is invoked when the client side object is stale. This can occur when another client
* even another window in the same application instance has saved the component after it has been loaded.
* This implementation will try again, which will overwrite the previous change; however, this is where
* configuration could be added to display a message instead.
*/
private void handleStaleObject(AbstractComponent ac) {
overwritePreviousChanges(ac);
}

private void overwritePreviousChanges(AbstractComponent ac) {
AbstractComponent updatedComp = PlatformAccess.getPlatform().getPersistenceProvider().getComponentFromStore(ac.getComponentId());
ac.getCapability(Updatable.class).setVersion(updatedComp.getVersion());
actionPerformed(null);
}

@Override
public void actionPerformed(ActionEvent e) {
AbstractComponent ac = getCenterPaneComponent();
Set<AbstractComponent> allModifiedObjects = ac.getAllModifiedObjects();
if (ac.isDirty())
allModifiedObjects.add(ac);
try {
PlatformAccess.getPlatform().getPersistenceProvider().persist(allModifiedObjects);
} catch (OptimisticLockException ole) {
handleStaleObject(ac);
}
}

}
Expand Up @@ -65,7 +65,8 @@ protected void populate() {
addMenuItemInfos(OBJECTS_OPEN_EXT, Arrays.asList(
new MenuItemInfo("OBJECTS_OPEN", MenuItemType.NORMAL),
new MenuItemInfo(DetectGraphicsDevices.OBJECTS_OPEN_MULTIPLE_MONITORS_MENU, MenuItemType.SUBMENU),
new MenuItemInfo("OBJECTS_SAVE", MenuItemType.NORMAL)
new MenuItemInfo("OBJECTS_SAVE", MenuItemType.NORMAL),
new MenuItemInfo("OBJECTS_SAVE_ALL", MenuItemType.NORMAL)
));


Expand Down
Expand Up @@ -56,6 +56,7 @@ protected void populate() {
new MenuItemInfo("THIS_OPEN_ACTION_ID", MenuItemType.NORMAL),
new MenuItemInfo(DetectGraphicsDevices.THIS_OPEN_MULTIPLE_MONITORS_MENU, MenuItemType.SUBMENU),
new MenuItemInfo("THIS_SAVE_ACTION", MenuItemType.NORMAL),
new MenuItemInfo("THIS_SAVE_ALL_ACTION", MenuItemType.NORMAL),
new MenuItemInfo("VIEW_REVERT_TO_COMMITTED", MenuItemType.NORMAL),
new MenuItemInfo(bundle.getString("ExportThisAsImageCommandKey"), MenuItemType.NORMAL)
));
Expand Down
Expand Up @@ -30,30 +30,32 @@

import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.components.DetectGraphicsDevices;
import gov.nasa.arc.mct.gui.actions.ExportViewAsImageAction;
import gov.nasa.arc.mct.gui.actions.ExportThisAsImageAction;
import gov.nasa.arc.mct.gui.actions.AboutMCT;
import gov.nasa.arc.mct.gui.actions.AboutMCTLicenses;
import gov.nasa.arc.mct.gui.actions.CenterPaneRevertToCommitted;
import gov.nasa.arc.mct.gui.actions.ChangeHousingViewAction;
import gov.nasa.arc.mct.gui.actions.ConveniencesOpenMineGroupAction;
import gov.nasa.arc.mct.gui.actions.ConveniencesOpenUserEnvAction;
import gov.nasa.arc.mct.gui.actions.DeleteObjectAction;
import gov.nasa.arc.mct.gui.actions.DuplicateAction;
import gov.nasa.arc.mct.gui.actions.ExportThisAsImageAction;
import gov.nasa.arc.mct.gui.actions.ExportViewAsImageAction;
import gov.nasa.arc.mct.gui.actions.HelpMCTAction;
import gov.nasa.arc.mct.gui.actions.IconOpenAction;
import gov.nasa.arc.mct.gui.actions.InspectorPaneRevertToCommitted;
import gov.nasa.arc.mct.gui.actions.ListWindowsAction;
import gov.nasa.arc.mct.gui.actions.MemoryMeterAction;
import gov.nasa.arc.mct.gui.actions.ObjectsOpenAction;
import gov.nasa.arc.mct.gui.actions.ObjectsSaveAction;
import gov.nasa.arc.mct.gui.actions.ObjectsSaveAllAction;
import gov.nasa.arc.mct.gui.actions.PlaceObjectsInCollectionAction;
import gov.nasa.arc.mct.gui.actions.CenterPaneRevertToCommitted;
import gov.nasa.arc.mct.gui.actions.RedrawDataAction;
import gov.nasa.arc.mct.gui.actions.RemoveManifestationAction;
import gov.nasa.arc.mct.gui.actions.ResetFeedViewsAction;
import gov.nasa.arc.mct.gui.actions.ShowHideControlArea;
import gov.nasa.arc.mct.gui.actions.ThisOpenAction;
import gov.nasa.arc.mct.gui.actions.ThisSaveAction;
import gov.nasa.arc.mct.gui.actions.ThisSaveAllAction;
import gov.nasa.arc.mct.gui.actions.ViewShowControlAreaAction;
import gov.nasa.arc.mct.gui.actions.WindowsExclusiveCloseAction;
import gov.nasa.arc.mct.gui.formatting.actions.AlignToDecimalAction;
Expand Down Expand Up @@ -83,6 +85,7 @@
import java.util.List;
import java.util.ResourceBundle;


/**
* Create the User Environment.
*
Expand Down Expand Up @@ -119,8 +122,10 @@ private void initUI() {
ActionManager.registerAction(IconOpenAction.class, "ICON_OPEN_ACTION");
ActionManager.registerAction(ObjectsOpenAction.class, "OBJECTS_OPEN");
ActionManager.registerAction(ObjectsSaveAction.class, "OBJECTS_SAVE");
ActionManager.registerAction(ObjectsSaveAllAction.class, "OBJECTS_SAVE_ALL");
ActionManager.registerAction(InspectorPaneRevertToCommitted.class, "OBJECT_REVERT_TO_COMMITTED");
ActionManager.registerAction(ThisSaveAction.class, "THIS_SAVE_ACTION");
ActionManager.registerAction(ThisSaveAllAction.class, "THIS_SAVE_ALL_ACTION");
ActionManager.registerAction(CenterPaneRevertToCommitted.class, "VIEW_REVERT_TO_COMMITTED");
ActionManager.registerAction(ViewShowControlAreaAction.class, "VIEW_CONTROL_AREAS");
ActionManager.registerAction(ChangeHousingViewAction.class, "VIEW_CHANGE_HOUSING");
Expand Down
4 changes: 2 additions & 2 deletions platform/src/main/resources/Platform.properties
Expand Up @@ -29,8 +29,8 @@ LAYOUT_C = Layout:
SHOW = Show
SHOW_ALL = Show All

DIRECTORY = List
BROWSE_CONTROL_TEXT = Descendants
DIRECTORY = Directory
BROWSE_CONTROL_TEXT = Browse
SEARCH_CONTROL_TEXT = Search Name
SEARCH_BUTTON = Search

Expand Down
Expand Up @@ -24,6 +24,7 @@ MemoryMeterAction.label=Memory Usage Monitor

#Save Action
SaveAction.label=Commit
SaveAllAction.label=Save All

#Remove Manifestation
RemoveManifestation = Remove Manifestation
Expand Down

0 comments on commit 770df79

Please sign in to comment.