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