Skip to content
This repository has been archived by the owner on May 17, 2018. It is now read-only.

Commit

Permalink
More missing context handling improvements.
Browse files Browse the repository at this point in the history
Better handling of cases where context is missing. Will prompt user when
Update Diagram is selected. Removed Update menu option and only allow
Update Diagram. Better handling when diagram has not been updated and is
being used with proxy objects.
  • Loading branch information
philip-alldredge committed Dec 12, 2017
1 parent f7740b8 commit d8f5e39
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 66 deletions.
2 changes: 1 addition & 1 deletion org.osate.ge.doc/docs-gen/user_guide.html
Expand Up @@ -807,7 +807,7 @@ <h2 id="inconsistent-font-sizes-across-machines"><span class="header-section-num
<h2 id="unable-to-set-properties-unless-text-model-is-open"><span class="header-section-number">4.3</span> Unable to Set Properties Unless Text Model is Open</h2>
<p>The AADL Property Values view does not support editing property associations unless the textual AADL model is open. To work around this issue, open the textual AADL file before attempting to create property assignments with the AADL Properties Values view.</p>
<h2 id="updating-the-diagram"><span class="header-section-number">4.4</span> Updating the Diagram</h2>
<p>In most cases the graphical editor will automatically update diagrams to reflect changes to the AADL Model. If a diagram has not been updated for any reason, it can be updated manually by right-clicking inside an empty area of the diagram and selecting <em>Update</em> from the context menu.</p>
<p>In most cases the graphical editor will automatically update diagrams to reflect changes to the AADL Model. If a diagram has not been updated for any reason, it can be updated manually by right-clicking inside the diagram and selecting <em>Update Diagram</em> from the context menu.</p>
<h2 id="missing-diagram-elements-after-modification-of-aadl-source"><span class="header-section-number">4.5</span> Missing Diagram Elements After Modification of AADL Source</h2>
<p>See section <a href="#sec:restore_missing_diagram_elements">3.1.15</a>.</p>
<h2 id="reporting-bugs"><span class="header-section-number">4.6</span> Reporting Bugs</h2>
Expand Down
2 changes: 1 addition & 1 deletion org.osate.ge.doc/docs/user_guide.md
Expand Up @@ -611,7 +611,7 @@ To ensure diagrams have a consistent appearance across machines, the graphical e
The AADL Property Values view does not support editing property associations unless the textual AADL model is open. To work around this issue, open the textual AADL file before attempting to create property assignments with the AADL Properties Values view.

## Updating the Diagram
In most cases the graphical editor will automatically update diagrams to reflect changes to the AADL Model. If a diagram has not been updated for any reason, it can be updated manually by right-clicking inside an empty area of the diagram and selecting *Update* from the context menu.
In most cases the graphical editor will automatically update diagrams to reflect changes to the AADL Model. If a diagram has not been updated for any reason, it can be updated manually by right-clicking inside the diagram and selecting *Update Diagram* from the context menu.

## Missing Diagram Elements After Modification of AADL Source
See @sec:restore_missing_diagram_elements.
Expand Down
Expand Up @@ -160,7 +160,8 @@ public void initialize(final IEclipseContext context) {
queryService, nodeFactory);
deInfoProvider = new DefaultDiagramElementGraphicalConfigurationProvider(referenceResolver, extService);
diagramUpdater = new DiagramUpdater(boTreeExpander, deInfoProvider);
this.updateDiagramFeature = new UpdateDiagramFeature(this, graphitiService, diagramUpdater, graphitiService);
this.updateDiagramFeature = new UpdateDiagramFeature(this, graphitiService, diagramUpdater, graphitiService,
referenceResolver);

