@Override
  public boolean canHandle(ActionContext context) {
    actionContext = (ActionContextImpl) context;

    if (DetectGraphicsDevices.getInstance().getNumberGraphicsDevices()
        > DetectGraphicsDevices.MINIMUM_MONITOR_CHECK) {
      graphicsDeviceName =
          actionContext
              .getTargetHousing()
              .getHostedFrame()
              .getGraphicsConfiguration()
              .getDevice()
              .getIDstring();
      graphicsDeviceName = graphicsDeviceName.replace("\\", "");
    }

    selectedManifestations = context.getSelectedManifestations();
    if (selectedManifestations.isEmpty()) {
      // No objects selected to add to a new collections
      return false;
    }

    // Guards against attempting to put a top level object into a collection as this will result in
    // that collection becoming a child of itself. The prime example of this is the "All" entry in
    // the tree. All necessary contains everything so adding All to All would result in All being a
    // child
    for (View manifestation : selectedManifestations) {
      if (manifestation.getManifestedComponent()
          == PlatformAccess.getPlatform().getRootComponent()) {
        return false;
      }
    }

    return true;
  }
Ejemplo n.º 2
0
  @Test(dataProvider = "generateSwitcherTests")
  public void testSwitcher(boolean addGUI, boolean doChange, boolean acceptChange) {
    // Create the test object
    View switcherView = SwitcherView.VIEW_INFO.createView(mockComponent);

    // Act as though the view provider has/hasn't accepted the view switch
    Mockito.when(mockViewProvider.setHousedViewManifestation(mockViewInfo2))
        .thenReturn(acceptChange);

    // Attach view provider to gui, if this test iteration says we should
    if (addGUI) {
      switcherView.addMonitoredGUI(mockViewProvider);
    }

    // Find combo box so we can change selection
    @SuppressWarnings("rawtypes")
    JComboBox comboBox = findComponent(switcherView, JComboBox.class);
    Assert.assertNotNull(comboBox);

    // Change the item - again, only if we're supposed to
    if (doChange) {
      comboBox.setSelectedItem(mockViewInfo2);
    }

    // Verify that the change was reported to the GUI,
    // if a GUI was attached and the change was done
    Mockito.verify(mockViewProvider, Mockito.times(addGUI && doChange ? 1 : 0))
        .setHousedViewManifestation(mockViewInfo2);

    // Verify that combo box state has/hasn't reset, as apparopriate
    // Specifically, only should if change was done, and an attached GUI didn't reject it
    boolean shouldChange = doChange && !(addGUI && !acceptChange);
    Assert.assertEquals(comboBox.getSelectedItem(), shouldChange ? mockViewInfo2 : mockViewInfo1);
  }
Ejemplo n.º 3
0
 @Override
 public void closeHousing() {
   boolean toCloseWindow = true;
   MCTContentArea centerPane = housingViewManifestation.getContentArea();
   if (centerPane != null) {
     View centerPaneView = centerPane.getHousedViewManifestation();
     AbstractComponent centerComponent = centerPaneView.getManifestedComponent();
     if (!centerComponent.isStale() && centerComponent.isDirty()) {
       toCloseWindow =
           commitOrAbortPendingChanges(
               centerPaneView,
               MessageFormat.format(
                   BUNDLE.getString("centerpane.modified.alert.text"),
                   centerPaneView.getInfo().getViewName(),
                   centerComponent.getDisplayName()));
     }
   }
   View inspectionArea = housingViewManifestation.getInspectionArea();
   if (inspectionArea != null) {
     View inspectorPaneView = inspectionArea.getHousedViewManifestation();
     AbstractComponent inspectorComponent = inspectorPaneView.getManifestedComponent();
     if (!inspectorComponent.isStale() && inspectorComponent.isDirty()) {
       toCloseWindow =
           commitOrAbortPendingChanges(
               inspectionArea,
               MessageFormat.format(
                   BUNDLE.getString("inspectorpane.modified.alert.text"),
                   inspectorPaneView.getInfo().getViewName(),
                   inspectorComponent.getDisplayName()));
     }
   }
   if (toCloseWindow) {
     disposeHousing();
   }
 }
  @Override
  public boolean isEnabled() {
    List<AbstractComponent> components =
        new ArrayList<AbstractComponent>(selectedManifestations.size());
    for (View view : selectedManifestations) {
      components.add(view.getManifestedComponent());
    }

    // disable use for objects which cannot be contained
    PolicyContext context = new PolicyContext();
    context.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(), components);
    String policyCategoryKey = PolicyInfo.CategoryType.CAN_OBJECT_BE_CONTAINED_CATEGORY.getKey();
    ExecutionResult result = PolicyManagerImpl.getInstance().execute(policyCategoryKey, context);
    return result.getStatus();
  }
Ejemplo n.º 5
0
  @Test
  public void testBadInput() {
    // Make sure that view does not break for unexpected input
    // (verify that null checks are present.)

    // Create the test object
    View switcherView = SwitcherView.VIEW_INFO.createView(mockComponent);

    // Add monitored GUI can take a variety of object types
    // Make sure an unexpected object type does not trigger an exception
    switcherView.addMonitoredGUI(null);
    switcherView.addMonitoredGUI("hello");
    Mockito.when(mockViewProvider.getHousedViewManifestation()).thenReturn(null);
    switcherView.addMonitoredGUI(mockViewProvider);
  }
Ejemplo n.º 6
0
  @Override
  public void actionPerformed(ActionEvent e) {
    Set<AbstractComponent> sourceComponents = new LinkedHashSet<AbstractComponent>();
    for (View manifestation : selectedManifestations)
      sourceComponents.add(manifestation.getManifestedComponent());

    final AbstractComponent activity = createNewActivity(sourceComponents);
    activity.setDisplayName("Activity 1");
    // invoke later so that transaction will have already completed
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            openNewActivity("Activity 1", activity);
          }
        });
  }
Ejemplo n.º 7
0
  public MCTStandardHousing(
      String title, int width, int height, int closeAction, View housingView) {
    super(housingView.getManifestedComponent().getId());

    getContentPane().setLayout(new GridLayout());
    this.width = width;
    this.height = height;
    setSize(this.width, this.height);
    displayPanel.setSize(this.width, this.height);
    setTitle(title);
    setIcon(housingView.getManifestedComponent().getAsset(ImageIcon.class));
    setDefaultCloseOperation(closeAction);
    MCTHousingViewManifestation housingManifestation = (MCTHousingViewManifestation) housingView;
    setHousingViewManifesation(housingManifestation);
    addWindowListenerToHousing();
    getContentPane().add(displayPanel);
  }
Ejemplo n.º 8
0
  /**
   * Prompts users to commit or abort pending changes in view.
   *
   * @param view the modified view
   * @param dialogMessage the dialog message which differs from where the view is located (in the
   *     center or inspector pane)
   * @return false to keep the window open, true to close the window
   */
  private boolean commitOrAbortPendingChanges(View view, String dialogMessage) {
    AbstractComponent comp = view.getManifestedComponent();
    if (!isComponentWriteableByUser(comp)) return true;

    // Options (save, save all, abort)
    String save = BUNDLE.getString("view.modified.alert.save");
    String discard = BUNDLE.getString("view.modified.alert.abort");
    String cancel = BUNDLE.getString("view.modified.alert.cancel");

    // Show options - Save, Abort, or maybe Save All
    ObjectManager om = comp.getCapability(ObjectManager.class);
    Set<AbstractComponent> modified =
        om != null ? om.getAllModifiedObjects() : Collections.<AbstractComponent>emptySet();
    String[] options = new String[] {save, discard, cancel};

    Map<String, Object> hints = new HashMap<String, Object>();
    hints.put(WindowManagerImpl.MESSAGE_TYPE, OptionBox.WARNING_MESSAGE);
    hints.put(WindowManagerImpl.OPTION_TYPE, OptionBox.YES_NO_OPTION);
    hints.put(WindowManagerImpl.PARENT_COMPONENT, view);

    String answer =
        PlatformAccess.getPlatform()
            .getWindowManager()
            .showInputDialog(
                BUNDLE.getString("view.modified.alert.title"),
                dialogMessage,
                options,
                options[0],
                hints);

    if (save.equals(answer)) {
      Set<AbstractComponent> allModifiedObjects;
      if (comp.isDirty()) {
        // Create a new set including the object if it's dirty
        allModifiedObjects = new HashSet<AbstractComponent>();
        allModifiedObjects.addAll(modified);
        allModifiedObjects.add(comp);
      } else {
        // Just use the same set returned by the comp's ObjectManager capability
        allModifiedObjects = modified;
      }
      PlatformAccess.getPlatform().getPersistenceProvider().persist(allModifiedObjects);

      if (om != null) {
        om.notifySaved(modified);
      }
      return true;
    } else if (discard.equals(answer)) {
      // Do close window, don't save changes
      return true;
    } else { // Cancel
      return false;
    }
  }
  @Override
  public void actionPerformed(ActionEvent e) {
    Set<AbstractComponent> sourceComponents = new LinkedHashSet<AbstractComponent>();
    for (View manifestation : selectedManifestations)
      sourceComponents.add(manifestation.getManifestedComponent());

    final String name = getNewCollection(sourceComponents);
    if (name.isEmpty()) return;

    final AbstractComponent collection = createNewCollection(sourceComponents);
    if (collection == null) {
      showErrorInCreateCollection();
    } else {
      collection.setDisplayName(name);
      // invoke later so that transaction will have already completed
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              openNewCollection(name, collection);
            }
          });
    }
  }