use of org.eclipse.sirius.viewpoint.DRepresentation in project Palladio-Editors-Sirius by PalladioSimulator.
the class OpenRepresentation method execute.
@Override
public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {
EObject semantic = (EObject) parameters.get("element");
Session session = SessionManager.INSTANCE.getSession(semantic);
String viewpointName = (String) parameters.get("Viewpoint");
String representationDescriptionName = (String) parameters.get("RepresentationDescription");
String diagramName = (String) parameters.get("Diagram name");
// Select viewpoint
List<String> selectedViewpoints = new ArrayList<String>();
selectedViewpoints.add(viewpointName);
SiriusCustomUtil.selectViewpoints(session, selectedViewpoints, false, new NullProgressMonitor());
// Getting selected viewpoint and representation
Viewpoint viewpoint = SiriusCustomUtil.getSelectedViewpointByName(session, viewpointName);
RepresentationDescription description = SiriusCustomUtil.findDescription(viewpoint, representationDescriptionName);
// Find representations
Collection<DRepresentation> representations = DialectManager.INSTANCE.getRepresentations(semantic, session);
// create a new representation if none exists and open it
if (representations.isEmpty()) {
String representationName = null;
if (diagramName != null && !diagramName.isEmpty()) {
representationName = diagramName;
} else {
representationName = ((description.getLabel() == null) ? description.getName() : description.getLabel());
}
DRepresentation representation = SiriusCustomUtil.createRepresentation(session, representationName, description, semantic, new NullProgressMonitor());
DialectUIManager.INSTANCE.openEditor(session, representation, new NullProgressMonitor());
} else {
// open available representations
for (DRepresentation representation : representations) {
DialectUIManager.INSTANCE.openEditor(session, representation, new NullProgressMonitor());
}
}
}
use of org.eclipse.sirius.viewpoint.DRepresentation in project Palladio-Editors-Sirius by PalladioSimulator.
the class NewModelWizard method createModel.
private void createModel(final IProject project, final boolean createRepresentation, final String representationName, final IProgressMonitor monitor) throws CoreException {
monitor.beginTask("Creating Model File", 6000);
if (!project.hasNature(ModelingProject.NATURE_ID)) {
ModelingProjectManager.INSTANCE.convertToModelingProject(project, SubMonitor.convert(monitor, "Converting to Modeling Project", 1000));
}
final URI representationsURI = SiriusCustomUtil.getRepresentationsURI(project);
final Session session = SessionManager.INSTANCE.getSession(representationsURI, SubMonitor.convert(monitor, "Getting Session", 1000));
createResource(session, SubMonitor.convert(monitor, "Creating Resource", 1000));
HashSet<Viewpoint> selectedViewpoints = new HashSet<Viewpoint>();
selectedViewpoints.add(viewpoint);
SiriusCustomUtil.selectViewpoints(session, selectedViewpoints, false, SubMonitor.convert(monitor, "Selecting Viewpoint", 1000));
// Apparently the selected viewpoint's instance is not the same as the passed instance
// We retrieve here the actually selected Viewpoint
Viewpoint selectedViewpoint = SiriusCustomUtil.getSelectedViewpointByName(session, viewpoint.getName());
RepresentationDescription actualRepresentationDescription = SiriusCustomUtil.findDescription(selectedViewpoint, representationDescription.getName());
if (createRepresentation) {
final DRepresentation createdRepresentation = SiriusCustomUtil.createRepresentation(session, representationName, actualRepresentationDescription, this.modelObject, SubMonitor.convert(monitor, "Creating Representation", 1000));
DialectUIManager.INSTANCE.openEditor(session, createdRepresentation, SubMonitor.convert(monitor, "Opening representation", 1000));
}
monitor.done();
}
use of org.eclipse.sirius.viewpoint.DRepresentation in project InformationSystem by ObeoNetwork.
the class BindingService method openBindingEditor.
public BindingInfo openBindingEditor(BindingInfo bindingInfo) {
DBindingEditor editor = null;
final Session session = SessionManager.INSTANCE.getSession(bindingInfo);
// Find an editor to open
Collection<DRepresentation> representations = DialectManager.INSTANCE.getRepresentations(bindingInfo, session);
for (DRepresentation representation : representations) {
if (representation instanceof DBindingEditor) {
editor = (DBindingEditor) representation;
break;
}
}
// Create an editor if needed
if (editor == null) {
RepresentationDescription representationDescription = getBindingEditorRepresentation(session);
if (representationDescription != null) {
DRepresentation representation = DialectManager.INSTANCE.createRepresentation(computeBindingEditorName(bindingInfo), bindingInfo, representationDescription, session, new NullProgressMonitor());
if (representation != null && representation instanceof DBindingEditor) {
editor = (DBindingEditor) representation;
}
}
}
// Open the editor
if (editor != null) {
UserSession.from(session).openRepresentation(new StructuredSelection(editor));
}
return bindingInfo;
}
use of org.eclipse.sirius.viewpoint.DRepresentation in project InformationSystem by ObeoNetwork.
the class CreateSequenceDiagramAction method run.
@Override
public void run() {
if (context == null) {
return;
}
final Shell shell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
Session session = SessionManager.INSTANCE.getSession(context);
if (session == null) {
return;
}
TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
if (editingDomain == null) {
return;
}
RecordingCommand cmd = new RecordingCommand(editingDomain, "Create Sequence diagram") {
protected void doExecute() {
// Get Session
Session session = SessionManager.INSTANCE.getSession(context);
if (session != null) {
// Ask the user to provide a name for the diagram
InputDialog dialog = new InputDialog(shell, "New representation", "New representation name", "new Sequence diagram", null);
int buttonPressed = dialog.open();
if (buttonPressed == InputDialog.OK) {
String diagramName = dialog.getValue();
// Create a new interaction instance
Interaction interaction = InteractionFactory.eINSTANCE.createInteraction();
interaction.setName(diagramName);
context.getBehaviours().add(interaction);
Collection<RepresentationDescription> descs = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), interaction);
for (RepresentationDescription desc : descs) {
Viewpoint viewpoint = (Viewpoint) desc.eContainer();
if (InteractionAnalysisContextMenuActionProvider.isInteractionViewpoint(viewpoint) && "Sequence Diagram".equals(desc.getName())) {
// Create the new diagram
if (DialectManager.INSTANCE.canCreate(interaction, desc)) {
DRepresentation sequenceDiagram = DialectManager.INSTANCE.createRepresentation(diagramName, interaction, desc, session, new NullProgressMonitor());
if (sequenceDiagram != null) {
DialectUIManager.INSTANCE.openEditor(session, sequenceDiagram, new NullProgressMonitor());
}
}
}
}
}
}
}
};
editingDomain.getCommandStack().execute(cmd);
}
use of org.eclipse.sirius.viewpoint.DRepresentation in project InformationSystem by ObeoNetwork.
the class CreateStateMachineDiagramAction method run.
@Override
public void run() {
if (context == null) {
return;
}
final Shell shell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
// TransactionalEditingDomain editingDomain = EditingDomainService.getInstance().getEditingDomainProvider().getEditingDomain();
Session session = SessionManager.INSTANCE.getSession(context);
if (session == null) {
return;
}
TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
if (editingDomain == null) {
return;
}
RecordingCommand cmd = new RecordingCommand(editingDomain, "Create Sequence diagram") {
protected void doExecute() {
// Get Session
Session session = SessionManager.INSTANCE.getSession(context);
if (session != null) {
// Ask the user to provide a name for the diagram
InputDialog dialog = new InputDialog(shell, "New representation", "New representation name", "new State machine diagram", null);
int buttonPressed = dialog.open();
if (buttonPressed == InputDialog.OK) {
String diagramName = dialog.getValue();
// Create a new state machine instance
StateMachine statemachine = StateMachineFactory.eINSTANCE.createStateMachine();
statemachine.setName(diagramName);
context.getBehaviours().add(statemachine);
Collection<RepresentationDescription> descs = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), statemachine);
for (RepresentationDescription desc : descs) {
Viewpoint viewpoint = (Viewpoint) desc.eContainer();
if (StateMachineAnalysisContextMenuActionProvider.isStateMachineViewpoint(viewpoint) && "State Machine Diagram".equals(desc.getName())) {
// Create the new diagram
if (DialectManager.INSTANCE.canCreate(statemachine, desc)) {
DRepresentation stateMachineDiagram = DialectManager.INSTANCE.createRepresentation(diagramName, statemachine, desc, session, new NullProgressMonitor());
if (stateMachineDiagram != null) {
DialectUIManager.INSTANCE.openEditor(session, stateMachineDiagram, new NullProgressMonitor());
}
}
}
}
}
}
}
};
editingDomain.getCommandStack().execute(cmd);
}
Aggregations