/** {@inheritDoc} */ @Override protected void initRepresentation() { super.initRepresentation(); List<View> compartmentViews = CompartmentUtils.getAllCompartments(getRepresentedEditPart(), false); List<View> visibleCompartments = CompartmentUtils.getAllVisibleCompartments(getRepresentedEditPart(), false); for (View currentView : compartmentViews) { CompartmentEditPartRepresentation representation = new CompartmentEditPartRepresentation(null, currentView, getSemanticElement(), this); elementsToSelect.add(representation); if (visibleCompartments.contains(currentView)) { initialSelection.add(representation); } } }
/** * Constructor. * * @param representedEditPart the represented EditPart. this can be <code>null</code> if the * compartment is not visible when the dialog is opened * @param compartmentView notation view for this compartment. this should never be <code>null * </code>. * @param eObject the semantic element represented by EditPartRepresentation * @param parentRepresentation parent representation of this edit part representation */ public CompartmentEditPartRepresentation( IResizableCompartmentEditPart representedEditPart, View compartmentView, EObject eObject, EditPartRepresentation parentRepresentation) { super(representedEditPart, eObject, parentRepresentation); isTitleVisible = CompartmentUtils.isCompartmentTitleVisible(compartmentView); this.compartmentView = compartmentView; assert compartmentView != null : "The compartment view should not be null"; }
/** {@inheritDoc} */ @Override protected Command getActionCommand() { /* for further information, see bug 302555 */ ViewServiceUtil.forceLoad(); ShowHideCompartmentRequest req = null; CompoundCommand completeCmd = new CompoundCommand("Destroy and Create Compartment Command"); // $NON-NLS-1$ // the commands to hide compartment for (EditPartRepresentation current : this.viewsToDestroy) { if (current instanceof CompartmentEditPartRepresentation) { CompartmentEditPartRepresentation currentRepresentation = (CompartmentEditPartRepresentation) current; View currentView = currentRepresentation.getCompartmentView(); EditPart currentEditPart = currentRepresentation .getRepresentedEditPart(); // should not be null, because a view to delete should // be visible, and so have an existing associated edit // part. // if null, try to find it using gmf methods from the view if (currentEditPart == null) { Activator.log.debug( "Warning! An edit part representation wished to destroy a view, but no edit part exists currently!" + current); currentEditPart = DiagramEditPartsUtil.getEditPartFromView(currentView, selectedElements.get(0)) .getParent(); } if (currentEditPart != null) { req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.HIDE, currentView); req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT); Command tmp = currentEditPart.getCommand(req); if (tmp != null && tmp.canExecute()) { completeCmd.add(tmp); } } else { Activator.log.debug( "Impossible to find an edit part for the given representation: " + current); } } // if(current instanceof View) { // EditPart ep = DiagramEditPartsUtil.getEditPartFromView((View)current, // selectedElements.get(0)).getParent(); // req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.HIDE, // ((View)current).getType()); // req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT); // Command tmp = ep.getCommand(req); // if(tmp != null && tmp.canExecute()) { // completeCmd.add(tmp); // } // } else if(current instanceof CompartmentTitleRepresentation) { // ShowHideTitleOfCompartmentCommand tmp = new // ShowHideTitleOfCompartmentCommand(this.domain, // (View)((CompartmentTitleRepresentation)current).getRealObject(), false); // if(tmp != null && tmp.canExecute()) { // completeCmd.add(new ICommandProxy(tmp)); // } // } } // the command to show compartment for (EditPartRepresentation current : this.viewsToCreate) { if (current instanceof CompartmentEditPartRepresentation) { CompartmentEditPartRepresentation currentRepresentation = (CompartmentEditPartRepresentation) current; View currentView = currentRepresentation.getCompartmentView(); EditPartRepresentation parentRepresentation = currentRepresentation.getParentRepresentation(); IGraphicalEditPart parentEditPart = parentRepresentation.getRepresentedEditPart(); if (currentView != null && parentEditPart != null) { req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.SHOW, currentView); req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT); Command tmp = parentEditPart.getCommand(req); if (tmp != null && tmp.canExecute()) { completeCmd.add(tmp); } } } // if(current instanceof View) { // EditPart ep = CompartmentUtils.getCompartmentTitleRepresentation(rep, // (View)current).getParent(); // req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.SHOW, // ((View)current).getType()); // req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT); // Command tmp = ep.getCommand(req); // if(tmp != null && tmp.canExecute()) { // completeCmd.add(tmp); // } // } else if(current instanceof CompartmentTitleRepresentation) { // CompartmentTitleRepresentation compartmentTitleRep = // (CompartmentTitleRepresentation)current; // final View view = (View)compartmentTitleRep.getRealObject(); // Style style = view.getStyle(NotationPackage.eINSTANCE.getTitleStyle()); // if(style == null) { // // style is not existing yet (true for models created with Papyrus 0.7.x) => create now // // See bug 351084 // completeCmd.add(new ICommandProxy(new AbstractTransactionalCommand(domain, "Create // title style", Collections.EMPTY_LIST) { //$NON-NLS-1$ // // public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) { // TitleStyle style = // (TitleStyle)view.createStyle(NotationPackage.eINSTANCE.getTitleStyle()); // style.setShowTitle(false); // return CommandResult.newOKCommandResult(); // } // })); // } // ShowHideTitleOfCompartmentCommand tmp = new // ShowHideTitleOfCompartmentCommand(this.domain, view, true); // if(tmp != null && tmp.canExecute()) { // completeCmd.add(new ICommandProxy(tmp)); // } // } } // now sets the visibility for all shown views for (CompartmentEditPartRepresentation currentRepresentation : visibleRepresentations) { final View currentView = currentRepresentation.getCompartmentView(); boolean newVisibility = currentRepresentation.isTitleVisible(); boolean oldVisibility = CompartmentUtils.isCompartmentTitleVisible(currentView); IGraphicalEditPart parentEditPart = currentRepresentation.getParentRepresentation().getRepresentedEditPart(); final TransactionalEditingDomain domain = parentEditPart.getEditingDomain(); // visibility has changed => change the model if (newVisibility != oldVisibility) { Style style = currentView.getStyle(NotationPackage.eINSTANCE.getTitleStyle()); if (style == null) { // style is not existing yet (true for models created with Papyrus 0.7.x) => create now // See bug 351084 completeCmd.add( new ICommandProxy( new AbstractTransactionalCommand( domain, "Create title style", Collections.EMPTY_LIST) { // $NON-NLS-1$ @Override public CommandResult doExecuteWithResult( IProgressMonitor dummy, IAdaptable info) { TitleStyle style = (TitleStyle) currentView.createStyle(NotationPackage.eINSTANCE.getTitleStyle()); style.setShowTitle(false); return CommandResult.newOKCommandResult(); } })); } ShowHideTitleOfCompartmentCommand tmp = new ShowHideTitleOfCompartmentCommand(domain, currentView, newVisibility); if (tmp != null && tmp.canExecute()) { completeCmd.add(new ICommandProxy(tmp)); } } } return completeCmd; }