Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Icons] Merge in latest from nasa/master

  • Loading branch information...
commit 211691bd88352fb13781b9beaf1d35f502b0b17b 2 parents 0103b60 + e9d24e0
@VWoeltjen VWoeltjen authored
Showing with 449 additions and 63 deletions.
  1. +14 −2 databasePersistence/src/main/java/gov/nasa/arc/mct/dbpersistence/service/PersistenceServiceImpl.java
  2. +108 −0 mctcore/src/main/java/gov/nasa/arc/mct/gui/ContextAwareButton.java
  3. +9 −21 mctcore/src/main/java/gov/nasa/arc/mct/gui/SettingsButton.java
  4. +11 −3 mctcore/src/main/java/gov/nasa/arc/mct/platform/spi/RoleAccess.java
  5. +126 −0 mctcore/src/test/java/gov/nasa/arc/mct/gui/TestContextAwareButton.java
  6. +30 −8 mctcore/src/test/java/gov/nasa/arc/mct/platform/spi/RoleAccessTest.java
  7. +3 −0  platform-assembly/src/main/resources/properties/mysql.properties
  8. +6 −0 platform-assembly/src/main/resources/properties/persistence.properties
  9. +4 −4 platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java
  10. +44 −13 platform/src/main/java/gov/nasa/arc/mct/gui/actions/RefreshAction.java
  11. +24 −3 platform/src/main/java/gov/nasa/arc/mct/gui/housing/Inspector.java
  12. +28 −4 platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTContentArea.java
  13. BIN  platform/src/main/resources/icons/mct_icon_refresh.png
  14. +16 −3 platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestInfoView.java
  15. +26 −2 platform/src/test/java/gov/nasa/arc/mct/gui/actions/TestRefresh.java
