/
EcoreInitDiagramFileAction.java
82 lines (68 loc) · 2.82 KB
/
EcoreInitDiagramFileAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*******************************************************************************
* Copyright (c) 2014, 2023 Obeo.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.ecoretools.design.ui.action;
import java.util.Collection;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecoretools.design.ui.wizard.InitializeEcoreDiagramWizard;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import com.google.common.collect.Lists;
public class EcoreInitDiagramFileAction implements IObjectActionDelegate {
private IWorkbenchPart targetPart;
private Collection<URI> domainModelURI = Lists.newArrayList();
private IProject containingProject;
private IStructuredSelection selection;
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
this.targetPart = targetPart;
}
public void selectionChanged(IAction action, ISelection selection) {
domainModelURI.clear();
action.setEnabled(false);
if (selection instanceof IStructuredSelection == false || selection.isEmpty()) {
return;
}
this.selection = (IStructuredSelection) selection;
if (this.selection.getFirstElement() instanceof IFile) {
IFile file = (IFile) this.selection.getFirstElement();
containingProject = file.getProject();
domainModelURI.add(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
action.setEnabled(true);
IFile genmodel = containingProject
.getFile(file.getProjectRelativePath().removeFileExtension().addFileExtension("genmodel"));
if (genmodel.exists() && genmodel.isAccessible()) {
domainModelURI.add(URI.createPlatformResourceURI(genmodel.getFullPath().toString(), true));
}
}
}
private Shell getShell() {
return targetPart.getSite().getShell();
}
public void run(IAction action) {
openCreateRepresentationWizard();
}
protected void openCreateRepresentationWizard() {
InitializeEcoreDiagramWizard wizard = new InitializeEcoreDiagramWizard(selection, domainModelURI,
containingProject);
wizard.init();
final WizardDialog dialog = new WizardDialog(getShell(), wizard);
dialog.setPageSize(750, 400);
dialog.create();
dialog.getShell().setText("Create Representation Wizard");
dialog.open();
}
}