use of org.osate.ge.internal.services.ColoringService in project osate2 by osate.
the class AgeEditor method createPartControl.
@Override
public void createPartControl(final Composite parent) {
//
// Create the FX canvas which is an SWT widget for embedding JavaFX content.
//
fxCanvas = new FXCanvas(parent, SWT.NONE);
fxCanvas.addDisposeListener(e -> {
fxCanvas.getScene().setRoot(new Group());
fxCanvas.setScene(null);
});
fxCanvas.addPaintListener(paintListener);
// Suppress SWT key press handling when interaction is active
fxCanvas.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(final org.eclipse.swt.events.KeyEvent e) {
if (activeInteraction != null) {
e.doit = false;
}
}
});
fxCanvas.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
deactivateInteraction();
}
});
// Create the context menu
contextMenuManager = new MenuManager(MENU_ID, MENU_ID);
contextMenuManager.setRemoveAllWhenShown(true);
final Menu contextMenu = contextMenuManager.createContextMenu(fxCanvas);
fxCanvas.setMenu(contextMenu);
getEditorSite().registerContextMenu(MENU_ID, contextMenuManager, selectionProvider, true);
// Create the action executor. It will append an action to activate the editor when undoing and redoing actions.
actionExecutor = (label, mode, action) -> {
final boolean reverseActionWasSpecified = actionService.execute(label, mode, action);
// This will ensure that when the action is undone, the editor will be switched to the one in which the action was performed.
if (isEditorActive() && reverseActionWasSpecified && !actionService.isActionExecuting() && mode == ExecutionMode.NORMAL) {
actionService.execute("Activate Editor", ExecutionMode.APPEND_ELSE_HIDE, new ActivateAgeEditorAction(AgeEditor.this));
}
fireDirtyPropertyChangeEvent();
return reverseActionWasSpecified;
};
// Initialize the palette model
final AgeEditorPaletteModel.ImageProvider imageProvider = id -> {
final RegisteredImage img = extRegistry.getImageMap().get(id);
if (img == null) {
return Optional.empty();
}
final URI imageUri = URI.createPlatformPluginURI("/" + img.plugin + "/" + img.path, true);
if (CommonPlugin.asLocalURI(imageUri).isFile()) {
return Optional.of(new Image(imageUri.toString()));
} else {
return Optional.empty();
}
};
Object diagramBo = AgeDiagramUtil.getConfigurationContextBusinessObject(diagram, projectReferenceService);
if (diagramBo == null) {
diagramBo = project;
}
this.paletteModel = new AgeEditorPaletteModel(extRegistry.getPaletteContributors(), diagramBo, imageProvider);
// If the palette item changes while an interaction is active, deactivate the interaction.
this.paletteModel.activeItemProperty().addListener((javafx.beans.value.ChangeListener<SimplePaletteItem>) (observable, oldValue, newValue) -> deactivateInteraction());
// Initialize the JavaFX nodes based on the diagram
canvas = new InfiniteCanvas();
// Set show grid based on preferences
canvas.setShowGrid(preferenceStore.getBoolean(Preferences.SHOW_GRID));
final Scene scene = new Scene(new DiagramEditorNode(paletteModel, canvas));
fxCanvas.setScene(scene);
gefDiagram = new GefAgeDiagram(diagram, coloringService);
// Create a wrapper around the diagram's scene node.
final Group wrapper = new DiagramNodeWrapper(gefDiagram.getSceneNode());
// Add the wrapper to the canvas
canvas.getContentGroup().getChildren().add(wrapper);
gefDiagram.updateDiagramFromSceneGraph(false);
// Treat the current state of the diagram as clean.
cleanDiagramChangeNumber = diagram.getCurrentChangeNumber();
adapterMap.put(LayoutInfoProvider.class, gefDiagram);
// Create overlays
overlays = new Overlays(gefDiagram);
selectionProvider.addSelectionChangedListener(overlays);
canvas.getScrolledOverlayGroup().getChildren().add(overlays);
// Perform the initial incremental layout
diagram.modify("Incremental Layout", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, gefDiagram));
// Set action executor after initial load. This occurs after the incremental layout to prevent the loading and initial layout from being undoable
diagram.setActionExecutor(actionExecutor);
// Refresh the dirty state whenever an operation occurs
final IOperationHistory history = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
history.addOperationHistoryListener(operationHistoryListener);
canvas.setOnScroll(e -> {
if (e.isControlDown()) {
// Adjust zoom
if (e.getDeltaY() < 0.0) {
zoomOut();
} else {
zoomIn();
}
} else {
if (e.isShiftDown()) {
// Scroll in X direction
canvas.setHorizontalScrollOffset(canvas.getHorizontalScrollOffset() - e.getDeltaY());
} else {
// Scroll
canvas.setHorizontalScrollOffset(canvas.getHorizontalScrollOffset() - e.getDeltaX());
canvas.setVerticalScrollOffset(canvas.getVerticalScrollOffset() + e.getDeltaY());
}
}
});
//
// Listeners to handle tooltips
//
canvas.addEventHandler(MouseEvent.MOUSE_ENTERED_TARGET, e -> {
if (e.getTarget() instanceof Node && activeInteraction == null && tooltipManager != null && gefDiagram != null) {
final DiagramElement de = gefDiagram.getDiagramElement((Node) e.getTarget());
if (de != null) {
tooltipManager.mouseEnter(de);
}
}
});
canvas.addEventHandler(MouseEvent.MOUSE_EXITED_TARGET, e -> {
if (e.getTarget() instanceof Node && activeInteraction == null && tooltipManager != null && gefDiagram != null) {
final DiagramElement de = gefDiagram.getDiagramElement((Node) e.getTarget());
if (de != null) {
tooltipManager.mouseExit(de);
}
}
});
//
// General input handlers
//
// Event handler. Delegates to input event handlers or the active interaction as appropriate
final EventHandler<? super InputEvent> handleInput = e -> {
if (activeInteraction == null) {
// Delegate processing of the event to the input event handlers
for (final InputEventHandler inputEventHandler : inputEventHandlers) {
final InputEventHandler.HandledEvent r = inputEventHandler.handleEvent(e);
if (r != null) {
activeInteraction = r.newInteraction;
if (activeInteraction != null) {
canvas.setCursor(activeInteraction.getCursor());
if (tooltipManager != null) {
tooltipManager.hideTooltip();
}
}
break;
}
}
} else {
if (activeInteraction.handleEvent(e) == InteractionState.COMPLETE) {
deactivateInteraction();
}
canvas.setCursor(activeInteraction == null ? null : activeInteraction.getCursor());
}
};
// Handle mouse button presses
canvas.addEventFilter(MouseEvent.MOUSE_PRESSED, handleInput);
canvas.addEventFilter(MouseEvent.MOUSE_DRAGGED, handleInput);
canvas.addEventFilter(MouseEvent.MOUSE_RELEASED, handleInput);
scene.addEventFilter(KeyEvent.KEY_PRESSED, handleInput);
canvas.addEventFilter(MouseEvent.MOUSE_MOVED, e -> {
if (activeInteraction == null) {
Cursor cursor = Cursor.DEFAULT;
for (final InputEventHandler inputEventHandler : inputEventHandlers) {
final Cursor overrideCursor = inputEventHandler.getCursor(e);
if (overrideCursor != null) {
cursor = overrideCursor;
break;
}
}
canvas.setCursor(cursor);
}
handleInput.handle(e);
});
// Create input event handlers
inputEventHandlers.add(new OpenPropertiesViewInputEventHandler(this));
inputEventHandlers.add(new ResizeInputEventHandler(this));
inputEventHandlers.add(new MarqueeSelectInputEventHandler(this));
inputEventHandlers.add(new MoveConnectionPointTool(this));
inputEventHandlers.add(new RenameInputEventHandler(this));
inputEventHandlers.add(new SelectInputEventHandler(this));
inputEventHandlers.add(new MoveInputEventHandler(this));
inputEventHandlers.add(new PaletteCommandInputEventHandler(this));
}
use of org.osate.ge.internal.services.ColoringService in project osate2 by osate.
the class CreateEndToEndFlowSpecificationTool method activated.
@Override
public void activated(final ActivatedEvent ctx) {
final UiService uiService = ctx.getUiService();
try {
ctx.getSelectedBoc().ifPresent(selectedBoc -> {
final AadlModificationService aadlModService = ctx.getAadlModificatonService();
final ColoringService coloringService = ctx.getColoringService();
// Check for existing errors and warnings
final Set<Diagnostic> diagnostics = ToolUtil.getAllReferencedPackageDiagnostics(selectedBoc);
// Do not allow tool activation if there are errors in the models
final Set<Diagnostic> errors = FlowDialogUtil.getErrors(diagnostics);
if (!errors.isEmpty()) {
Display.getDefault().asyncExec(() -> new FlowDialogUtil.ErrorDialog("The Create End-To-End", errors).open());
} else {
// Create a coloring object that will allow adjustment of pictogram
coloring = coloringService.adjustColors();
// Create and update based on current selection
createFlowDialog.create();
if (segmentSelections.isEmpty() && modeFeatureSelections.isEmpty()) {
update(Collections.singletonList(selectedBoc));
} else {
final Iterator<SegmentData> segmentIt = segmentSelections.iterator();
while (segmentIt.hasNext()) {
final SegmentData segmentData = segmentIt.next();
setColor(segmentData, Color.MAGENTA.darker());
}
for (Iterator<BusinessObjectContext> modeFeatureIt = modeFeatureSelections.iterator(); modeFeatureIt.hasNext(); setColor(modeFeatureIt.next(), Color.MAGENTA.brighter())) {
}
update();
}
if (createFlowDialog.open() == Window.OK && createFlowDialog != null) {
createFlowDialog.getFlow().ifPresent(endToEndFlow -> {
if (createFlowDialog.eteFlowToEdit != null) {
// Editing end to end flow
final EndToEndFlow endToEndFlowToEdit = (EndToEndFlow) createFlowDialog.eteFlowToEdit;
aadlModService.modify(endToEndFlowToEdit, eTEFlowToEdit -> {
eTEFlowToEdit.getAllFlowSegments().clear();
eTEFlowToEdit.getAllFlowSegments().addAll(endToEndFlow.getAllFlowSegments());
eTEFlowToEdit.setName(endToEndFlow.getName());
eTEFlowToEdit.getInModeOrTransitions().clear();
eTEFlowToEdit.getInModeOrTransitions().addAll(endToEndFlow.getInModeOrTransitions());
});
} else {
// Creating end to end flow
createFlowDialog.getOwnerComponentImplementation().ifPresent(ownerCi -> {
aadlModService.modify(ownerCi, ci -> {
ci.getOwnedEndToEndFlows().add(endToEndFlow);
ci.setNoFlows(false);
});
});
}
});
}
}
});
} finally {
uiService.deactivateActiveTool();
}
}
use of org.osate.ge.internal.services.ColoringService in project osate2 by osate.
the class CreateFlowImplementationTool method activated.
@Override
public void activated(final ActivatedEvent ctx) {
final UiService uiService = ctx.getUiService();
try {
ctx.getSelectedBoc().ifPresent(selectedBoc -> {
final AadlModificationService aadlModService = ctx.getAadlModificatonService();
final ColoringService coloringService = ctx.getColoringService();
// Check for existing errors and warnings
final Set<Diagnostic> diagnostics = ToolUtil.getAllReferencedPackageDiagnostics(selectedBoc);
// Do not allow tool activation if there are errors in the models
final Set<Diagnostic> errors = FlowDialogUtil.getErrors(diagnostics);
if (!errors.isEmpty()) {
Display.getDefault().asyncExec(() -> new FlowDialogUtil.ErrorDialog("The Create Flow Implementation", errors).open());
} else {
coloring = coloringService.adjustColors();
// Create and update based on current selection
createFlowImplDlg.create();
if (segmentSelections.isEmpty() && modeFeatureSelections.isEmpty()) {
update(Collections.singletonList(selectedBoc), true);
} else {
final Iterator<SegmentData> segmentIt = segmentSelections.iterator();
if (segmentIt.hasNext()) {
// Set color for flow spec
setColor(segmentIt.next().getBoc(), Color.ORANGE.darker());
// Set color for flow segments
while (segmentIt.hasNext()) {
setColor(segmentIt.next().getBoc(), Color.MAGENTA.darker());
}
}
// Set color for in mode and mode transitions
for (Iterator<BusinessObjectContext> modeFeatureIt = modeFeatureSelections.iterator(); modeFeatureIt.hasNext(); setColor(modeFeatureIt.next(), Color.MAGENTA.brighter())) {
}
}
if (createFlowImplDlg.open() == Window.OK && createFlowImplDlg != null) {
final BusinessObjectContext ownerBoc = createFlowImplDlg.getOwnerBoc().orElse(null);
// Create a new flow impl based on selections
final FlowImplementation flowImpl = createFlowImplDlg.createFlow(ownerBoc);
createFlowImplDlg.getFlowComponentImplementation(ownerBoc).ifPresent(ownerCi -> {
// Modifications to perform
final List<AadlModificationService.Modification<? extends NamedElement, ? extends NamedElement>> modifications = new ArrayList<>();
if (createFlowImplDlg.flowImplToEdit != null) {
// Editing existing flow impl
final FlowImplementation flowImplToEdit = createFlowImplDlg.flowImplToEdit;
// Copy owned property associations from old flow impl to new flow impl and remove old flow impl
modifications.add(Modification.create(flowImplToEdit, fi -> {
flowImpl.getOwnedPropertyAssociations().addAll(EcoreUtil.copyAll(fi.getOwnedPropertyAssociations()));
EcoreUtil.remove(fi);
}));
}
// Add new flow impl
modifications.add(Modification.create(ownerCi, ci -> {
ci.getOwnedFlowImplementations().add(flowImpl);
ci.setNoFlows(false);
}));
// Perform modifications
aadlModService.modify(modifications);
});
}
}
});
} finally {
uiService.deactivateActiveTool();
}
}
Aggregations