Skip to content
Snippets Groups Projects
Commit 24d14873 authored by Alberto Debiasi's avatar Alberto Debiasi
Browse files

Add missing headers with ELP 2.0 license.

Change-Id: Ic79abc870bf93096fa9eb07d138ac7d2c2d6c647
parent f4e0cd59
No related branches found
No related tags found
No related merge requests found
Showing
with 2190 additions and 2050 deletions
package org.polarsys.chess.cdo;
import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.polarsys.chess.cdo"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/** Logging helper */
public static LogHelper log = new LogHelper();
/**
* The constructor
*/
public Activator() {
super();
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
// register the log helper
log.setPlugin(plugin);
}
@Override
public void stop(BundleContext context) throws Exception {
log = null;
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.cdo;
import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.polarsys.chess.cdo"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/** Logging helper */
public static LogHelper log = new LogHelper();
/**
* The constructor
*/
public Activator() {
super();
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
// register the log helper
log.setPlugin(plugin);
}
@Override
public void stop(BundleContext context) throws Exception {
log = null;
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
package org.polarsys.chess.cdo.dialogs;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.polarsys.chess.cdo.dialogs.utils.DialogUtil;
import org.polarsys.chess.cdo.providers.CDOResourceListLabelProvider;
import org.polarsys.chess.cdo.providers.CHESSProjectListLabelProvider;
public class CDOExportDialog extends TitleAreaDialog {
private static final String CHESS_NATURE = "org.polarsys.chess.CHESSNature";
private ComboViewer chessModelsCombo;
private ComboViewer cdoFoldersCombo;
private CDOView view;
private CDOTransaction transaction;
private IProject selectedCHESSProject;
private CDOResourceFolder selectedCDOFolder;
public CDOExportDialog(Shell shell) throws Exception{
super(shell);
CDOConnectionUtil.instance.init(
//TODO These three lines should be kept if the preference page is available
PreferenceConstants.getRepositoryName(),
PreferenceConstants.getProtocol(),
PreferenceConstants.getServerName()
// "repo",
// "tcp",
// "localhost"
);
CDOSession session = CDOConnectionUtil.instance.openSession();
transaction = CDOConnectionUtil.instance.openTransaction(session);
view = CDOConnectionUtil.instance.openView(session);
}
@Override
public void create() {
setHelpAvailable(false);
super.create();
setTitle("Export CHESS project to CDO");
setMessage("Select CHESS project and CDO folder and click OK to perform the export", IMessageProvider.INFORMATION);
}
@Override
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(2, false));
Label chessModelsLabel = new Label(parent, SWT.NONE);
chessModelsLabel.setText("Select a CHESS project: ");
chessModelsCombo = new ComboViewer(parent, SWT.NONE);
chessModelsCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
chessModelsCombo.setContentProvider(new ArrayContentProvider());
chessModelsCombo.setLabelProvider(new CHESSProjectListLabelProvider());
Label cdoFoldersLabel = new Label(parent, SWT.NONE);
cdoFoldersLabel.setText("Select the target CDO Folder: ");
cdoFoldersCombo = new ComboViewer(parent, SWT.NONE);
cdoFoldersCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
cdoFoldersCombo.setContentProvider(new ArrayContentProvider());
cdoFoldersCombo.setLabelProvider(new CDOResourceListLabelProvider());
addCHESSModelsFromWorkspace();
addCDOFoldersFromRepository();
return super.createDialogArea(parent);
}
private void addCDOFoldersFromRepository() {
List<CDOResourceFolder> folderList = DialogUtil.getAllFolders(view);
cdoFoldersCombo.setInput(folderList.toArray());
cdoFoldersCombo.setComparator(new ViewerComparator() {
public int compare(
Viewer viewer, Object c1, Object c2) {
return ((CDOResourceFolder) c1).getPath().compareToIgnoreCase(((CDOResourceFolder) c2).getPath());
}
});
}
private void addCHESSModelsFromWorkspace() {
List<IProject> chessProjects = new ArrayList<>();
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for(IProject project : projects){
try {
if(project.isOpen() && project.hasNature(CHESS_NATURE)){
chessProjects.add(project);
}
} catch (CoreException e) {
e.printStackTrace();
}
}
chessModelsCombo.setInput(chessProjects.toArray());
chessModelsCombo.setComparator(new ViewerComparator() {
public int compare(
Viewer viewer, Object c1, Object c2) {
return ((IProject) c1).getName().compareToIgnoreCase(((IProject) c2).getName());
}
});
}
@Override
protected boolean isResizable() {
return true;
}
@Override
protected void okPressed() {
IProject chessProject = (IProject)((IStructuredSelection)chessModelsCombo.getSelection()).getFirstElement();
CDOResourceFolder cdoFolder = (CDOResourceFolder)((IStructuredSelection)cdoFoldersCombo.getSelection()).getFirstElement();
if(chessProject == null || cdoFolder == null){
setMessage("Please select CHESS model and CDO Folder!", IMessageProvider.ERROR);
}else{
setSelectedCHESSProject(chessProject);
setSelectedCDOFolder(cdoFolder);
super.okPressed();
}
}
public IProject getSelectedCHESSProject() {
return selectedCHESSProject;
}
public void setSelectedCHESSProject(IProject selectedCHESSProject) {
this.selectedCHESSProject = selectedCHESSProject;
}
public CDOResourceFolder getSelectedCDOFolder() {
return selectedCDOFolder;
}
public void setSelectedCDOFolder(CDOResourceFolder selectedCDOFolder) {
this.selectedCDOFolder = selectedCDOFolder;
}
public CDOTransaction getTransaction() {
return transaction;
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.cdo.dialogs;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.polarsys.chess.cdo.dialogs.utils.DialogUtil;
import org.polarsys.chess.cdo.providers.CDOResourceListLabelProvider;
import org.polarsys.chess.cdo.providers.CHESSProjectListLabelProvider;
public class CDOExportDialog extends TitleAreaDialog {
private static final String CHESS_NATURE = "org.polarsys.chess.CHESSNature";
private ComboViewer chessModelsCombo;
private ComboViewer cdoFoldersCombo;
private CDOView view;
private CDOTransaction transaction;
private IProject selectedCHESSProject;
private CDOResourceFolder selectedCDOFolder;
public CDOExportDialog(Shell shell) throws Exception{
super(shell);
CDOConnectionUtil.instance.init(
//TODO These three lines should be kept if the preference page is available
PreferenceConstants.getRepositoryName(),
PreferenceConstants.getProtocol(),
PreferenceConstants.getServerName()
// "repo",
// "tcp",
// "localhost"
);
CDOSession session = CDOConnectionUtil.instance.openSession();
transaction = CDOConnectionUtil.instance.openTransaction(session);
view = CDOConnectionUtil.instance.openView(session);
}
@Override
public void create() {
setHelpAvailable(false);
super.create();
setTitle("Export CHESS project to CDO");
setMessage("Select CHESS project and CDO folder and click OK to perform the export", IMessageProvider.INFORMATION);
}
@Override
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(2, false));
Label chessModelsLabel = new Label(parent, SWT.NONE);
chessModelsLabel.setText("Select a CHESS project: ");
chessModelsCombo = new ComboViewer(parent, SWT.NONE);
chessModelsCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
chessModelsCombo.setContentProvider(new ArrayContentProvider());
chessModelsCombo.setLabelProvider(new CHESSProjectListLabelProvider());
Label cdoFoldersLabel = new Label(parent, SWT.NONE);
cdoFoldersLabel.setText("Select the target CDO Folder: ");
cdoFoldersCombo = new ComboViewer(parent, SWT.NONE);
cdoFoldersCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
cdoFoldersCombo.setContentProvider(new ArrayContentProvider());
cdoFoldersCombo.setLabelProvider(new CDOResourceListLabelProvider());
addCHESSModelsFromWorkspace();
addCDOFoldersFromRepository();
return super.createDialogArea(parent);
}
private void addCDOFoldersFromRepository() {
List<CDOResourceFolder> folderList = DialogUtil.getAllFolders(view);
cdoFoldersCombo.setInput(folderList.toArray());
cdoFoldersCombo.setComparator(new ViewerComparator() {
public int compare(
Viewer viewer, Object c1, Object c2) {
return ((CDOResourceFolder) c1).getPath().compareToIgnoreCase(((CDOResourceFolder) c2).getPath());
}
});
}
private void addCHESSModelsFromWorkspace() {
List<IProject> chessProjects = new ArrayList<>();
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
for(IProject project : projects){
try {
if(project.isOpen() && project.hasNature(CHESS_NATURE)){
chessProjects.add(project);
}
} catch (CoreException e) {
e.printStackTrace();
}
}
chessModelsCombo.setInput(chessProjects.toArray());
chessModelsCombo.setComparator(new ViewerComparator() {
public int compare(
Viewer viewer, Object c1, Object c2) {
return ((IProject) c1).getName().compareToIgnoreCase(((IProject) c2).getName());
}
});
}
@Override
protected boolean isResizable() {
return true;
}
@Override
protected void okPressed() {
IProject chessProject = (IProject)((IStructuredSelection)chessModelsCombo.getSelection()).getFirstElement();
CDOResourceFolder cdoFolder = (CDOResourceFolder)((IStructuredSelection)cdoFoldersCombo.getSelection()).getFirstElement();
if(chessProject == null || cdoFolder == null){
setMessage("Please select CHESS model and CDO Folder!", IMessageProvider.ERROR);
}else{
setSelectedCHESSProject(chessProject);
setSelectedCDOFolder(cdoFolder);
super.okPressed();
}
}
public IProject getSelectedCHESSProject() {
return selectedCHESSProject;
}
public void setSelectedCHESSProject(IProject selectedCHESSProject) {
this.selectedCHESSProject = selectedCHESSProject;
}
public CDOResourceFolder getSelectedCDOFolder() {
return selectedCDOFolder;
}
public void setSelectedCDOFolder(CDOResourceFolder selectedCDOFolder) {
this.selectedCDOFolder = selectedCDOFolder;
}
public CDOTransaction getTransaction() {
return transaction;
}
}
package org.polarsys.chess.cdo.dialogs;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.cdo.common.lob.CDOBlob;
import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
import org.eclipse.emf.cdo.eresource.CDOBinaryResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.polarsys.chess.cdo.dialogs.utils.DialogUtil;
import org.polarsys.chess.cdo.providers.CDOResourceListLabelProvider;
public class CDOImportDialog extends TitleAreaDialog {
private CDOView view;
private CDOTransaction transaction;
private ComboViewer cdoCHESSProjectsCombo;
private Text projectNameText;
private String newProjectName;
private CDOResourceFolder selectedCHESSProjectCDO;
public CDOImportDialog(Shell shell) {
super(shell);
CDOConnectionUtil.instance.init(
//TODO These three lines should be kept if the preference page is available
PreferenceConstants.getRepositoryName(),
PreferenceConstants.getProtocol(),
PreferenceConstants.getServerName()
// "repo",
// "tcp",
// "localhost"
);
CDOSession session = CDOConnectionUtil.instance.openSession();
transaction = CDOConnectionUtil.instance.openTransaction(session);
view = CDOConnectionUtil.instance.openView(session);
}
@Override
public void create() {
setHelpAvailable(false);
super.create();
setTitle("Import CHESS project from CDO");
setMessage("Select a CHESS project from the CDO repository. Enter the project name and click OK to perform the import", IMessageProvider.INFORMATION);
}
@Override
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(2, false));
Label chessModelsLabel = new Label(parent, SWT.NONE);
chessModelsLabel.setText("Select a CHESS project: ");
cdoCHESSProjectsCombo = new ComboViewer(parent, SWT.NONE);
cdoCHESSProjectsCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
cdoCHESSProjectsCombo.setContentProvider(new ArrayContentProvider());
cdoCHESSProjectsCombo.setLabelProvider(new CDOResourceListLabelProvider());
ISelectionChangedListener listener = new ISelectionChangedListener(){
@Override
public void selectionChanged(SelectionChangedEvent event) {
String text = cdoCHESSProjectsCombo.getCombo().getText();
text = text.substring(text.lastIndexOf(File.separator)+1);
projectNameText.setText(text);
}
};
cdoCHESSProjectsCombo.addSelectionChangedListener(listener);
Label cdoFoldersLabel = new Label(parent, SWT.NONE);
cdoFoldersLabel.setText("Enter the Project Name: ");
projectNameText = new Text(parent, SWT.BORDER);
projectNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
projectNameText.setText("");
addCHESSProjectsFromCDORepository();
return super.createDialogArea(parent);
}
private void addCHESSProjectsFromCDORepository() {
List<CDOResourceFolder> folderList = DialogUtil.getAllFolders(view);
List<CDOResourceFolder> chessProjectsCDO = new ArrayList<>();
for(CDOResourceFolder folder : folderList){
// System.out.println(folder.getName());
EList<CDOResourceNode> nodes = folder.getNodes();
for(CDOResourceNode node : nodes){
// System.out.println("--> " + node.toString());
if(node instanceof CDOBinaryResource && node.getName().equals(".project")){
CDOBinaryResource projectRes = (CDOBinaryResource) node;
CDOBlob contents = projectRes.getContents();
// System.out.println("----> " + contents.toString());
if(contents != null){
try {
InputStream is = contents.getContents();
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[(int) contents.getSize()];
int length;
while ((length = is.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
String contentsAsString = result.toString("UTF-8");
// System.out.println("------------> " + contentsAsString);
if (contentsAsString.contains("org.polarsys.chess.CHESSNature")){
chessProjectsCDO.add(folder);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
cdoCHESSProjectsCombo.setInput(chessProjectsCDO.toArray());
cdoCHESSProjectsCombo.setComparator(new ViewerComparator() {
public int compare(
Viewer viewer, Object c1, Object c2) {
return ((CDOResourceFolder) c1).getPath().compareToIgnoreCase(((CDOResourceFolder) c2).getPath());
}
});
}
@Override
protected boolean isResizable() {
return true;
}
@Override
protected void okPressed() {
CDOResourceFolder cdoCHESSFolder = (CDOResourceFolder)((IStructuredSelection)cdoCHESSProjectsCombo.getSelection()).getFirstElement();
String projectName = projectNameText.getText();
if(cdoCHESSFolder == null || projectName == null || projectName.isEmpty()){
setMessage("Please select CHESS project (from CDO) and enter the name of the new project!", IMessageProvider.ERROR);
}else{
setNewProjectName(projectName);
setSelectedCHESSProjectCDO(cdoCHESSFolder);
super.okPressed();
}
}
public CDOResourceFolder getSelectedCHESSProjectCDO() {
return selectedCHESSProjectCDO;
}
public void setSelectedCHESSProjectCDO(CDOResourceFolder selectedCHESSProjectCDO) {
this.selectedCHESSProjectCDO = selectedCHESSProjectCDO;
}
public String getNewProjectName() {
return newProjectName;
}
public void setNewProjectName(String newProjectName) {
this.newProjectName = newProjectName;
}
public CDOTransaction getTransaction() {
return transaction;
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.cdo.dialogs;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.cdo.common.lob.CDOBlob;
import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants;
import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil;
import org.eclipse.emf.cdo.eresource.CDOBinaryResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.polarsys.chess.cdo.dialogs.utils.DialogUtil;
import org.polarsys.chess.cdo.providers.CDOResourceListLabelProvider;
public class CDOImportDialog extends TitleAreaDialog {
private CDOView view;
private CDOTransaction transaction;
private ComboViewer cdoCHESSProjectsCombo;
private Text projectNameText;
private String newProjectName;
private CDOResourceFolder selectedCHESSProjectCDO;
public CDOImportDialog(Shell shell) {
super(shell);
CDOConnectionUtil.instance.init(
//TODO These three lines should be kept if the preference page is available
PreferenceConstants.getRepositoryName(),
PreferenceConstants.getProtocol(),
PreferenceConstants.getServerName()
// "repo",
// "tcp",
// "localhost"
);
CDOSession session = CDOConnectionUtil.instance.openSession();
transaction = CDOConnectionUtil.instance.openTransaction(session);
view = CDOConnectionUtil.instance.openView(session);
}
@Override
public void create() {
setHelpAvailable(false);
super.create();
setTitle("Import CHESS project from CDO");
setMessage("Select a CHESS project from the CDO repository. Enter the project name and click OK to perform the import", IMessageProvider.INFORMATION);
}
@Override
protected Control createDialogArea(Composite parent) {
parent.setLayout(new GridLayout(2, false));
Label chessModelsLabel = new Label(parent, SWT.NONE);
chessModelsLabel.setText("Select a CHESS project: ");
cdoCHESSProjectsCombo = new ComboViewer(parent, SWT.NONE);
cdoCHESSProjectsCombo.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
cdoCHESSProjectsCombo.setContentProvider(new ArrayContentProvider());
cdoCHESSProjectsCombo.setLabelProvider(new CDOResourceListLabelProvider());
ISelectionChangedListener listener = new ISelectionChangedListener(){
@Override
public void selectionChanged(SelectionChangedEvent event) {
String text = cdoCHESSProjectsCombo.getCombo().getText();
text = text.substring(text.lastIndexOf(File.separator)+1);
projectNameText.setText(text);
}
};
cdoCHESSProjectsCombo.addSelectionChangedListener(listener);
Label cdoFoldersLabel = new Label(parent, SWT.NONE);
cdoFoldersLabel.setText("Enter the Project Name: ");
projectNameText = new Text(parent, SWT.BORDER);
projectNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
projectNameText.setText("");
addCHESSProjectsFromCDORepository();
return super.createDialogArea(parent);
}
private void addCHESSProjectsFromCDORepository() {
List<CDOResourceFolder> folderList = DialogUtil.getAllFolders(view);
List<CDOResourceFolder> chessProjectsCDO = new ArrayList<>();
for(CDOResourceFolder folder : folderList){
// System.out.println(folder.getName());
EList<CDOResourceNode> nodes = folder.getNodes();
for(CDOResourceNode node : nodes){
// System.out.println("--> " + node.toString());
if(node instanceof CDOBinaryResource && node.getName().equals(".project")){
CDOBinaryResource projectRes = (CDOBinaryResource) node;
CDOBlob contents = projectRes.getContents();
// System.out.println("----> " + contents.toString());
if(contents != null){
try {
InputStream is = contents.getContents();
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[(int) contents.getSize()];
int length;
while ((length = is.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
String contentsAsString = result.toString("UTF-8");
// System.out.println("------------> " + contentsAsString);
if (contentsAsString.contains("org.polarsys.chess.CHESSNature")){
chessProjectsCDO.add(folder);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
cdoCHESSProjectsCombo.setInput(chessProjectsCDO.toArray());
cdoCHESSProjectsCombo.setComparator(new ViewerComparator() {
public int compare(
Viewer viewer, Object c1, Object c2) {
return ((CDOResourceFolder) c1).getPath().compareToIgnoreCase(((CDOResourceFolder) c2).getPath());
}
});
}
@Override
protected boolean isResizable() {
return true;
}
@Override
protected void okPressed() {
CDOResourceFolder cdoCHESSFolder = (CDOResourceFolder)((IStructuredSelection)cdoCHESSProjectsCombo.getSelection()).getFirstElement();
String projectName = projectNameText.getText();
if(cdoCHESSFolder == null || projectName == null || projectName.isEmpty()){
setMessage("Please select CHESS project (from CDO) and enter the name of the new project!", IMessageProvider.ERROR);
}else{
setNewProjectName(projectName);
setSelectedCHESSProjectCDO(cdoCHESSFolder);
super.okPressed();
}
}
public CDOResourceFolder getSelectedCHESSProjectCDO() {
return selectedCHESSProjectCDO;
}
public void setSelectedCHESSProjectCDO(CDOResourceFolder selectedCHESSProjectCDO) {
this.selectedCHESSProjectCDO = selectedCHESSProjectCDO;
}
public String getNewProjectName() {
return newProjectName;
}
public void setNewProjectName(String newProjectName) {
this.newProjectName = newProjectName;
}
public CDOTransaction getTransaction() {
return transaction;
}
}
package org.polarsys.chess.cdo.dialogs.utils;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.common.util.EList;
public class DialogUtil {
public static List<CDOResourceFolder> getAllFolders(CDOView view) {
List<CDOResourceFolder> folderList = new ArrayList<>();
CDOResourceNode[] cdoElements = view.getElements();
for(CDOResourceNode cdoElem : cdoElements){
if(cdoElem instanceof CDOResourceFolder){
CDOResourceFolder cdoFolder = (CDOResourceFolder)cdoElem;
folderList.add(cdoFolder);
//check for subfolders
EList<CDOResourceNode> subNodes = cdoFolder.getNodes();
folderList = getSubFolders(subNodes,folderList);
}
}
return folderList;
}
private static List<CDOResourceFolder> getSubFolders(EList<CDOResourceNode> nodes, List<CDOResourceFolder> folderList) {
for(CDOResourceNode cdoElem : nodes){
if(cdoElem instanceof CDOResourceFolder){
CDOResourceFolder cdoFolder = (CDOResourceFolder)cdoElem;
folderList.add(cdoFolder);
//check for subfolders
EList<CDOResourceNode> subNodes = cdoFolder.getNodes();
folderList = getSubFolders(subNodes,folderList);
}
}
return folderList;
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.cdo.dialogs.utils;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.emf.common.util.EList;
public class DialogUtil {
public static List<CDOResourceFolder> getAllFolders(CDOView view) {
List<CDOResourceFolder> folderList = new ArrayList<>();
CDOResourceNode[] cdoElements = view.getElements();
for(CDOResourceNode cdoElem : cdoElements){
if(cdoElem instanceof CDOResourceFolder){
CDOResourceFolder cdoFolder = (CDOResourceFolder)cdoElem;
folderList.add(cdoFolder);
//check for subfolders
EList<CDOResourceNode> subNodes = cdoFolder.getNodes();
folderList = getSubFolders(subNodes,folderList);
}
}
return folderList;
}
private static List<CDOResourceFolder> getSubFolders(EList<CDOResourceNode> nodes, List<CDOResourceFolder> folderList) {
for(CDOResourceNode cdoElem : nodes){
if(cdoElem instanceof CDOResourceFolder){
CDOResourceFolder cdoFolder = (CDOResourceFolder)cdoElem;
folderList.add(cdoFolder);
//check for subfolders
EList<CDOResourceNode> subNodes = cdoFolder.getNodes();
folderList = getSubFolders(subNodes,folderList);
}
}
return folderList;
}
}
package org.polarsys.chess.cdo.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.spi.transfer.FileSystemTransferSystem;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.transfer.CDOTransfer;
import org.eclipse.emf.cdo.transfer.CDOTransferElement;
import org.eclipse.emf.cdo.transfer.CDOTransferMapping;
import org.eclipse.emf.cdo.transfer.CDOTransferSystem;
import org.eclipse.emf.cdo.transfer.spi.repository.RepositoryTransferSystem;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.polarsys.chess.cdo.dialogs.CDOExportDialog;
public class CDOExportHandler extends AbstractHandler {
private String errorMsg = "";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if(window != null){
Shell shell = window.getShell();
//Show a dialog with a list of all the CHESS projects in the workspace and
//and a list of the CDO folders (from the configured CDO repo).
//get the selected project and CDO folder and perform the copy from workspace to CDO.
CDOExportDialog dialog = null;
try{
dialog = new CDOExportDialog(shell);
}catch (Exception e){
MessageDialog.openError(shell, "Export CHESS Project to CDO", "Error: " + e.getMessage());
}
if(dialog != null && dialog.open() == Window.OK){
CDOResourceFolder cdoFolder = dialog.getSelectedCDOFolder();
IProject chessProject = dialog.getSelectedCHESSProject();
if(cdoFolder != null && chessProject != null){
CDOTransaction transaction = dialog.getTransaction();
try{
String filepath = chessProject.getLocation().toString();
CDOTransferElement source = FileSystemTransferSystem.INSTANCE.getElement(new Path(filepath));
CDOTransferSystem target = new RepositoryTransferSystem(transaction);
CDOTransfer transfer = new CDOTransfer(source.getSystem(), target);
CDOTransferMapping mapping = transfer.map(filepath, new NullProgressMonitor());
mapping.setRelativePath(cdoFolder.getPath() + "/" + chessProject.getName());
transfer.perform();
transaction.commit();
transaction.close();
} catch (Exception e) {
e.printStackTrace();
errorMsg = e.getMessage();
}
}
}
if(errorMsg != null && !errorMsg.isEmpty()){
MessageDialog.openError(shell, "Export CHESS Project to CDO", "Error: " + errorMsg);
errorMsg = "";
}
}
return null;
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.cdo.handlers;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.spi.transfer.FileSystemTransferSystem;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.transfer.CDOTransfer;
import org.eclipse.emf.cdo.transfer.CDOTransferElement;
import org.eclipse.emf.cdo.transfer.CDOTransferMapping;
import org.eclipse.emf.cdo.transfer.CDOTransferSystem;
import org.eclipse.emf.cdo.transfer.spi.repository.RepositoryTransferSystem;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.polarsys.chess.cdo.dialogs.CDOExportDialog;
public class CDOExportHandler extends AbstractHandler {
private String errorMsg = "";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if(window != null){
Shell shell = window.getShell();
//Show a dialog with a list of all the CHESS projects in the workspace and
//and a list of the CDO folders (from the configured CDO repo).
//get the selected project and CDO folder and perform the copy from workspace to CDO.
CDOExportDialog dialog = null;
try{
dialog = new CDOExportDialog(shell);
}catch (Exception e){
MessageDialog.openError(shell, "Export CHESS Project to CDO", "Error: " + e.getMessage());
}
if(dialog != null && dialog.open() == Window.OK){
CDOResourceFolder cdoFolder = dialog.getSelectedCDOFolder();
IProject chessProject = dialog.getSelectedCHESSProject();
if(cdoFolder != null && chessProject != null){
CDOTransaction transaction = dialog.getTransaction();
try{
String filepath = chessProject.getLocation().toString();
CDOTransferElement source = FileSystemTransferSystem.INSTANCE.getElement(new Path(filepath));
CDOTransferSystem target = new RepositoryTransferSystem(transaction);
CDOTransfer transfer = new CDOTransfer(source.getSystem(), target);
CDOTransferMapping mapping = transfer.map(filepath, new NullProgressMonitor());
mapping.setRelativePath(cdoFolder.getPath() + "/" + chessProject.getName());
transfer.perform();
transaction.commit();
transaction.close();
} catch (Exception e) {
e.printStackTrace();
errorMsg = e.getMessage();
}
}
}
if(errorMsg != null && !errorMsg.isEmpty()){
MessageDialog.openError(shell, "Export CHESS Project to CDO", "Error: " + errorMsg);
errorMsg = "";
}
}
return null;
}
}
package org.polarsys.chess.cdo.handlers;
import java.io.File;
import java.net.URI;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.spi.transfer.FileSystemTransferSystem;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.transfer.CDOTransfer;
import org.eclipse.emf.cdo.transfer.CDOTransferElement;
import org.eclipse.emf.cdo.transfer.CDOTransferMapping;
import org.eclipse.emf.cdo.transfer.CDOTransferSystem;
import org.eclipse.emf.cdo.transfer.spi.repository.RepositoryTransferSystem;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.polarsys.chess.cdo.dialogs.CDOImportDialog;
import org.polarsys.chess.core.util.CHESSProjectSupport;
public class CDOImportHandler extends AbstractHandler {
private String errorMsg = "";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if(window != null){
Shell shell = window.getShell();
//Show a dialog with a list of all the CHESS projects in the configured CDO.
//get the selected CDO project and the entered name for the project (default same name?)
//perform the copy from CDO to workspace.
CDOImportDialog dialog = null;
try{
dialog = new CDOImportDialog(shell);
}catch (Exception e){
MessageDialog.openError(shell, "Import CHESS Project from CDO", "Error: " + e.getMessage());
}
if(dialog != null && dialog.open() == Window.OK){
CDOResourceFolder chessProjectCDO = dialog.getSelectedCHESSProjectCDO();
String projectName = dialog.getNewProjectName();
if(chessProjectCDO != null && projectName != null){
//create new CHESS project (if not already there)
try{
IProject chessProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if(chessProject == null || !chessProject.exists()){
IPath workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation();
URI location = URI.create(workspaceLocation + "/" + projectName);
chessProject=CHESSProjectSupport.createProject(projectName, null);
}else if(!chessProject.isOpen()){
chessProject.open(new NullProgressMonitor());
}
CDOTransaction transaction = dialog.getTransaction();
String filepath = chessProject.getLocation().toString();
// System.out.println(filepath.toString());
//ugly workaround to get relative path -- TODO: will it ever work on windows as well?
filepath = filepath.substring(System.getProperty("user.home").length()+1);
// System.out.println(filepath.toString());
CDOTransferSystem source = new RepositoryTransferSystem(transaction);
CDOTransferElement target = FileSystemTransferSystem.INSTANCE.getElement(chessProject.getLocation());
CDOTransfer transfer = new CDOTransfer(source, target.getSystem());
for(CDOResourceNode node : chessProjectCDO.getNodes()){
if(!node.getName().equals(".project")){
CDOTransferMapping mapping = transfer.map(node.getPath(), new NullProgressMonitor());
mapping.setRelativePath(filepath + File.separator + node.getName());
transfer.perform();
}
}
transaction.commit();
transaction.close();
} catch (Exception e) {
e.printStackTrace();
errorMsg = e.getMessage();
}
}
}
if(errorMsg != null && !errorMsg.isEmpty()){
MessageDialog.openError(shell, "Import CHESS Project from CDO", "Error: " + errorMsg);
errorMsg = "";
}
}
return null;
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.cdo.handlers;
import java.io.File;
import java.net.URI;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.spi.transfer.FileSystemTransferSystem;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
import org.eclipse.emf.cdo.transfer.CDOTransfer;
import org.eclipse.emf.cdo.transfer.CDOTransferElement;
import org.eclipse.emf.cdo.transfer.CDOTransferMapping;
import org.eclipse.emf.cdo.transfer.CDOTransferSystem;
import org.eclipse.emf.cdo.transfer.spi.repository.RepositoryTransferSystem;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.polarsys.chess.cdo.dialogs.CDOImportDialog;
import org.polarsys.chess.core.util.CHESSProjectSupport;
public class CDOImportHandler extends AbstractHandler {
private String errorMsg = "";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
if(window != null){
Shell shell = window.getShell();
//Show a dialog with a list of all the CHESS projects in the configured CDO.
//get the selected CDO project and the entered name for the project (default same name?)
//perform the copy from CDO to workspace.
CDOImportDialog dialog = null;
try{
dialog = new CDOImportDialog(shell);
}catch (Exception e){
MessageDialog.openError(shell, "Import CHESS Project from CDO", "Error: " + e.getMessage());
}
if(dialog != null && dialog.open() == Window.OK){
CDOResourceFolder chessProjectCDO = dialog.getSelectedCHESSProjectCDO();
String projectName = dialog.getNewProjectName();
if(chessProjectCDO != null && projectName != null){
//create new CHESS project (if not already there)
try{
IProject chessProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
if(chessProject == null || !chessProject.exists()){
IPath workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation();
URI location = URI.create(workspaceLocation + "/" + projectName);
chessProject=CHESSProjectSupport.createProject(projectName, null);
}else if(!chessProject.isOpen()){
chessProject.open(new NullProgressMonitor());
}
CDOTransaction transaction = dialog.getTransaction();
String filepath = chessProject.getLocation().toString();
// System.out.println(filepath.toString());
//ugly workaround to get relative path -- TODO: will it ever work on windows as well?
filepath = filepath.substring(System.getProperty("user.home").length()+1);
// System.out.println(filepath.toString());
CDOTransferSystem source = new RepositoryTransferSystem(transaction);
CDOTransferElement target = FileSystemTransferSystem.INSTANCE.getElement(chessProject.getLocation());
CDOTransfer transfer = new CDOTransfer(source, target.getSystem());
for(CDOResourceNode node : chessProjectCDO.getNodes()){
if(!node.getName().equals(".project")){
CDOTransferMapping mapping = transfer.map(node.getPath(), new NullProgressMonitor());
mapping.setRelativePath(filepath + File.separator + node.getName());
transfer.perform();
}
}
transaction.commit();
transaction.close();
} catch (Exception e) {
e.printStackTrace();
errorMsg = e.getMessage();
}
}
}
if(errorMsg != null && !errorMsg.isEmpty()){
MessageDialog.openError(shell, "Import CHESS Project from CDO", "Error: " + errorMsg);
errorMsg = "";
}
}
return null;
}
}
package org.polarsys.chess.cdo.providers;
import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.adapt;
import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.getSelectedResourceURI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
import org.eclipse.papyrus.cdo.internal.ui.editors.PapyrusCDOEditorInput;
import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
import org.eclipse.papyrus.uml.diagram.wizards.providers.AbstractNewModelStorageProvider;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.CreateModelWizard;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.InitModelWizard;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.INewWizard;
import org.polarsys.chess.cdo.pages.NewCHESSModelPage;
import org.polarsys.chess.cdo.wizards.CreateCDOCHESSModelWizard;
import org.polarsys.chess.wizards.wizards.CreateCHESSModelWizard;
import com.google.common.eventbus.EventBus;
public class CHESSCDONewModelStorageProvider extends AbstractNewModelStorageProvider {
private final EventBus bus = new EventBus("NewCDOModelWizard"); //$NON-NLS-1$
private CreateCDOCHESSModelWizard wizard;
private SelectDiagramCategoryPage newDiagramCategoryPage;
private NewCHESSModelPage newModelPage;
private IStructuredSelection selection;
public CHESSCDONewModelStorageProvider() {
super();
}
@Override
public boolean canHandle(IStructuredSelection initialSelection) {
for (Object next : initialSelection.toList()) {
if (CDOUtils.isCDOObject(adapt(next, EObject.class))) {
return true;
}
if (adapt(next, CDOCheckout.class) != null) {
return true;
}
}
return false;
}
public void init(CreateCDOCHESSModelWizard wizard, IStructuredSelection selection) {
// super.init(wizard, selection);
this.wizard = wizard;
this.selection = selection;
newModelPage = createNewModelPage(selection);
createSelectProviderPart();
CDOCheckout checkout = getRepository(selection);
if (checkout != null) {
bus.post(checkout);
}
// newDiagramCategoryPage = createNewDiagramCategoryPage(selection);
}
/**
* Gets the contextual repository, if any, from a selection.
*
* @param selection
* a selection
*
* @return the repository that is or contains the {@code selection}
*/
static CDOCheckout getRepository(IStructuredSelection selection) {
CDOCheckout result = null;
if (!selection.isEmpty()) {
result = adapt(selection.getFirstElement(), CDOCheckout.class);
if (result == null) {
CDOResourceNode node = adapt(selection.getFirstElement(), CDOResourceNode.class);
if (node == null) {
EObject object = adapt(selection.getFirstElement(), EObject.class);
if (object != null) {
CDOObject cdo = CDOUtils.getCDOObject(object);
if (cdo != null) {
node = cdo.cdoResource();
}
}
}
if (node != null) {
result = CDOExplorerUtil.getCheckout(node.getURI());
}
}
}
return result;
}
@Override
public List<? extends IWizardPage> createPages() {
if (newModelPage == null && newDiagramCategoryPage == null) {
return Collections.emptyList();
}
return Arrays.asList(newDiagramCategoryPage, newModelPage);
}
@Override
public SelectDiagramCategoryPage getDiagramCategoryPage() {
return newDiagramCategoryPage;
}
@Override
public IStatus validateDiagramCategories(String... newCategories) {
if (newModelPage != null && newModelPage.getNewResourceName() != null) {
String firstCategory = newCategories.length > 0 ? newCategories[0] : null;
if (newCategories.length > 0) {
// 316943 - [Wizard] Wrong suffix for file name when creating a
// profile model
return newModelPage.diagramExtensionChanged(wizard.getDiagramFileExtension(firstCategory));
}
}
return super.validateDiagramCategories(newCategories);
}
/**
* Creates the new model page, if required.
*
* @param selection
* the selection
*
* @return the new model page, or {@code null} if none
*/
protected NewCHESSModelPage createNewModelPage(IStructuredSelection selection) {
if (wizard.isCreateProjectWizard() || wizard.isCreateMultipleModelsWizard()) {
return null;
}
if (isCreateFromExistingDomainModel()) {
URI uri = getSelectedResourceURI(selection);
if (uri != null) {
uri = uri.trimFileExtension().appendFileExtension(wizard.getDiagramFileExtension(null));
return new NewDiagramForExistingModelPage(selection, wizard.getModelKindName(), bus, uri.lastSegment());
}
}
return new NewCHESSModelPage(selection, bus, wizard.getModelKindName());
}
protected boolean isCreateFromExistingDomainModel() {
return false;
}
@Override
public URI createNewModelURI(String categoryId) {
return newModelPage.createNewModelResourceURI();
}
@Override
public IEditorInput createEditorInput(URI uri) {
return new PapyrusCDOEditorInput(uri, uri.trimFileExtension().lastSegment());
}
// private SelectDiagramCategoryPage createNewDiagramCategoryPage(IStructuredSelection selection) {
// if (wizard.isCreateProjectWizard() || wizard.isCreateMultipleModelsWizard() || !wizard.isPapyrusRootWizard()) {
// return null;
// }
//
// return new SelectDiagramCategoryPage();
// }
//
// Nested types
//
/**
* This is the NewDiagramForExistingModelPage type. Enjoy.
*/
protected static class NewDiagramForExistingModelPage extends NewCHESSModelPage {
/** The my diagram resource name. */
private final String myDiagramResourceName;
/**
* Instantiates a new new diagram for existing model page.
*
* @param selection
* the selection
* @param modelKindName
* the user-presentable (translatable) name of the kind of
* model to create
* @param bus
* an event bus for posting events
* @param defaultResourceName
* the default resource name
*/
public NewDiagramForExistingModelPage(IStructuredSelection selection, String modelKindName, EventBus bus, String defaultResourceName) {
super(selection, bus, modelKindName);
myDiagramResourceName = defaultResourceName;
setTitle("Init a new Papyrus model");
setDescription("Init a new Papyrus model from the existing domain model");
}
@Override
public void createControl(Composite parent) {
super.createControl(parent);
setNewResourceName(myDiagramResourceName);
}
@Override
protected void validatePage() {
super.validatePage();
if (getMessageType() < ERROR) {
if (!myDiagramResourceName.equals(getNewResourceName())) {
setMessage(NLS.bind(org.eclipse.papyrus.uml.diagram.wizards.Messages.InitModelWizard_diagram_name_is_different_from_domain_model, myDiagramResourceName), ERROR);
setPageComplete(false);
}
}
};
}
public String getFolderRelativePath(){
return newModelPage.getFolderRelativePath();
}
public String getProjectName(){
return newModelPage.getProjectName();
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.cdo.providers;
import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.adapt;
import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.getSelectedResourceURI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
import org.eclipse.papyrus.cdo.internal.ui.editors.PapyrusCDOEditorInput;
import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
import org.eclipse.papyrus.uml.diagram.wizards.providers.AbstractNewModelStorageProvider;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.CreateModelWizard;
import org.eclipse.papyrus.uml.diagram.wizards.wizards.InitModelWizard;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.INewWizard;
import org.polarsys.chess.cdo.pages.NewCHESSModelPage;
import org.polarsys.chess.cdo.wizards.CreateCDOCHESSModelWizard;
import org.polarsys.chess.wizards.wizards.CreateCHESSModelWizard;
import com.google.common.eventbus.EventBus;
public class CHESSCDONewModelStorageProvider extends AbstractNewModelStorageProvider {
private final EventBus bus = new EventBus("NewCDOModelWizard"); //$NON-NLS-1$
private CreateCDOCHESSModelWizard wizard;
private SelectDiagramCategoryPage newDiagramCategoryPage;
private NewCHESSModelPage newModelPage;
private IStructuredSelection selection;
public CHESSCDONewModelStorageProvider() {
super();
}
@Override
public boolean canHandle(IStructuredSelection initialSelection) {
for (Object next : initialSelection.toList()) {
if (CDOUtils.isCDOObject(adapt(next, EObject.class))) {
return true;
}
if (adapt(next, CDOCheckout.class) != null) {
return true;
}
}
return false;
}
public void init(CreateCDOCHESSModelWizard wizard, IStructuredSelection selection) {
// super.init(wizard, selection);
this.wizard = wizard;
this.selection = selection;
newModelPage = createNewModelPage(selection);
createSelectProviderPart();
CDOCheckout checkout = getRepository(selection);
if (checkout != null) {
bus.post(checkout);
}
// newDiagramCategoryPage = createNewDiagramCategoryPage(selection);
}
/**
* Gets the contextual repository, if any, from a selection.
*
* @param selection
* a selection
*
* @return the repository that is or contains the {@code selection}
*/
static CDOCheckout getRepository(IStructuredSelection selection) {
CDOCheckout result = null;
if (!selection.isEmpty()) {
result = adapt(selection.getFirstElement(), CDOCheckout.class);
if (result == null) {
CDOResourceNode node = adapt(selection.getFirstElement(), CDOResourceNode.class);
if (node == null) {
EObject object = adapt(selection.getFirstElement(), EObject.class);
if (object != null) {
CDOObject cdo = CDOUtils.getCDOObject(object);
if (cdo != null) {
node = cdo.cdoResource();
}
}
}
if (node != null) {
result = CDOExplorerUtil.getCheckout(node.getURI());
}
}
}
return result;
}
@Override
public List<? extends IWizardPage> createPages() {
if (newModelPage == null && newDiagramCategoryPage == null) {
return Collections.emptyList();
}
return Arrays.asList(newDiagramCategoryPage, newModelPage);
}
@Override
public SelectDiagramCategoryPage getDiagramCategoryPage() {
return newDiagramCategoryPage;
}
@Override
public IStatus validateDiagramCategories(String... newCategories) {
if (newModelPage != null && newModelPage.getNewResourceName() != null) {
String firstCategory = newCategories.length > 0 ? newCategories[0] : null;
if (newCategories.length > 0) {
// 316943 - [Wizard] Wrong suffix for file name when creating a
// profile model
return newModelPage.diagramExtensionChanged(wizard.getDiagramFileExtension(firstCategory));
}
}
return super.validateDiagramCategories(newCategories);
}
/**
* Creates the new model page, if required.
*
* @param selection
* the selection
*
* @return the new model page, or {@code null} if none
*/
protected NewCHESSModelPage createNewModelPage(IStructuredSelection selection) {
if (wizard.isCreateProjectWizard() || wizard.isCreateMultipleModelsWizard()) {
return null;
}
if (isCreateFromExistingDomainModel()) {
URI uri = getSelectedResourceURI(selection);
if (uri != null) {
uri = uri.trimFileExtension().appendFileExtension(wizard.getDiagramFileExtension(null));
return new NewDiagramForExistingModelPage(selection, wizard.getModelKindName(), bus, uri.lastSegment());
}
}
return new NewCHESSModelPage(selection, bus, wizard.getModelKindName());
}
protected boolean isCreateFromExistingDomainModel() {
return false;
}
@Override
public URI createNewModelURI(String categoryId) {
return newModelPage.createNewModelResourceURI();
}
@Override
public IEditorInput createEditorInput(URI uri) {
return new PapyrusCDOEditorInput(uri, uri.trimFileExtension().lastSegment());
}
// private SelectDiagramCategoryPage createNewDiagramCategoryPage(IStructuredSelection selection) {
// if (wizard.isCreateProjectWizard() || wizard.isCreateMultipleModelsWizard() || !wizard.isPapyrusRootWizard()) {
// return null;
// }
//
// return new SelectDiagramCategoryPage();
// }
//
// Nested types
//
/**
* This is the NewDiagramForExistingModelPage type. Enjoy.
*/
protected static class NewDiagramForExistingModelPage extends NewCHESSModelPage {
/** The my diagram resource name. */
private final String myDiagramResourceName;
/**
* Instantiates a new new diagram for existing model page.
*
* @param selection
* the selection
* @param modelKindName
* the user-presentable (translatable) name of the kind of
* model to create
* @param bus
* an event bus for posting events
* @param defaultResourceName
* the default resource name
*/
public NewDiagramForExistingModelPage(IStructuredSelection selection, String modelKindName, EventBus bus, String defaultResourceName) {
super(selection, bus, modelKindName);
myDiagramResourceName = defaultResourceName;
setTitle("Init a new Papyrus model");
setDescription("Init a new Papyrus model from the existing domain model");
}
@Override
public void createControl(Composite parent) {
super.createControl(parent);
setNewResourceName(myDiagramResourceName);
}
@Override
protected void validatePage() {
super.validatePage();
if (getMessageType() < ERROR) {
if (!myDiagramResourceName.equals(getNewResourceName())) {
setMessage(NLS.bind(org.eclipse.papyrus.uml.diagram.wizards.Messages.InitModelWizard_diagram_name_is_different_from_domain_model, myDiagramResourceName), ERROR);
setPageComplete(false);
}
}
};
}
public String getFolderRelativePath(){
return newModelPage.getFolderRelativePath();
}
public String getProjectName(){
return newModelPage.getProjectName();
}
}
package org.polarsys.chess.cdo.providers;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.core.resources.IProject;
public class CHESSProjectListLabelProvider extends LabelProvider {
public Image getImage(Object element) {
return null;
}
public String getText(Object element) {
IProject resource = (IProject) element;
return resource.getName();
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.cdo.providers;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.core.resources.IProject;
public class CHESSProjectListLabelProvider extends LabelProvider {
public Image getImage(Object element) {
return null;
}
public String getText(Object element) {
IProject resource = (IProject) element;
return resource.getName();
}
}
package org.polarsys.chess.codegen.ada.util;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
public class AdaGenUtil {
/**
* Utility method to get the active Eclipse project.
*
* @param editor the editor
* @return the active project
*/
public static IProject getActiveProject(IEditorPart editor) {
IFileEditorInput input = (IFileEditorInput) editor.getEditorInput();
IFile file = input.getFile();
return file.getProject();
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.codegen.ada.util;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IFileEditorInput;
public class AdaGenUtil {
/**
* Utility method to get the active Eclipse project.
*
* @param editor the editor
* @return the active project
*/
public static IProject getActiveProject(IEditorPart editor) {
IFileEditorInput input = (IFileEditorInput) editor.getEditorInput();
IFile file = input.getFile();
return file.getProject();
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package javax.xml.bind;
public class EmptyClass {
......
package org.polarsys.chess.core.constraint;
/**
* The Class PreferenceProperties.
*/
public class PreferenceProperties {
/** The diagram in view. */
public static String DIAGRAM_IN_VIEW="DiagramInView";
/** The palettes in view. */
public static String PALETTES_IN_VIEW="PaletteInView";
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.core.constraint;
/**
* The Class PreferenceProperties.
*/
public class PreferenceProperties {
/** The diagram in view. */
public static String DIAGRAM_IN_VIEW="DiagramInView";
/** The palettes in view. */
public static String PALETTES_IN_VIEW="PaletteInView";
}
package org.polarsys.chess.core.extensionpoint;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.uml2.uml.Model;
/**
* The Interface IAddProfile.
*/
public interface IAddProfile {
/**
* Applies a profile to the given model and resourceset.
*
* @param owner the owner
* @param resourceSet the resource set
*/
void addProfile(Model owner, ResourceSet resourceSet);
/**
* Loads a profile for the given ResourceSet.
*
* @param resourceSet the resource set
*/
void loadProfile(ResourceSet resourceSet);
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.core.extensionpoint;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.uml2.uml.Model;
/**
* The Interface IAddProfile.
*/
public interface IAddProfile {
/**
* Applies a profile to the given model and resourceset.
*
* @param owner the owner
* @param resourceSet the resource set
*/
void addProfile(Model owner, ResourceSet resourceSet);
/**
* Loads a profile for the given ResourceSet.
*
* @param resourceSet the resource set
*/
void loadProfile(ResourceSet resourceSet);
}
package org.polarsys.chess.core.internal.extensionpoint;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.emf.ecore.resource.ResourceSet;
//import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.uml2.uml.Model;
import org.polarsys.chess.core.Activator;
import org.polarsys.chess.core.extensionpoint.IAddProfile;
/**
* The Class AddProfileHandler.
*/
public class AddProfileHandler {
/** The Constant ADDPROFILE_ID. */
private static final String ADDPROFILE_ID =
"org.polarsys.chess.addprofile";
/**
* Execute add profile.
*
* @param registry the registry
* @param owner the owner
* @param resourceSet the resource set
*/
public void executeAddProfile(IExtensionRegistry registry, Model owner, ResourceSet resourceSet) {
evaluateAddProfile(registry, owner, resourceSet);
}
/**
* Evaluate add profile.
*
* @param registry the registry
* @param owner the owner
* @param resourceSet the resource set
*/
private void evaluateAddProfile(IExtensionRegistry registry, Model owner, ResourceSet resourceSet) {
IConfigurationElement[] config =
registry.getConfigurationElementsFor(ADDPROFILE_ID);
try {
for (IConfigurationElement e : config) {
System.out.println("Evaluating extension");
final Object o =
e.createExecutableExtension("class");
if (o instanceof IAddProfile) {
addProfile(o, owner, resourceSet);
}
}
} catch (CoreException ex) {
System.out.println(ex.getMessage());
Activator.error("evaluateAddProfile error", ex);
}
}
/**
* Adds the profile.
*
* @param o the o
* @param owner the owner
* @param resourceSet the resource set
*/
private void addProfile(final Object o, final Model owner, final ResourceSet resourceSet) {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void handleException(Throwable e) {
System.out.println("Exception in client");
Activator.error("Exception in client", e);
}
@Override
public void run() throws Exception {
((IAddProfile) o).addProfile(owner, resourceSet);
}
};
SafeRunner.run(runnable);
}
/**
* Execute load profile.
*
* @param registry the registry
* @param resourceSet the resource set
*/
public void executeLoadProfile(IExtensionRegistry registry, ResourceSet resourceSet) {
evaluateLoadProfile(registry, resourceSet);
}
/**
* Evaluate load profile.
*
* @param registry the registry
* @param resourceSet the resource set
*/
private void evaluateLoadProfile(IExtensionRegistry registry, ResourceSet resourceSet) {
IConfigurationElement[] config =
registry.getConfigurationElementsFor(ADDPROFILE_ID);
try {
for (IConfigurationElement e : config) {
System.out.println("Evaluating extension");
final Object o =
e.createExecutableExtension("class");
if (o instanceof IAddProfile) {
loadProfile(o, resourceSet);
}
}
} catch (CoreException ex) {
System.out.println(ex.getMessage());
Activator.error("EvaluateLoadProfile error", ex);
}
}
/**
* Load profile.
*
* @param o the o
* @param resourceSet the resource set
*/
private void loadProfile(final Object o, final ResourceSet resourceSet) {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void handleException(Throwable e) {
System.out.println("Exception in client");
Activator.error("Exception in client", e);
}
@Override
public void run() throws Exception {
((IAddProfile) o).loadProfile(resourceSet);
}
};
SafeRunner.run(runnable);
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.core.internal.extensionpoint;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.emf.ecore.resource.ResourceSet;
//import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.uml2.uml.Model;
import org.polarsys.chess.core.Activator;
import org.polarsys.chess.core.extensionpoint.IAddProfile;
/**
* The Class AddProfileHandler.
*/
public class AddProfileHandler {
/** The Constant ADDPROFILE_ID. */
private static final String ADDPROFILE_ID =
"org.polarsys.chess.addprofile";
/**
* Execute add profile.
*
* @param registry the registry
* @param owner the owner
* @param resourceSet the resource set
*/
public void executeAddProfile(IExtensionRegistry registry, Model owner, ResourceSet resourceSet) {
evaluateAddProfile(registry, owner, resourceSet);
}
/**
* Evaluate add profile.
*
* @param registry the registry
* @param owner the owner
* @param resourceSet the resource set
*/
private void evaluateAddProfile(IExtensionRegistry registry, Model owner, ResourceSet resourceSet) {
IConfigurationElement[] config =
registry.getConfigurationElementsFor(ADDPROFILE_ID);
try {
for (IConfigurationElement e : config) {
System.out.println("Evaluating extension");
final Object o =
e.createExecutableExtension("class");
if (o instanceof IAddProfile) {
addProfile(o, owner, resourceSet);
}
}
} catch (CoreException ex) {
System.out.println(ex.getMessage());
Activator.error("evaluateAddProfile error", ex);
}
}
/**
* Adds the profile.
*
* @param o the o
* @param owner the owner
* @param resourceSet the resource set
*/
private void addProfile(final Object o, final Model owner, final ResourceSet resourceSet) {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void handleException(Throwable e) {
System.out.println("Exception in client");
Activator.error("Exception in client", e);
}
@Override
public void run() throws Exception {
((IAddProfile) o).addProfile(owner, resourceSet);
}
};
SafeRunner.run(runnable);
}
/**
* Execute load profile.
*
* @param registry the registry
* @param resourceSet the resource set
*/
public void executeLoadProfile(IExtensionRegistry registry, ResourceSet resourceSet) {
evaluateLoadProfile(registry, resourceSet);
}
/**
* Evaluate load profile.
*
* @param registry the registry
* @param resourceSet the resource set
*/
private void evaluateLoadProfile(IExtensionRegistry registry, ResourceSet resourceSet) {
IConfigurationElement[] config =
registry.getConfigurationElementsFor(ADDPROFILE_ID);
try {
for (IConfigurationElement e : config) {
System.out.println("Evaluating extension");
final Object o =
e.createExecutableExtension("class");
if (o instanceof IAddProfile) {
loadProfile(o, resourceSet);
}
}
} catch (CoreException ex) {
System.out.println(ex.getMessage());
Activator.error("EvaluateLoadProfile error", ex);
}
}
/**
* Load profile.
*
* @param o the o
* @param resourceSet the resource set
*/
private void loadProfile(final Object o, final ResourceSet resourceSet) {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void handleException(Throwable e) {
System.out.println("Exception in client");
Activator.error("Exception in client", e);
}
@Override
public void run() throws Exception {
((IAddProfile) o).loadProfile(resourceSet);
}
};
SafeRunner.run(runnable);
}
}
package org.polarsys.chess.core.internal.util;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.Enumeration;
import java.util.List;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.Bundle;
import org.polarsys.chess.core.natures.CHESSNature;
import org.polarsys.chess.core.util.CHESSProjectSupport;
/**
* The Class InternalCHESSProjectSupport.
*/
public class InternalCHESSProjectSupport {
/**
* Adds the nature.
*
* @param project the project
* @throws CoreException the core exception
*/
public static void addNature(IProject project) throws CoreException {
if (!project.hasNature(CHESSNature.NATURE_ID)) {
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = CHESSNature.NATURE_ID;
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
}
/**
* Creates the base project.
*
* @param projectName the project name
* @param location the location
* @return the i project
*/
public static IProject createBaseProject(String projectName, URI location) {
IProject newProject = ResourcesPlugin.getWorkspace().getRoot()
.getProject(projectName);
if (!newProject.exists()) {
URI projectLocation = location;
IProjectDescription desc = newProject.getWorkspace()
.newProjectDescription(newProject.getName());
if (location != null
&& ResourcesPlugin.getWorkspace().getRoot()
.getLocationURI().equals(location)) {
projectLocation = null;
}
desc.setLocationURI(projectLocation);
try {
newProject.create(desc, null);
if (!newProject.isOpen()) {
newProject.open(null);
}
} catch (CoreException e) {
e.printStackTrace();
}
}
return newProject;
}
/**
* Adds the to project structure.
*
* @param newProject the new project
* @param paths the paths
* @throws CoreException the core exception
*/
@SuppressWarnings("unused")
private static void addToProjectStructure(final IProject newProject,
final String[] paths) throws CoreException {
for (String path : paths) {
IFolder etcFolder = newProject.getFolder(path);
CHESSProjectSupport.createFolder(etcFolder);
}
}
/**
* This is a copy of org.eclipse.core.internal.utils.FileUtil.
* Converts a URI to an IPath. Returns null if the URI cannot be represented
* as an IPath.
* <p>
* Note this method differs from URIUtil in its handling of relative URIs
* as being relative to path variables.
*
* @param uri the uri
* @return the i path
*/
public static IPath toPath(URI uri) {
if (uri == null)
return null;
final String scheme = uri.getScheme();
// null scheme represents path variable
if (scheme == null || EFS.SCHEME_FILE.equals(scheme))
return new Path(uri.getSchemeSpecificPart());
return null;
}
/**
* Gets the plugin install location.
*
* @param pluginId the plugin id
* @return the plugin install location
* @throws Exception the exception
*/
public static String getPluginInstallLocation(String pluginId) throws Exception {
Bundle bundle = Platform.getBundle(pluginId);
URL locationUrl = FileLocator.find(bundle,new Path("/"), null);
URL fileUrl = FileLocator.toFileURL(locationUrl);
return fileUrl.getFile();
}
/**
* Gets the name without extension.
*
* @param inputFile the input file
* @return the name without extension
*/
public static String getNameWithoutExtension(IFile inputFile) {
String inputName = inputFile.getName();
int extensionIndex = inputName.lastIndexOf('.');
if (extensionIndex != -1)
inputName = inputName.substring(0, extensionIndex);
return inputName;
}
/**
* File copy.
*
* @param in the in
* @param out the out
* @throws IOException Signals that an I/O exception has occurred.
*/
public static void fileCopy(InputStream in, FileOutputStream out)
throws IOException {
byte[] buf = new byte[8192];
while (true) {
int length = in.read(buf);
if (length < 0)
break;
out.write(buf, 0, length);
}
try {
in.close();
} catch (IOException ignore) {
}
try {
out.close();
} catch (IOException ignore) {
}
}
/**
* Gets the bundle contents.
*
* @param activator the activator
* @param path the path
* @param collectedPaths the collected paths
* @return the bundle contents
*/
public static void getBundleContents(Plugin activator, String path,
List<String> collectedPaths) {
Enumeration<?> enums = activator.getBundle().getEntryPaths(path);
while (enums.hasMoreElements()) {
Object object = enums.nextElement();
Enumeration<?> tmpEnum = activator.getBundle().getEntryPaths(
object.toString());
if (tmpEnum != null)
getBundleContents(activator, object.toString(), collectedPaths);
else {
collectedPaths.add(object.toString());
}
}
}
/**
* Gets the i file from absolute path.
*
* @param path the path
* @return the i file from absolute path
*/
public static IFile getIFileFromAbsolutePath(String path) {
IPath location = Path.fromOSString(path);
return ResourcesPlugin.getWorkspace().getRoot()
.getFileForLocation(location);
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.core.internal.util;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.Enumeration;
import java.util.List;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.Bundle;
import org.polarsys.chess.core.natures.CHESSNature;
import org.polarsys.chess.core.util.CHESSProjectSupport;
/**
* The Class InternalCHESSProjectSupport.
*/
public class InternalCHESSProjectSupport {
/**
* Adds the nature.
*
* @param project the project
* @throws CoreException the core exception
*/
public static void addNature(IProject project) throws CoreException {
if (!project.hasNature(CHESSNature.NATURE_ID)) {
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = CHESSNature.NATURE_ID;
description.setNatureIds(newNatures);
project.setDescription(description, null);
}
}
/**
* Creates the base project.
*
* @param projectName the project name
* @param location the location
* @return the i project
*/
public static IProject createBaseProject(String projectName, URI location) {
IProject newProject = ResourcesPlugin.getWorkspace().getRoot()
.getProject(projectName);
if (!newProject.exists()) {
URI projectLocation = location;
IProjectDescription desc = newProject.getWorkspace()
.newProjectDescription(newProject.getName());
if (location != null
&& ResourcesPlugin.getWorkspace().getRoot()
.getLocationURI().equals(location)) {
projectLocation = null;
}
desc.setLocationURI(projectLocation);
try {
newProject.create(desc, null);
if (!newProject.isOpen()) {
newProject.open(null);
}
} catch (CoreException e) {
e.printStackTrace();
}
}
return newProject;
}
/**
* Adds the to project structure.
*
* @param newProject the new project
* @param paths the paths
* @throws CoreException the core exception
*/
@SuppressWarnings("unused")
private static void addToProjectStructure(final IProject newProject,
final String[] paths) throws CoreException {
for (String path : paths) {
IFolder etcFolder = newProject.getFolder(path);
CHESSProjectSupport.createFolder(etcFolder);
}
}
/**
* This is a copy of org.eclipse.core.internal.utils.FileUtil.
* Converts a URI to an IPath. Returns null if the URI cannot be represented
* as an IPath.
* <p>
* Note this method differs from URIUtil in its handling of relative URIs
* as being relative to path variables.
*
* @param uri the uri
* @return the i path
*/
public static IPath toPath(URI uri) {
if (uri == null)
return null;
final String scheme = uri.getScheme();
// null scheme represents path variable
if (scheme == null || EFS.SCHEME_FILE.equals(scheme))
return new Path(uri.getSchemeSpecificPart());
return null;
}
/**
* Gets the plugin install location.
*
* @param pluginId the plugin id
* @return the plugin install location
* @throws Exception the exception
*/
public static String getPluginInstallLocation(String pluginId) throws Exception {
Bundle bundle = Platform.getBundle(pluginId);
URL locationUrl = FileLocator.find(bundle,new Path("/"), null);
URL fileUrl = FileLocator.toFileURL(locationUrl);
return fileUrl.getFile();
}
/**
* Gets the name without extension.
*
* @param inputFile the input file
* @return the name without extension
*/
public static String getNameWithoutExtension(IFile inputFile) {
String inputName = inputFile.getName();
int extensionIndex = inputName.lastIndexOf('.');
if (extensionIndex != -1)
inputName = inputName.substring(0, extensionIndex);
return inputName;
}
/**
* File copy.
*
* @param in the in
* @param out the out
* @throws IOException Signals that an I/O exception has occurred.
*/
public static void fileCopy(InputStream in, FileOutputStream out)
throws IOException {
byte[] buf = new byte[8192];
while (true) {
int length = in.read(buf);
if (length < 0)
break;
out.write(buf, 0, length);
}
try {
in.close();
} catch (IOException ignore) {
}
try {
out.close();
} catch (IOException ignore) {
}
}
/**
* Gets the bundle contents.
*
* @param activator the activator
* @param path the path
* @param collectedPaths the collected paths
* @return the bundle contents
*/
public static void getBundleContents(Plugin activator, String path,
List<String> collectedPaths) {
Enumeration<?> enums = activator.getBundle().getEntryPaths(path);
while (enums.hasMoreElements()) {
Object object = enums.nextElement();
Enumeration<?> tmpEnum = activator.getBundle().getEntryPaths(
object.toString());
if (tmpEnum != null)
getBundleContents(activator, object.toString(), collectedPaths);
else {
collectedPaths.add(object.toString());
}
}
}
/**
* Gets the i file from absolute path.
*
* @param path the path
* @return the i file from absolute path
*/
public static IFile getIFileFromAbsolutePath(String path) {
IPath location = Path.fromOSString(path);
return ResourcesPlugin.getWorkspace().getRoot()
.getFileForLocation(location);
}
}
package org.polarsys.chess.core.internal.util;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import org.polarsys.chess.core.util.CHESSProjectSupport;
/**
* The Class InternalConsoleUtil.
*/
public class InternalConsoleUtil {
/**
* Find console.
*
* @param name the name
* @return the message console
*/
public static MessageConsole findConsole(final String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
return (MessageConsole) existing[i];
//no console found, so create a new one
MessageConsole myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[]{myConsole});
return myConsole;
}
/**
* Find CHES sconsole.
*
* @return the message console stream
*/
public static MessageConsoleStream findCHESSconsole(){
MessageConsole myConsole = findConsole(CHESSProjectSupport.CHESS_CONSOLE_NAME);
return myConsole.newMessageStream();
}
/**
* Write log.
*
* @param message the message
* @throws FileNotFoundException the file not found exception
*/
public static void writeLog(String message) throws FileNotFoundException {
FileOutputStream out = new FileOutputStream(InternalConsoleUtil.getEclipseInstallLocation()
+ "CHESSLOG");
PrintStream p = new PrintStream(out);
p.println(message);
p.close();
}
/**
* Gets the eclipse install location.
*
* @return the eclipse install location
*/
public static String getEclipseInstallLocation() {
if (System.getProperty("os.name").equals("Linux"))
return System.getProperties().get("osgi.install.area").toString()
.substring(5);
else
return System.getProperties().get("osgi.install.area").toString()
.substring(6);
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.core.internal.util;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;
import org.polarsys.chess.core.util.CHESSProjectSupport;
/**
* The Class InternalConsoleUtil.
*/
public class InternalConsoleUtil {
/**
* Find console.
*
* @param name the name
* @return the message console
*/
public static MessageConsole findConsole(final String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
return (MessageConsole) existing[i];
//no console found, so create a new one
MessageConsole myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[]{myConsole});
return myConsole;
}
/**
* Find CHES sconsole.
*
* @return the message console stream
*/
public static MessageConsoleStream findCHESSconsole(){
MessageConsole myConsole = findConsole(CHESSProjectSupport.CHESS_CONSOLE_NAME);
return myConsole.newMessageStream();
}
/**
* Write log.
*
* @param message the message
* @throws FileNotFoundException the file not found exception
*/
public static void writeLog(String message) throws FileNotFoundException {
FileOutputStream out = new FileOutputStream(InternalConsoleUtil.getEclipseInstallLocation()
+ "CHESSLOG");
PrintStream p = new PrintStream(out);
p.println(message);
p.close();
}
/**
* Gets the eclipse install location.
*
* @return the eclipse install location
*/
public static String getEclipseInstallLocation() {
if (System.getProperty("os.name").equals("Linux"))
return System.getProperties().get("osgi.install.area").toString()
.substring(5);
else
return System.getProperties().get("osgi.install.area").toString()
.substring(6);
}
}
package org.polarsys.chess.core.transformationExecutor;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.uml2.uml.Package;
/**
* This interface defines the transformation to execute.
*
*/
public interface ITransformationExecutor {
/**
* Executes the transformation.
*
* @param modelFile the input model for the transformation
* @param transformationDirectory the directory where the output of the transformation will be created
* @param monitor the progress monitor
* @param psmPackage the PSM package to use as input for the transformation
* @return the resulting status of the transformation
* @throws Exception when something went wrong during the transformation
*/
public String execute(IFile modelFile, IFolder transformationDirectory,
IProgressMonitor monitor, Package psmPackage) throws Exception;
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.core.transformationExecutor;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.uml2.uml.Package;
/**
* This interface defines the transformation to execute.
*
*/
public interface ITransformationExecutor {
/**
* Executes the transformation.
*
* @param modelFile the input model for the transformation
* @param transformationDirectory the directory where the output of the transformation will be created
* @param monitor the progress monitor
* @param psmPackage the PSM package to use as input for the transformation
* @return the resulting status of the transformation
* @throws Exception when something went wrong during the transformation
*/
public String execute(IFile modelFile, IFolder transformationDirectory,
IProgressMonitor monitor, Package psmPackage) throws Exception;
}
/* ------------------------------------------------------------------------------
- Copyright (c) 2015 Intecs.
- All rights reserved. This program and the accompanying materials
- are made available under the terms of the Eclipse Public License v2.0
- which accompanies this distribution, and is available at
- http://www.eclipse.org/legal/epl-v20.html
-
- Contributors:
- L. Baracchi, laura.baracchi@intecs.it
------------------------------------------------------------------------------*/
package org.polarsys.chess.core.util;
/**
* Used to save and display the results data from End to End Response Time Analysis .
*/
public class EndToEndResultData {
/** The scenario name. */
public String scenarioName ="";
/** The deadline. */
public String deadline ="";
/** The resp time. */
public String respTime ="";
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
/* ------------------------------------------------------------------------------
- Copyright (c) 2015 Intecs.
- All rights reserved. This program and the accompanying materials
- are made available under the terms of the Eclipse Public License v2.0
- which accompanies this distribution, and is available at
- http://www.eclipse.org/legal/epl-v20.html
-
- Contributors:
- L. Baracchi, laura.baracchi@intecs.it
------------------------------------------------------------------------------*/
package org.polarsys.chess.core.util;
/**
* Used to save and display the results data from End to End Response Time Analysis .
*/
public class EndToEndResultData {
/** The scenario name. */
public String scenarioName ="";
/** The deadline. */
public String deadline ="";
/** The resp time. */
public String respTime ="";
}
package org.polarsys.chess.core.util.commands;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.uml.tools.model.UmlUtils;
import org.eclipse.uml2.uml.Model;
import org.polarsys.chess.core.internal.extensionpoint.AddProfileHandler;
import org.polarsys.chess.core.internal.views.commands.CreateViewsCommand;
/**
* This class extends the {@link RecordingCommand} class to implement the command to initialize a
* CHESS model.
*
*/
public class InitCHESSModelCommand extends RecordingCommand {
/** The model set. */
private ModelSet modelSet;
/**
* Initializes the command.
*
* @param editingDomain the editing domain where the command takes place
* @param modelSet the model set where the command works in
*/
public InitCHESSModelCommand(TransactionalEditingDomain editingDomain, ModelSet modelSet) {
super(editingDomain);
this.modelSet = modelSet;
}
/* (non-Javadoc)
* @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
*/
@Override
protected void doExecute() {
EObject owner = getRootElement(UmlUtils.getUmlResource(modelSet));
CreateViewsCommand.viewsToModel((Model)owner, modelSet/*, chess, marte, sysml*/);
//let external plugins to add additional profiles
AddProfileHandler h = new AddProfileHandler();
IExtensionRegistry reg = Platform.getExtensionRegistry();
h.executeAddProfile(reg, (Model)owner, modelSet);
}
/**
* Gets the root element.
*
* @param modelResource the model resource
* @return the root element
*/
protected EObject getRootElement(Resource modelResource) {
EObject rootElement = null;
if(modelResource != null && modelResource.getContents() != null && modelResource.getContents().size() > 0) {
Object root = modelResource.getContents().get(0);
if(root instanceof EObject) {
rootElement = (EObject)root;
}
}
return rootElement;
}
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.core.util.commands;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.uml.tools.model.UmlUtils;
import org.eclipse.uml2.uml.Model;
import org.polarsys.chess.core.internal.extensionpoint.AddProfileHandler;
import org.polarsys.chess.core.internal.views.commands.CreateViewsCommand;
/**
* This class extends the {@link RecordingCommand} class to implement the command to initialize a
* CHESS model.
*
*/
public class InitCHESSModelCommand extends RecordingCommand {
/** The model set. */
private ModelSet modelSet;
/**
* Initializes the command.
*
* @param editingDomain the editing domain where the command takes place
* @param modelSet the model set where the command works in
*/
public InitCHESSModelCommand(TransactionalEditingDomain editingDomain, ModelSet modelSet) {
super(editingDomain);
this.modelSet = modelSet;
}
/* (non-Javadoc)
* @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
*/
@Override
protected void doExecute() {
EObject owner = getRootElement(UmlUtils.getUmlResource(modelSet));
CreateViewsCommand.viewsToModel((Model)owner, modelSet/*, chess, marte, sysml*/);
//let external plugins to add additional profiles
AddProfileHandler h = new AddProfileHandler();
IExtensionRegistry reg = Platform.getExtensionRegistry();
h.executeAddProfile(reg, (Model)owner, modelSet);
}
/**
* Gets the root element.
*
* @param modelResource the model resource
* @return the root element
*/
protected EObject getRootElement(Resource modelResource) {
EObject rootElement = null;
if(modelResource != null && modelResource.getContents() != null && modelResource.getContents().size() > 0) {
Object root = modelResource.getContents().get(0);
if(root instanceof EObject) {
rootElement = (EObject)root;
}
}
return rootElement;
}
}
package org.polarsys.chess.core.util.uml;
/**
* The Class ModelError.
*/
public class ModelError extends Exception {
/**
* Instantiates a new model error.
*
* @param message the message
*/
public ModelError(String message) {
super(message);
}
/**
* Instantiates a new model error.
*
* @param messageFormat the message format
* @param args the args
*/
public ModelError(String messageFormat, Object... args) {
super(String.format(messageFormat, args));
}
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -3470869043917284064L;
}
/*******************************************************************************
* Copyright (C) 2020
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
******************************************************************************/
package org.polarsys.chess.core.util.uml;
/**
* The Class ModelError.
*/
public class ModelError extends Exception {
/**
* Instantiates a new model error.
*
* @param message the message
*/
public ModelError(String message) {
super(message);
}
/**
* Instantiates a new model error.
*
* @param messageFormat the message format
* @param args the args
*/
public ModelError(String messageFormat, Object... args) {
super(String.format(messageFormat, args));
}
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -3470869043917284064L;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment