Пример #1
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 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;
  }
Пример #3
0
 QueryResult search(String pattern, boolean isFindObjectsCreatedByMe) {
   Properties props = new Properties();
   if (isFindObjectsCreatedByMe)
     props.setProperty("creator", PlatformAccess.getPlatform().getCurrentUser().getUserId());
   return InternalDBPersistenceAccess.getService()
       .findComponentsByBaseDisplayedNamePattern(pattern, props);
 }
Пример #4
0
 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();
 }