View
16 databasePersistence/src/main/java/gov/nasa/arc/mct/dbpersistence/service/PersistenceServiceImpl.java
@@ -131,9 +131,21 @@ public void setEntityManagerProperties(Properties p) {
}
public void activate(ComponentContext context) throws IOException {
- setEntityManagerProperties(getPersistenceProperties());
+ Properties persistenceProperties = getPersistenceProperties();
+ setEntityManagerProperties(persistenceProperties);
new InternalDBPersistenceAccess().setPersistenceService(this);
checkDatabaseVersion();
+
+ // Check for configuration of the polling interval (default is 3s)
+ long pollingInterval = 3000;
+ try {
+ String intervalString = persistenceProperties.getProperty("mct.database_pollInterval");
+ if (intervalString != null) {
+ pollingInterval = Long.parseLong(intervalString);
+ }
+ } catch (NumberFormatException nfe) {
+ // Stick with the default
+ }
Timer databasePollingTimer = new Timer();
databasePollingTimer.schedule(new TimerTask() {
@@ -143,7 +155,7 @@ public void run() {
InternalDBPersistenceAccess.getService().updateComponentsFromDatabase();
}
- }, Calendar.getInstance().getTime(), 3000);
+ }, Calendar.getInstance().getTime(), pollingInterval);
}
View
108 mctcore/src/main/java/gov/nasa/arc/mct/gui/ContextAwareButton.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Mission Control Technologies, Copyright (c) 2009-2012, United States Government
+ * as represented by the Administrator of the National Aeronautics and Space
+ * Administration. All rights reserved.
+ *
+ * The MCT platform is licensed under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ *
+ * MCT includes source code licensed under additional open source licenses. See
+ * the MCT Open Source Licenses file included with this distribution or the About
+ * MCT Licenses dialog available at runtime from the MCT Help menu for additional
+ * information.
+ *******************************************************************************/
+package gov.nasa.arc.mct.gui;
+
+import gov.nasa.arc.mct.util.MCTIcons;
+
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+
+/**
+ * A button containing a context aware action.
+ * Sets its enabled/disabled state in response to context
+ * changes. Must be notified of these context changes explicitly.
+ *
+ * @author vwoeltje
+ *
+ */
+public class ContextAwareButton extends JButton {
+ private static final long serialVersionUID = -2380576132488962171L;
+
+ /**
+ * Create a new button for the specified action.
+ * @param action the action to perform when the button is clicked
+ */
+ public ContextAwareButton(ContextAwareAction action) {
+ this(action, null);
+ }
+
+ /**
+ * Create a new button for the specified action.
+ * Provide an initial context, used to determine
+ * visible/enabled states (and typically to also
+ * inform the actual behavior of the button.)
+ *
+ * @param action the action to perform when the button is clicked
+ * @param context the context for this action
+ */
+ public ContextAwareButton(ContextAwareAction action, ActionContext context) {
+ super(action);
+ setContext(context);
+ }
+
+ @Override
+ public void setIcon(Icon icon) {
+ if (icon != null && icon instanceof ImageIcon) {
+ super.setIcon(MCTIcons.processIcon((ImageIcon) icon, .9f, .9f, .9f, true));
+ super.setPressedIcon(MCTIcons.processIcon((ImageIcon) icon, 1f, 1f, 1f, true));
+ } else {
+ super.setIcon(icon);
+ }
+ }
+
+ @Override
+ public void setText(String text) {
+ // If text is not the action name, make a tool tip
+ Object name = getAction().getValue(Action.NAME);
+ if (name != null && !name.equals(text)) {
+ this.setToolTipText(name.toString());
+ }
+ super.setText(text);
+ }
+
+ /**
+ * Set the context for the current action.
+ * Button will enable/disable based on the action's
+ * state with regard to the current context.
+ *
+ * This method should be called whenever the action's
+ * context may have meaningfully changed. Otherwise,
+ * the action performed by the button may be outdated.
+ *
+ * @param context the context for this action
+ */
+ public void setContext(ActionContext context) {
+ if (context != null) {
+ Action a = getAction();
+ if (a instanceof ContextAwareAction) {
+ ContextAwareAction action = (ContextAwareAction) a;
+ setVisible(action.canHandle(context));
+ setEnabled(action.isEnabled());
+ }
+ } else {
+ setVisible(false);
+ setEnabled(false);
+ }
+ }
+}
View
30 mctcore/src/main/java/gov/nasa/arc/mct/gui/SettingsButton.java
@@ -24,7 +24,6 @@
import gov.nasa.arc.mct.util.MCTIcons;
import java.awt.Color;
-import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
@@ -47,34 +46,18 @@
private static final Icon CONFIG_DESELECTED =
MCTIcons.processIcon(
new ImageIcon(SettingsButton.class.getResource("/icons/mct_icon_config.png")),
- 0.9f, 0.9f, 0.9f, false);
+ 0.9f, 0.9f, 0.9f, true);
private static final Icon CONFIG_SELECTED =
MCTIcons.processIcon(
new ImageIcon(SettingsButton.class.getResource("/icons/mct_icon_config.png")),
- 1f, 1f, 1f, false);
- private static final Icon CONFIG_DISABLED = new Icon() {
- @Override
- public void paintIcon(Component c, Graphics g, int x, int y) {
- // Do not paint when disabled
- }
-
- @Override
- public int getIconWidth() {
- return CONFIG_SELECTED.getIconWidth();
- }
-
- @Override
- public int getIconHeight() {
- return CONFIG_SELECTED.getIconHeight();
- }
- };
+ 1f, 1f, 1f, true);
private static final Color SELECTED_BACKGROUND = new Color(193, 193, 193);
private static final Color SELECTED_BORDER = new Color(138, 138, 138);
private static final Color FOCUS_BORDER = new Color(138, 138, 200);
private static final Dimension PREFERRED_SIZE =
- new Dimension(19, 17);
+ new Dimension(17, 17);
/**
* Create a new configuration button.
@@ -86,12 +69,17 @@ public SettingsButton() {
setBorder(BorderFactory.createEmptyBorder());
setOpaque(false);
setIcon(CONFIG_DESELECTED);
- setDisabledIcon(CONFIG_DISABLED);
setSelectedIcon(CONFIG_SELECTED);
setSelected(false);
}
@Override
+ public void setEnabled(boolean enabled) {
+ setVisible(enabled);
+ super.setEnabled(enabled);
+ }
+
+ @Override
public void paintComponent(Graphics g) {
if (isSelected()) {
g.setColor(SELECTED_BACKGROUND);
View
14 mctcore/src/main/java/gov/nasa/arc/mct/platform/spi/RoleAccess.java
@@ -67,10 +67,18 @@ public static boolean hasRole(User user, String role) {
* @param runtimeUser the user
* @return true if this components owner can be changed.
*/
- public static boolean canChangeOwner(AbstractComponent component, User runtimeUser) {
-
+ public static boolean canChangeOwner(AbstractComponent component, User runtimeUser) {
+ // TODO: Consider moving this to Policy?
+ // First, rule out bootstrap components - changing ownership of these could result in major loss of functionality
+ for (AbstractComponent bootstrap : PlatformAccess.getPlatform().getBootstrapComponents()) {
+ if (bootstrap.getComponentId().equals(component.getComponentId())) {
+ return false;
+ }
+ }
+
+ // Otherwise, consider ownership and role rules
String componentOwner = component.getOriginalOwner() == null ? component.getOwner() : component.getOriginalOwner();
- if (componentOwner.equals(runtimeUser.getUserId()) || "admin".equals(runtimeUser.getUserId())) {
+ if (componentOwner.equals(runtimeUser.getUserId()) || "admin".equals(runtimeUser.getUserId())) {
return true;
} else {
return RoleAccess.hasRole(runtimeUser, componentOwner);
View
126 mctcore/src/test/java/gov/nasa/arc/mct/gui/TestContextAwareButton.java
@@ -0,0 +1,126 @@
+package gov.nasa.arc.mct.gui;
+
+import java.awt.image.BufferedImage;
+
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+public class TestContextAwareButton {
+
+ private static final String ACTION_NAME = "Mock";
+
+ @Mock private ContextAwareAction action;
+ @Mock private ActionContext context;
+
+ @BeforeMethod
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.when(action.getValue(Action.NAME)).thenReturn(ACTION_NAME);
+ }
+
+ @Test
+ public void testNoContext() {
+ // Button should not be visible if no context has been provided
+ ContextAwareButton button = new ContextAwareButton(action);
+ Assert.assertFalse(button.isEnabled());
+ Assert.assertFalse(button.isVisible());
+
+ // Should behave similarly if context is explicitly null
+ button = new ContextAwareButton(action, null);
+ Assert.assertFalse(button.isEnabled());
+ Assert.assertFalse(button.isVisible());
+ }
+
+ @Test
+ public void testContext() {
+ // Should invoke canHandle for the specified context
+ new ContextAwareButton(action, context);
+ Mockito.verify(action).canHandle(context);
+ Mockito.verify(action, Mockito.atLeastOnce()).isEnabled();
+ }
+
+ @Test
+ public void testSetContext() {
+ // Should invoke canHandle for the specified context
+ new ContextAwareButton(action).setContext(context);
+ Mockito.verify(action).canHandle(context);
+ Mockito.verify(action, Mockito.atLeastOnce()).isEnabled();
+ }
+
+ @Test (dataProvider="generateStates")
+ public void testState(boolean canHandle, boolean isEnabled, boolean useConstructor) {
+ // Set up states
+ Mockito.when(action.canHandle(context)).thenReturn(canHandle);
+ Mockito.when(action.isEnabled()).thenReturn(isEnabled);
+
+ // Make the button
+ ContextAwareButton button = useConstructor ?
+ new ContextAwareButton(action, context) :
+ new ContextAwareButton(action);
+ if (!useConstructor) {
+ button.setContext(context);
+ }
+
+ // Verify visibility/enabled states match what the action reports
+ Assert.assertEquals(button.isVisible(), canHandle);
+ Assert.assertEquals(button.isEnabled(), isEnabled);
+ }
+
+ @Test
+ public void testToolTip() {
+ // Tool tip should show action name if text set to something else
+ ContextAwareButton button = new ContextAwareButton(action);
+
+ // Should not have a tool tip by default
+ Assert.assertTrue(button.getToolTipText() == null || button.getToolTipText().isEmpty());
+
+ // Setting text to same action name should not change tool tip
+ button.setText(ACTION_NAME);
+ Assert.assertTrue(button.getToolTipText() == null || button.getToolTipText().isEmpty());
+
+ // Setting text to some other name should change tool tip
+ button.setText("Something else");
+ Assert.assertEquals(button.getToolTipText(), ACTION_NAME);
+ }
+
+ @Test
+ public void testSetIcon() {
+ // Should not have an icon by default
+ Assert.assertNull(new ContextAwareButton(action).getIcon());
+
+ // Should customize (change) icon if it can (only for ImageIcons)
+ Icon icon = new ImageIcon(new BufferedImage(12,12,BufferedImage.TYPE_INT_ARGB));
+ Mockito.when(action.getValue(Action.SMALL_ICON)).thenReturn(icon);
+ Mockito.when(action.getValue(Action.LARGE_ICON_KEY)).thenReturn(icon);
+ Assert.assertNotNull(new ContextAwareButton(action).getIcon());
+ Assert.assertNotSame(new ContextAwareButton(action).getIcon(), icon);
+
+ // Should use (but not customize) regular icon
+ icon = Mockito.mock(Icon.class);
+ Mockito.when(action.getValue(Action.SMALL_ICON)).thenReturn(icon);
+ Mockito.when(action.getValue(Action.LARGE_ICON_KEY)).thenReturn(icon);
+ Assert.assertEquals(new ContextAwareButton(action).getIcon(), icon);
+ }
+
+ @DataProvider
+ public Object[][] generateStates() {
+ Object[][] result = new Object[8][];
+ for (int i = 0; i < result.length; i++) {
+ result[i] = new Object[]{
+ (i & 1) != 0, // canHandle
+ (i & 2) != 0, // isEnabled
+ (i & 4) != 0 // useConstructor
+ };
+ }
+ return result;
+ }
+}
View
38 mctcore/src/test/java/gov/nasa/arc/mct/platform/spi/RoleAccessTest.java
@@ -25,44 +25,66 @@
import gov.nasa.arc.mct.services.internal.component.ComponentInitializer;
import gov.nasa.arc.mct.services.internal.component.User;
+import java.util.Arrays;
+
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
-import org.testng.annotations.BeforeTest;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class RoleAccessTest {
@Mock private User testUser;
+ @Mock private Platform mockPlatform;
+ @Mock private AbstractComponent mockBootstrap;
private AbstractComponent component;
- @BeforeTest
+ private Platform oldPlatform;
+
+ @BeforeMethod
void setup() {
MockitoAnnotations.initMocks(this);
component = new AbstractComponent() {
};
+ oldPlatform = PlatformAccess.getPlatform();
+ new PlatformAccess().setPlatform(mockPlatform);
+ Mockito.when(mockBootstrap.getComponentId()).thenReturn("boot");
+ Mockito.when(mockPlatform.getBootstrapComponents()).thenReturn(Arrays.asList(mockBootstrap));
+ }
+
+ @AfterMethod
+ void teardown() {
+ new PlatformAccess().setPlatform(oldPlatform);
}
@DataProvider(name="userAndComponentSetup")
Object[][] userTests() {
return new Object[][] {
- new Object[] {"admin", "xyz", true},
- new Object[] {"xyz", "xyz", true},
- new Object[] {"qqq", "xyz", false}
+ new Object[] {"admin", "xyz", "...", true},
+ new Object[] {"xyz", "xyz", "...", true},
+ new Object[] {"qqq", "xyz", "...", false},
+ // The following should be identified as bootstrap components,
+ // and ownership changed should be disallowed.
+ new Object[] {"admin", "xyz", "boot", false},
+ new Object[] {"xyz", "xyz", "boot", false},
+ new Object[] {"qqq", "xyz", "boot", false}
};
}
- void setupUserAndComponent(String user, String originalOwner) {
+ void setupUserAndComponent(String user, String originalOwner, String id) {
Mockito.when(testUser.getUserId()).thenReturn(user);
ComponentInitializer ci = component.getCapability(ComponentInitializer.class);
ci.setOwner(originalOwner);
+ ci.setId(id);
}
@Test(dataProvider="userAndComponentSetup")
- public void testCanChangeOwner(String userName, String originalOwner, boolean expectedValue) {
- setupUserAndComponent(userName, originalOwner);
+ public void testCanChangeOwner(String userName, String originalOwner, String id, boolean expectedValue) {
+ setupUserAndComponent(userName, originalOwner, id);
component.setOwner(userName);
Assert.assertEquals(RoleAccess.canChangeOwner(component, testUser), expectedValue);
}
View
3  platform-assembly/src/main/resources/properties/mysql.properties
@@ -45,6 +45,9 @@ mct.database_userName=root
# script.
mct.database_password=root
+# Configure the polling interval for retrieving new component versions from
+# the database. This value is in milliseconds.
+mct.database_pollInterval=500
# The properties below this line are passed directly into the JPA persistence manager
hibernate.show_sql=false
View
6 platform-assembly/src/main/resources/properties/persistence.properties
@@ -26,6 +26,12 @@
javax.persistence.jdbc.url=jdbc:derby:testdb;create=true
hibernate.hbm2ddl.auto=update
+# Configure the polling interval for retrieving new component versions from
+# the database. This value is in milliseconds.
+# Using a low value with Derby should not pose problems, as there will not
+# be multi-user load on the database.
+mct.database_pollInterval=250
+
# The properties below this line are passed directly into the JPA persistence manager
hibernate.show_sql=false
hibernate.format_sql=true
View
8 platform/src/main/java/gov/nasa/arc/mct/defaults/view/SwitcherView.java
@@ -87,7 +87,6 @@ public SwitcherView(AbstractComponent ac, ViewInfo vi) {
comboBox.setVisible(false);
comboBox.setEnabled(false);
comboBox.setOpaque(false);
- comboBox.setFont(comboBox.getFont().deriveFont(FONT_SIZE));
add(comboBox);
} else if (viewInfos.length == 1) {
// Otherwise, just show the one available view as a label
@@ -99,6 +98,7 @@ public SwitcherView(AbstractComponent ac, ViewInfo vi) {
// No views to show
}
+ setBorder(BorderFactory.createEmptyBorder(1,4,1,2));
setOpaque(false);
}
@@ -207,7 +207,7 @@ public void paint(Graphics g, JComponent c) {
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
g.setColor(c.getBackground());
- g.fillRoundRect(0, 1, c.getWidth()-2, c.getHeight()-2, 10, 10);
+ g.fillRoundRect(0, 1, c.getWidth()-1, c.getHeight()-2, 10, 10);
super.paint(g, c);
}
@@ -227,8 +227,8 @@ public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean ha
private static final Icon ARROW_ICON = new Icon() {
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
- int tx[] = { 2, 10, 6 };
- int ty[] = { 7, 7, 11 };
+ int tx[] = { 3, 11, 7 };
+ int ty[] = { 6, 6, 10 };
if (g instanceof Graphics2D) {
((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
View
57 platform/src/main/java/gov/nasa/arc/mct/gui/actions/RefreshAction.java
@@ -21,12 +21,12 @@
*******************************************************************************/
package gov.nasa.arc.mct.gui.actions;
+import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.defaults.view.MCTHousingViewManifestation;
import gov.nasa.arc.mct.gui.ActionContext;
import gov.nasa.arc.mct.gui.ContextAwareAction;
import gov.nasa.arc.mct.gui.OptionBox;
import gov.nasa.arc.mct.gui.View;
-import gov.nasa.arc.mct.gui.housing.MCTContentArea;
import gov.nasa.arc.mct.gui.impl.WindowManagerImpl;
import gov.nasa.arc.mct.platform.spi.PlatformAccess;
import gov.nasa.arc.mct.services.component.ViewInfo;
@@ -36,6 +36,10 @@
import java.util.Map;
import java.util.ResourceBundle;
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
/**
* The "Refresh Now" menu option. Causes the view in the
* center pane to be re-created with the latest version
@@ -50,23 +54,38 @@
ResourceBundle.getBundle(
ThisSaveAllAction.class.getName().substring(0,
ThisSaveAllAction.class.getName().lastIndexOf("."))+".Bundle"); //NOI18N
-
+ private static final Icon ICON =
+ new ImageIcon(RefreshAction.class.getResource("/icons/mct_icon_refresh.png"));
+
+
+ private boolean isHousing;
private MCTHousingViewManifestation housing;
+ private View view;
/**
* Create the refresh action.
*/
public RefreshAction() {
super(BUNDLE.getString("RefreshAction.label")); //NOI18N
+ this.putValue(Action.LARGE_ICON_KEY, ICON);
}
@Override
public boolean canHandle(ActionContext context) {
- // Store reference to housing for "actionPerformed"
- this.housing = (MCTHousingViewManifestation) context.getWindowManifestation();
+ // Get the view container whose contents will be refreshed.
+ this.view = context.getWindowManifestation();
+ isHousing = view != null && view instanceof MCTHousingViewManifestation;
- // Only valid if we have a center pane
- return housing != null && housing.getContentArea() != null;
+ if (isHousing) {
+ // Store reference to housing for "actionPerformed"
+ this.housing = (MCTHousingViewManifestation) context.getWindowManifestation();
+
+ // Only valid if we have a center pane
+ return housing != null && housing.getContentArea() != null;
+ } else {
+ // Otherwise, we're dealing with some view directly
+ return view != null && view.getHousedViewManifestation() != null;
+ }
}
@Override
@@ -79,11 +98,12 @@ public boolean isEnabled() {
@Override
public void actionPerformed(ActionEvent e) {
- MCTContentArea contentArea = housing.getContentArea();
+ View housedView = isHousing ?
+ housing.getContentArea().getHousedViewManifestation() :
+ view.getHousedViewManifestation();
// Should not be null per canHandle, but check for safety
- if (contentArea != null) {
- View housedView = contentArea.getHousedViewManifestation();
+ if (housedView != null) {
boolean doRefresh = true;
// Give the user an opportunity to cancel the refresh if it would
@@ -105,12 +125,23 @@ public void actionPerformed(ActionEvent e) {
hints);
doRefresh = input.equals(ok);
}
-
+
// Perform the refresh by re-creating view
if (doRefresh) {
- ViewInfo vi = contentArea.getHousedViewManifestation().getInfo();
- View newView = vi.createView(housing.getManifestedComponent());
- contentArea.setOwnerComponentCanvasManifestation(newView);
+ // Update component from persistence
+ AbstractComponent comp = housedView.getManifestedComponent();
+ comp = PlatformAccess.getPlatform().getPersistenceProvider().getComponent(comp.getComponentId());
+ housedView.setManifestedComponent(comp);
+
+ // Re-create view
+ ViewInfo vi = housedView.getInfo();
+ if (isHousing) {
+ View newView = vi.createView(comp);
+ housing.getContentArea().setOwnerComponentCanvasManifestation(newView);
+ } else {
+ housedView.setManifestedComponent(comp);
+ view.setHousedViewManifestation(vi);
+ }
}
}
}
View
27 platform/src/main/java/gov/nasa/arc/mct/gui/housing/Inspector.java
@@ -23,11 +23,15 @@
import gov.nasa.arc.mct.components.AbstractComponent;
import gov.nasa.arc.mct.defaults.view.SwitcherView;
+import gov.nasa.arc.mct.gui.ActionContext;
+import gov.nasa.arc.mct.gui.ContextAwareButton;
import gov.nasa.arc.mct.gui.OptionBox;
import gov.nasa.arc.mct.gui.SelectionProvider;
import gov.nasa.arc.mct.gui.SettingsButton;
import gov.nasa.arc.mct.gui.View;
import gov.nasa.arc.mct.gui.ViewRoleSelection;
+import gov.nasa.arc.mct.gui.actions.RefreshAction;
+import gov.nasa.arc.mct.gui.impl.ActionContextImpl;
import gov.nasa.arc.mct.gui.impl.WindowManagerImpl;
import gov.nasa.arc.mct.platform.spi.Platform;
import gov.nasa.arc.mct.platform.spi.PlatformAccess;
@@ -78,7 +82,7 @@
private static final Color BACKGROUND_COLOR = LafColor.WINDOW_BORDER.darker();
private static final Color FOREGROUND_COLOR = LafColor.WINDOW.brighter();
-
+
private static final ResourceBundle BUNDLE =
ResourceBundle.getBundle(
Inspector.class.getName().substring(0,
@@ -138,6 +142,7 @@ public void propertyChange(PropertyChangeEvent evt) {
private JPanel statusbar = new JPanel();
private GridBagConstraints c = new GridBagConstraints();
private JToggleButton controlAreaToggle = new SettingsButton();
+ private ContextAwareButton refreshButton = new ContextAwareButton(new RefreshAction());
public Inspector(AbstractComponent ac, ViewInfo vi) {
super(ac,vi);
@@ -185,12 +190,24 @@ public void actionPerformed(ActionEvent e) {
STALE_LABEL.setForeground(Color.red);
content = emptyPanel;
setMinimumSize(new Dimension(0, 0));
+
+ refreshButton.setContentAreaFilled(false);
+ refreshButton.setText("");
+ refreshButton.setBorder(null);
+ refreshButton.setContext(context);
}
public AbstractComponent getCurrentlyShowingComponent() {
return view.getManifestedComponent();
}
+ private ActionContext context = new ActionContextImpl() {
+ @Override
+ public View getWindowManifestation() {
+ return Inspector.this;
+ }
+ };
+
/**
* Prompt the user to commit or abort pending changes,
* if there are any. Note that this may not be possible
@@ -283,6 +300,8 @@ private void refreshInspector(ViewInfo viewInfo) {
STALE_LABEL.setVisible(false);
populateStatusBar();
+ refreshButton.setContext(context);
+
view.requestFocusInWindow();
}
@@ -329,6 +348,7 @@ private void selectedManifestationChanged(View view) {
switcher.addMonitoredGUI(this);
switcher.setForeground(FOREGROUND_COLOR);
p.setOpaque(false);
+ p.add(refreshButton, BorderLayout.WEST);
p.add(switcher, BorderLayout.CENTER);
p.add(controlAreaToggle, BorderLayout.EAST);
titlebar.add(p, c);
@@ -346,6 +366,9 @@ private void selectedManifestationChanged(View view) {
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
content = inspectorScrollPane;
add(inspectorScrollPane, BorderLayout.CENTER);
+
+ refreshButton.setContext(context);
+
revalidate();
}
@@ -424,8 +447,6 @@ public void exitLockedState() {
view.exitLockedState();
}
-
-
@Override
public boolean setHousedViewManifestation(ViewInfo viewInfo) {
AbstractComponent ac = view.getManifestedComponent();
View
32 platform/src/main/java/gov/nasa/arc/mct/gui/housing/MCTContentArea.java
@@ -29,11 +29,14 @@
package gov.nasa.arc.mct.gui.housing;
import gov.nasa.arc.mct.components.AbstractComponent;
+import gov.nasa.arc.mct.gui.ActionContext;
import gov.nasa.arc.mct.gui.CompositeViewManifestationProvider;
+import gov.nasa.arc.mct.gui.ContextAwareButton;
import gov.nasa.arc.mct.gui.SelectionProvider;
import gov.nasa.arc.mct.gui.SettingsButton;
import gov.nasa.arc.mct.gui.View;
import gov.nasa.arc.mct.gui.ViewProvider;
+import gov.nasa.arc.mct.gui.actions.RefreshAction;
import gov.nasa.arc.mct.gui.housing.MCTHousing.ControlProvider;
import gov.nasa.arc.mct.gui.impl.ActionContextImpl;
import gov.nasa.arc.mct.gui.menu.MenuFactory;
@@ -59,6 +62,7 @@
import java.util.Map;
import java.util.ResourceBundle;
+import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
@@ -79,7 +83,8 @@
@SuppressWarnings("serial")
public class MCTContentArea extends JPanel implements CompositeViewManifestationProvider, SelectionProvider, ControlProvider {
- public static final String CENTER_PANE_VIEW_CHANGE = "center-pane-view-change";
+ public static final String CENTER_PANE_VIEW_CHANGE = "center-pane-view-change";
+
private MCTHousing parentHousing;
private final AbstractComponent ownerComponent;
private CanvasTitleArea titleBar;
@@ -93,6 +98,8 @@
private final Map<ViewInfo, ViewProvider> housedManifestations = new HashMap<ViewInfo, ViewProvider>();
+ private ContextAwareButton refreshButton = new ContextAwareButton(new RefreshAction());
+
private static final ResourceBundle BUNDLE =
ResourceBundle.getBundle(
MCTStandardHousing.class.getName().substring(0,
@@ -129,6 +136,12 @@ public MCTContentArea(MCTHousing parentHousing, AbstractComponent ownerComponent
setOwnerComponentCanvasManifestation(ownerComponentCanvasManifestation);
this.revalidate();
this.parentHousing.setContentArea(this);
+
+ refreshButton.setContentAreaFilled(false);
+ refreshButton.setText("");
+ refreshButton.setBorder(BorderFactory.createEmptyBorder());
+ refreshButton.setContext(context);
+
STALE_LABEL.setForeground(Color.red);
}
@@ -217,7 +230,8 @@ public JComponent getContentAreaPane() {
}
public void setParentHousing(MCTHousing parentHousing) {
- this.parentHousing = parentHousing;
+ this.parentHousing = parentHousing;
+ this.refreshButton.setContext(context);
}
/**
@@ -288,6 +302,7 @@ public void setOwnerComponentCanvasManifestation(View viewManifestation) {
add(scrollPane);
}
+ this.refreshButton.setContext(context);
revalidate();
}
@@ -359,7 +374,7 @@ private boolean containsMCTViewManifestation(Container parent) {
void clearHousedManifestations() {
housedManifestations.clear();
- }
+ }
private class CanvasTitleArea extends JPanel {
private final Color BACKGROUND_COLOR = LafColor.WINDOW_BORDER.darker();
@@ -401,6 +416,7 @@ public void actionPerformed(ActionEvent e) {
// Only enable control toggle if control manifestation not null.
controlToggle.setEnabled(controlManifestation != null);
add(Box.createHorizontalGlue());
+ add(refreshButton);
add(controlToggle);
// Add popup listener to title bar.
@@ -466,6 +482,14 @@ public boolean setHousedViewManifestation(ViewInfo viewInfo) {
setOwnerComponentCanvasManifestation(newView);
return true;
}
-
+
+ // Used to provide a context for buttons
+ private ActionContext context = new ActionContextImpl() {
+ @Override
+ public View getWindowManifestation() {
+ return parentHousing.getHousedViewManifestation();
+ }
+ };
+
}
View
BIN  platform/src/main/resources/icons/mct_icon_refresh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
19 platform/src/test/java/gov/nasa/arc/mct/defaults/view/TestInfoView.java
@@ -5,6 +5,8 @@
import gov.nasa.arc.mct.components.PropertyDescriptor.VisualControlDescriptor;
import gov.nasa.arc.mct.components.PropertyEditor;
import gov.nasa.arc.mct.context.GlobalContext;
+import gov.nasa.arc.mct.platform.spi.Platform;
+import gov.nasa.arc.mct.platform.spi.PlatformAccess;
import gov.nasa.arc.mct.platform.spi.RoleAccess;
import gov.nasa.arc.mct.platform.spi.RoleService;
import gov.nasa.arc.mct.services.component.ViewInfo;
@@ -29,6 +31,7 @@
import org.mockito.Mockito;
import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -38,19 +41,29 @@
User mockUser = Mockito.mock(User.class);
RoleService mockRoleService = Mockito.mock(RoleService.class);
AbstractComponent comp = Mockito.mock(AbstractComponent.class);
- ViewInfo info = new ViewInfo(InfoView.class, "Info", ViewType.CENTER);
-
+ Platform mockPlatform = Mockito.mock(Platform.class);
+ Platform oldPlatform;
+ ViewInfo info = new ViewInfo(InfoView.class, "Info", ViewType.CENTER);
+
@BeforeMethod
- public void setup() {
+ public void setup() {
// Setup minimum expected environment for info view
+ oldPlatform = PlatformAccess.getPlatform();
+ new PlatformAccess().setPlatform(mockPlatform);
Mockito.when(comp.getOwner()).thenReturn("*");
Mockito.when(comp.getComponentTypeID()).thenReturn("");
Mockito.when(mockUser.getUserId()).thenReturn("");
Mockito.when(mockRoleService.getAllUsers()).thenReturn(Collections.singleton(""));
+ Mockito.when(mockPlatform.getBootstrapComponents()).thenReturn(Collections.<AbstractComponent>emptyList());
GlobalContext.getGlobalContext().switchUser(mockUser, Mockito.mock(Runnable.class));
new RoleAccess().addRoleService(mockRoleService);
}
+ @AfterMethod
+ public void teardown() {
+ new PlatformAccess().setPlatform(oldPlatform);
+ }
+
@Test
public void testUpdateMonitoredGUI() {
/* This test ensures that updateMonitoredGUI triggers revalidate/repaint */
View
28 platform/src/test/java/gov/nasa/arc/mct/gui/actions/TestRefresh.java
@@ -27,6 +27,7 @@
import gov.nasa.arc.mct.gui.ContextAwareAction;
import gov.nasa.arc.mct.gui.View;
import gov.nasa.arc.mct.gui.housing.MCTContentArea;
+import gov.nasa.arc.mct.platform.spi.PersistenceProvider;
import gov.nasa.arc.mct.platform.spi.Platform;
import gov.nasa.arc.mct.platform.spi.PlatformAccess;
import gov.nasa.arc.mct.platform.spi.WindowManager;
@@ -64,6 +65,8 @@
@Mock private ViewInfo mockViewInfo;
@Mock private ActionEvent mockEvent;
@Mock private WindowManager mockWindowManager;
+ @Mock private PersistenceProvider mockPersistence;
+ @Mock private View mockInspector;
@BeforeClass
public void setup() {
@@ -84,10 +87,14 @@ public void setupMethod() {
Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockHousing);
Mockito.when(mockHousing.getContentArea()).thenReturn(mockContentArea);
Mockito.when(mockContentArea.getHousedViewManifestation()).thenReturn(mockView);
+ Mockito.when(mockInspector.getHousedViewManifestation()).thenReturn(mockView);
Mockito.when(mockHousing.getManifestedComponent()).thenReturn(mockComponent);
Mockito.when(mockView.getManifestedComponent()).thenReturn(mockComponent);
Mockito.when(mockView.getInfo()).thenReturn(mockViewInfo);
Mockito.when(mockPlatform.getWindowManager()).thenReturn(mockWindowManager);
+ Mockito.when(mockPlatform.getPersistenceProvider()).thenReturn(mockPersistence);
+ Mockito.when(mockPersistence.getComponent(Mockito.anyString())).thenReturn(mockComponent);
+ Mockito.when(mockComponent.getComponentId()).thenReturn("mock");
}
// Test various 'canHandle' responses
@@ -128,7 +135,7 @@ public void testActionPerformedNonDirty() {
// The newer version of the component, for which a view should be created
AbstractComponent newerComponent = Mockito.mock(AbstractComponent.class);
- Mockito.when(mockHousing.getManifestedComponent()).thenReturn(newerComponent);
+ Mockito.when(mockPersistence.getComponent("mock")).thenReturn(newerComponent);
// Similarly, newer version of the view
View newerView = Mockito.mock(View.class);
@@ -160,7 +167,7 @@ public void testActionPerformedDirty(final boolean confirmed) {
// The newer version of the component, for which a view should be created
AbstractComponent newerComponent = Mockito.mock(AbstractComponent.class);
- Mockito.when(mockHousing.getManifestedComponent()).thenReturn(newerComponent);
+ Mockito.when(mockPersistence.getComponent("mock")).thenReturn(newerComponent);
// Similarly, newer version of the view
View newerView = Mockito.mock(View.class);
@@ -207,4 +214,21 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
public Object[][] truthData() {
return new Object[][] { {true} , {false} };
}
+
+ // An Inspector has some differences from ContentArea - verify that it is refreshable too
+ @Test
+ public void testInspector() {
+ // Verify interactions with a mock inspector
+ Mockito.when(mockContext.getWindowManifestation()).thenReturn(mockInspector);
+
+ // Verify that refresh can handle, is enabled for an Inspector
+ ContextAwareAction refresh = new RefreshAction();
+ Assert.assertTrue(refresh.canHandle(mockContext));
+ Assert.assertTrue(refresh.isEnabled());
+
+ // Verify actionPerformed triggers appropriate method
+ refresh.actionPerformed(mockEvent);
+ Mockito.verify(mockInspector).setHousedViewManifestation(mockViewInfo);
+ }
}
+
Please sign in to comment.
Something went wrong with that request. Please try again.