@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 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; }
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); }
/** * 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 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(); }
@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); } }); }
@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); } }); } }