// Create the configure diagram feature
this.configureDiagramFeature = new ConfigureDiagramFeature(this, boTreeExpander, diagramUpdater,
Expand Down
Expand Up @@ -89,6 +89,11 @@ public boolean canDelete(final IDeleteContext context) {
return false;
}

// Don't allow proxies.
if (bo instanceof EObject && ((EObject) bo).eIsProxy()) {
return false;
}

final IEclipseContext childCtx = extService.createChildContext();
try {
childCtx.set(Names.BUSINESS_OBJECT, bo);
Expand Down
Expand Up @@ -81,7 +81,6 @@ public boolean isAvailable(final IContext context) {
final Object[] businessObjects = getBusinessObjects(bocs);
if(businessObjects == null){
return false;

}

populateEclipseContext(eclipseContext, bocs, businessObjects, null);
Expand Down Expand Up @@ -249,6 +248,10 @@ private Object[] getBusinessObjects(final BusinessObjectContext[] bocs) {
if(bos[i] == null) {
return null;
}

if (bos[i] instanceof EObject && ((EObject) bos[i]).eIsProxy()) {
return null;
}
}

return bos;
Expand Down
Expand Up @@ -20,18 +20,19 @@
import org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil;
import org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider;
import org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater;
import org.osate.ge.internal.graphiti.GraphitiAgeDiagramProvider;
import org.osate.ge.internal.graphiti.diagram.GraphitiAgeDiagram;
import org.osate.ge.internal.graphiti.services.GraphitiService;
import org.osate.ge.internal.services.ExtensionService;
import org.osate.ge.internal.services.ProjectProvider;
import org.osate.ge.internal.services.ProjectReferenceService;
import org.osate.ge.internal.ui.dialogs.DefaultDiagramConfigurationDialogModel;
import org.osate.ge.internal.ui.dialogs.DiagramConfigurationDialog;
import org.osate.ge.internal.ui.editor.AgeDiagramEditor;

public class ConfigureDiagramFeature extends AbstractCustomFeature implements ICustomUndoRedoFeature {
private final TreeUpdater boTreeExpander;
private final DiagramUpdater diagramUpdater;
private final GraphitiAgeDiagramProvider graphitiAgeDiagramProvider;
private final GraphitiService graphitiService;
private final ProjectReferenceService referenceService;
private final ExtensionService extService;
private final ProjectProvider projectProvider;
Expand All @@ -41,14 +42,14 @@ public class ConfigureDiagramFeature extends AbstractCustomFeature implements IC
public ConfigureDiagramFeature(final IFeatureProvider fp,
final TreeUpdater boTreeExpander,
final DiagramUpdater diagramUpdater,
final GraphitiAgeDiagramProvider graphitiAgeDiagramProvider,
final GraphitiService graphitiService,
final ProjectReferenceService referenceService,
final ExtensionService extService,
final ProjectProvider projectProvider, final LayoutInfoProvider layoutInfoProvider) {
super(fp);
this.boTreeExpander = Objects.requireNonNull(boTreeExpander, "boTreeExpander must not be null");
this.diagramUpdater = Objects.requireNonNull(diagramUpdater, "diagramUpdater must not be null");
this.graphitiAgeDiagramProvider = Objects.requireNonNull(graphitiAgeDiagramProvider, "graphitiAgeDiagramProvider must not be null");
this.graphitiService = Objects.requireNonNull(graphitiService, "graphitiService must not be null");
this.referenceService = Objects.requireNonNull(referenceService, "referenceService must not be null");
this.extService = Objects.requireNonNull(extService, "extService must not be null");
this.projectProvider = Objects.requireNonNull(projectProvider, "projectProvider must not be null");
Expand All @@ -62,12 +63,13 @@ public String getName() {

@Override
public boolean canExecute(final ICustomContext context) {
return true;
final AgeDiagramEditor editor = graphitiService.getEditor();
return editor != null && editor.isEditable();
}

@Override
public void execute(final ICustomContext context) {
final GraphitiAgeDiagram graphitiAgeDiagram = graphitiAgeDiagramProvider.getGraphitiAgeDiagram();
final GraphitiAgeDiagram graphitiAgeDiagram = graphitiService.getGraphitiAgeDiagram();
final AgeDiagram diagram = graphitiAgeDiagram.getAgeDiagram();

BusinessObjectNode boTree = DiagramToBusinessObjectTreeConverter.createBusinessObjectNode(diagram);
Expand Down
Expand Up @@ -16,23 +16,24 @@
import org.osate.ge.internal.diagram.runtime.BuiltinContentsFilter;
import org.osate.ge.internal.diagram.runtime.DiagramElement;
import org.osate.ge.internal.diagram.runtime.DiagramModification;
import org.osate.ge.internal.graphiti.GraphitiAgeDiagramProvider;
import org.osate.ge.internal.graphiti.services.GraphitiService;
import org.osate.ge.internal.model.PropertyValueGroup;
import org.osate.ge.internal.ui.editor.AgeDiagramEditor;

/**
* Sets the auto contents filter for a diagram element and then updates the diagram.
*
*/
public class SetAutoContentFilterFeature extends AbstractCustomFeature implements ICustomUndoRedoFeature {
private final GraphitiAgeDiagramProvider graphitiAgeDiagramProvider;
private final GraphitiService graphitiService;
private final BuiltinContentsFilter newFilterValue;

@Inject
public SetAutoContentFilterFeature (final IFeatureProvider fp,
final GraphitiAgeDiagramProvider graphitiAgeDiagramProvider,
final GraphitiService graphitiService,
final BuiltinContentsFilter newFilterValue) {
super(fp);
this.graphitiAgeDiagramProvider = Objects.requireNonNull(graphitiAgeDiagramProvider, "graphitiAgeDiagramProvider must not be null");
this.graphitiService = Objects.requireNonNull(graphitiService, "graphitiService must not be null");
this.newFilterValue = Objects.requireNonNull(newFilterValue, "newFilerValue must not be null");
}

Expand Down Expand Up @@ -84,14 +85,19 @@ public boolean canExecute(final ICustomContext context) {
return false;
}

// Don't allow execution if editor is not editable
final AgeDiagramEditor editor = graphitiService.getEditor();
if (editor != null && !editor.isEditable()) {
return false;
}

// If the selection is the "Hide Contents" selection, make the command executable if any of the descendants is manual
if(newFilterValue == BuiltinContentsFilter.ALLOW_FUNDAMENTAL) {
for(final DiagramElement e : elements) {
if(hasManualDescendant(e)) {
return true;
}
}

}

// Make the command executable if any of the elements have a different filter value
Expand All @@ -106,7 +112,7 @@ public boolean canExecute(final ICustomContext context) {

@Override
public void execute(final ICustomContext context) {
final AgeDiagram ageDiagram = graphitiAgeDiagramProvider.getGraphitiAgeDiagram().getAgeDiagram();
final AgeDiagram ageDiagram = graphitiService.getGraphitiAgeDiagram().getAgeDiagram();
final DiagramElement[] elements = getDiagramElements(context.getPictogramElements());
if(elements != null) {
ageDiagram.modify("Set Auto Children", m -> {
Expand All @@ -129,7 +135,7 @@ public void execute(final ICustomContext context) {
});

// Update the diagram
this.updatePictogramElement(graphitiAgeDiagramProvider.getGraphitiAgeDiagram().getGraphitiDiagram());
this.updatePictogramElement(graphitiService.getGraphitiAgeDiagram().getGraphitiDiagram());
}
}

Expand Down Expand Up @@ -167,7 +173,7 @@ private DiagramElement[] getDiagramElements(final PictogramElement[] pes) {
final DiagramElement[] elements = new DiagramElement[pes.length];

for(int i = 0; i < pes.length; i++) {
elements[i] = graphitiAgeDiagramProvider.getGraphitiAgeDiagram().getClosestDiagramElement(pes[i]);
elements[i] = graphitiService.getGraphitiAgeDiagram().getClosestDiagramElement(pes[i]);
if(elements[i] == null) {
return null;
}
Expand All @@ -187,10 +193,10 @@ public void preUndo(final IContext context) {

@Override
public void postUndo(final IContext context) {
AgeFeatureUtil.undoModification(graphitiAgeDiagramProvider.getGraphitiAgeDiagram(), context);
AgeFeatureUtil.undoModification(graphitiService.getGraphitiAgeDiagram(), context);

// Update the diagram
this.updatePictogramElement(graphitiAgeDiagramProvider.getGraphitiAgeDiagram().getGraphitiDiagram());
this.updatePictogramElement(graphitiService.getGraphitiAgeDiagram().getGraphitiDiagram());
}

@Override
Expand All @@ -204,9 +210,9 @@ public void preRedo(final IContext context) {

@Override
public void postRedo(final IContext context) {
AgeFeatureUtil.redoModification(graphitiAgeDiagramProvider.getGraphitiAgeDiagram(), context);
AgeFeatureUtil.redoModification(graphitiService.getGraphitiAgeDiagram(), context);

// Update the diagram
this.updatePictogramElement(graphitiAgeDiagramProvider.getGraphitiAgeDiagram().getGraphitiDiagram());
this.updatePictogramElement(graphitiService.getGraphitiAgeDiagram().getGraphitiDiagram());
}
}
@@ -1,19 +1,19 @@
package org.osate.ge.internal.graphiti.features;

import javax.inject.Inject;

import org.eclipse.graphiti.features.ICustomUndoRedoFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.mm.pictograms.Diagram;

public class UpdateDiagramCustomFeature extends AbstractCustomFeature implements ICustomUndoRedoFeature {
@Inject
public UpdateDiagramCustomFeature(final IFeatureProvider fp) {
super(fp);
}

@Override
public String getName() {
return "Update Diagram";
Expand All @@ -23,30 +23,28 @@ public String getName() {
public String getDescription() {
return "Updates the diagram";
}

@Override
public boolean isAvailable(final IContext context) {
// Don't make the command available if the only selection is the diagram. There is already an update menu option available in that case.
final ICustomContext customCtx = (ICustomContext)context;
return customCtx.getPictogramElements().length != 1 || !(customCtx.getPictogramElements()[0] instanceof Diagram);
return true;
}

@Override
public boolean canExecute(final ICustomContext context) {
return true;
}

@Override
public void execute(final ICustomContext context) {
updatePictogramElement(getDiagram());
getFeatureProvider().updateIfPossible(UpdateDiagramFeature.createUpdateContext(getDiagram(), true));
}

// ICustomUndoRedoFeature
@Override
public boolean canUndo(final IContext context) {
return false;
}

@Override
public void preUndo(final IContext context) {
}
Expand Down
Expand Up @@ -9,28 +9,42 @@
import org.eclipse.graphiti.features.IReason;
import org.eclipse.graphiti.features.context.IContext;
import org.eclipse.graphiti.features.context.IUpdateContext;
import org.eclipse.graphiti.features.context.impl.UpdateContext;
import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.swt.widgets.Display;
import org.osate.ge.internal.diagram.runtime.AgeDiagram;
import org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil;
import org.osate.ge.internal.diagram.runtime.layout.LayoutInfoProvider;
import org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater;
import org.osate.ge.internal.graphiti.GraphitiAgeDiagramProvider;
import org.osate.ge.internal.graphiti.services.GraphitiService;
import org.osate.ge.internal.services.ProjectReferenceService;
import org.osate.ge.internal.ui.editor.AgeDiagramEditor;
import org.osate.ge.internal.ui.editor.DiagramContextChecker;

public class UpdateDiagramFeature extends AbstractUpdateFeature implements ICustomUndoRedoFeature {
private final GraphitiAgeDiagramProvider graphitiAgeDiagramProvider;
private static final String promptToRelinkMissingContextProperty = "promptToRelinkMissingContext";

private final GraphitiService graphitiService;
private final DiagramUpdater diagramUpdater;
private final LayoutInfoProvider layoutInfoProvider;
private final ProjectReferenceService projectReferenceService;

private boolean wasContextValid = true;

@Inject
public UpdateDiagramFeature(final IFeatureProvider fp,
final GraphitiAgeDiagramProvider graphitiAgeDiagramProvider,
final DiagramUpdater diagramUpdater, final LayoutInfoProvider layoutInfoProvider) {
final GraphitiService graphitiService,
final DiagramUpdater diagramUpdater, final LayoutInfoProvider layoutInfoProvider,
final ProjectReferenceService projectReferenceService) {
super(fp);
this.graphitiAgeDiagramProvider = Objects.requireNonNull(graphitiAgeDiagramProvider, "graphitiAgeDiagramProvider must not be null");
this.graphitiService = Objects.requireNonNull(graphitiService, "graphitiService must not be null");
this.diagramUpdater = Objects.requireNonNull(diagramUpdater, "diagramUpdater must not be null");
this.layoutInfoProvider = Objects.requireNonNull(layoutInfoProvider, "layoutInfoProvider must not be null");
this.projectReferenceService = Objects.requireNonNull(projectReferenceService,
"projectReferenceService must not be null");
}

@Override
Expand All @@ -45,7 +59,28 @@ public IReason updateNeeded(IUpdateContext context) {

@Override
public boolean update(final IUpdateContext context) {
final AgeDiagram ageDiagram = graphitiAgeDiagramProvider.getGraphitiAgeDiagram().getAgeDiagram();
final AgeDiagram ageDiagram = graphitiService.getGraphitiAgeDiagram().getAgeDiagram();

// Get the editor
final AgeDiagramEditor editor = graphitiService.getEditor();
if (editor != null) {
// Check the context
Display.getCurrent().syncExec(() -> {
final boolean promptToRelink = editor.getGraphicalViewer().getControl() != null
&& editor.getGraphicalViewer().getControl().isVisible() && (wasContextValid
|| Boolean.TRUE.equals(context.getProperty(promptToRelinkMissingContextProperty)));
final DiagramContextChecker contextChecker = new DiagramContextChecker(graphitiService.getProject(),
projectReferenceService);
final DiagramContextChecker.Result result = contextChecker.checkContextIncrementalBuild(ageDiagram,
promptToRelink);
wasContextValid = result.isContextValid(); // Store for next execution
editor.setDiagramContextIsValid(result.isContextValid()); // Update editor with new state
});

if (!wasContextValid) {
return false;
}
}

// Update the diagram
diagramUpdater.updateDiagram(ageDiagram);
Expand Down Expand Up @@ -83,4 +118,17 @@ public void preRedo(final IContext context) {
@Override
public void postRedo(final IContext context) {
}

/**
*
* @param pe
* @param promptToRelinkMissingContext if true, then the user will be prompted to relink a missing context even if the user has been previously prompted. Prompts only occur if editor is visible.
* @return
*/
public static IUpdateContext createUpdateContext(final PictogramElement pe,
final boolean promptToRelinkMissingContext) {
final UpdateContext updateContext = new UpdateContext(pe);
updateContext.putProperty(promptToRelinkMissingContextProperty, promptToRelinkMissingContext);
return updateContext;
}
}

0 comments on commit d8f5e39

Please sign in to comment.