Skip to content
Snippets Groups Projects
Commit f7cf8778 authored by Kevin Kassin's avatar Kevin Kassin
Browse files

Commit 12.9 22:15

cleaned up some dependicies of iorm.ui,
CROM file is now shown in the multipage editor,
added checks if successful to the transformation
parent 22cb143e
Branches
No related tags found
No related merge requests found
......@@ -4,8 +4,10 @@ Bundle-Name: Ui
Bundle-SymbolicName: org.framed.iorm.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.framed.iorm.model.edit;visibility:=reexport,
Require-Bundle: org.framed.iorm.featuremodel;bundle-version="1.0.0",
org.framed.iorm.model.edit;visibility:=reexport,
de.ovgu.featureide.fm.core;bundle-version="3.3.1",
de.ovgu.featureide.fm.ui;bundle-version="3.3.2",
org.eclipse.graphiti;bundle-version="0.13.2",
org.eclipse.graphiti.mm;bundle-version="0.13.2",
org.eclipse.graphiti.pattern;bundle-version="0.13.2",
......@@ -25,9 +27,7 @@ Require-Bundle: org.framed.iorm.model.edit;visibility:=reexport,
org.eclipse.core.resources;bundle-version="3.11.1";visibility:=reexport,
org.eclipse.ui.workbench,
org.eclipse.emf.ecore
Import-Package: de.ovgu.featureide.fm.ui.editors.configuration,
org.eclipse.graphiti.features;version="0.13.2",
org.framed.iorm.featuremodel,
Import-Package: org.eclipse.graphiti.features;version="0.13.2",
org.framed.iorm.model,
org.framed.iorm.model.provider,
org.framed.orm.transformation
package org.framed.iorm.ui.exceptions;
import org.framed.iorm.ui.literals.TextLiterals;
/**
* This exception is thrown if the transformation triggered at saving a diagram failed.
* @author Kevin Kassin
*/
public class TransformationFailedException extends RuntimeException {
/**
* serial
*/
private static final long serialVersionUID = -3971492273757365431L;
/**
* the exceptions message gathered from {@link TextLiterals}
*/
private static final String ERROR_TRANSFORMATION_FAILED = TextLiterals.ERROR_TRANSFORMATION_FAILED;
/**
* Class constructor
*/
public TransformationFailedException() {
super(ERROR_TRANSFORMATION_FAILED);
}
}
......@@ -82,6 +82,11 @@ public class TextLiterals {
*/
public static final String FEATURE_HAS_NO_DESCRIPTOR_MESSAGE = "A Feature has no palette descriptor: ";
/**
* the message for the {@link TransformationFailedException}
*/
public static final String ERROR_TRANSFORMATION_FAILED = "The transformation of the IORM to the CROM failed!";
/**
* messages used in the Eclipse wizards
* <p>
......
package org.framed.iorm.ui.multipage;
import java.io.IOException;
import java.util.Collections;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
......@@ -34,8 +31,10 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.editor.FormEditor;
import org.eclipse.ui.part.FileEditorInput;
import org.framed.iorm.model.Model;
import org.framed.iorm.ui.exceptions.InvalidTypeOfEditorInputException;
import org.framed.iorm.ui.exceptions.TransformationFailedException;
import org.framed.iorm.ui.literals.IdentifierLiterals;
import org.framed.iorm.ui.literals.NameLiterals;
import org.framed.iorm.ui.literals.TextLiterals;
......@@ -288,9 +287,11 @@ public class MultipageEditor extends FormEditor implements ISelectionListener, I
* input.<br>
* Step 4: It creates a linked root model for the <em>main diagram</em> if it does not already have on linked. If so it
* also saves the role model file.<br>
* Step 5: It creates the feature editor and adds the page. To do that the created root model is needed.
* Step 5: It gets an editor input for the crom text file.<br>
* Step 6: It creates the feature editor and adds the page. To do that the created root model is needed.
* It also creates the editores and add the pages for the iorm and crom text viewers.<br>
* Step 6: It add its object to the register of multipage editors of the {@link MultipageEditorSynchronizationService}.
* Step 7: It sets the names of the pages. <br>
* Step 8: It add its object to the register of multipage editors of the {@link MultipageEditorSynchronizationService}.
* <p>
* If its not clear what <em>main diagram</em> means, see {@link RoleModelWizard#createEmfFileForDiagram} for reference.<br>
* @throws PartInitException
......@@ -316,21 +317,24 @@ public class MultipageEditor extends FormEditor implements ISelectionListener, I
if(createModelFeature.canCreate(createContext)) createModelFeature.create(createContext);
doSave(new NullProgressMonitor());
}
//Step 4
//Step 5
IFile CROMFile = GeneralUtil.getCROMFileForDiagramResource(resource);
IFileEditorInput fileEditorForCROM = new FileEditorInput(CROMFile);
//Step 6
editorFeatures = new FRaMEDFeatureEditor(diagramEditorInput, this);
textViewerIORM = new FRaMEDTextViewer();
textViewerCROM = new FRaMEDTextViewer();
try {
editorFeaturesIndex = addPage(editorFeatures, diagramEditorInput);
textViewerIORMIndex = addPage(textViewerIORM, fileEditorInput);
textViewerCROMIndex = addPage(textViewerCROM, fileEditorInput);
textViewerCROMIndex = addPage(textViewerCROM, fileEditorForCROM);
} catch (PartInitException e) { e.printStackTrace(); }
//Step 5
//Step 7
setPageText(editorDiagramIndex, DIAGRAM_PAGE_NAME);
setPageText(textViewerIORMIndex, TEXT_IORM_PAGE_NAME);
setPageText(textViewerCROMIndex, TEXT_CROM_PAGE_NAME);
setPageText(editorFeaturesIndex, FEATURE_PAGE_NAME);
//Step 6
//Step 8
MultipageEditorSynchronizationService.registerEditor(this);
}
......@@ -357,7 +361,8 @@ public class MultipageEditor extends FormEditor implements ISelectionListener, I
* This operation calls the save methods of the subeditors and synchronizes the feature configuration
* in the feature editor with the one in the role model. This is needed because there can be inconsistencies
* after undoing and redoing an feature configuration change.<br>
* It also synchronizes between multiple opened multipage editors using the {@link MultipageEditorSynchronizationService}.
* It also synchronizes between multiple opened multipage editors using the {@link MultipageEditorSynchronizationService},
* refreshes the used files and triggers the transformation of the IORM to the CROM.<br>
* The check in this operation is needed because the first save of an multipage editor at its creation is done
* before the feature editor even exists.
* @param monitor the monitor used for the save activity
......@@ -372,15 +377,14 @@ public class MultipageEditor extends FormEditor implements ISelectionListener, I
if(editorFeatures != null)
editorFeatures.synchronizeConfigurationEditorAndModelConfiguration();
refreshFile();
//TEST AREA
transformModel();
//TEST AREA
boolean transformationSuccessful = transformModel();
if(!transformationSuccessful) throw new TransformationFailedException();
MultipageEditorSynchronizationService.synchronize();
}
}
/**
* refreshes the file which is edited by the multipage editor
* refreshes the files which are used by the multipage editor
* <p>
* This is needed since the text files use different editor inputs from diagram and the feature editor.
* Therefore Graphiti does not synchronize them automatically.
......@@ -402,24 +406,29 @@ public class MultipageEditor extends FormEditor implements ISelectionListener, I
} else throw new NullPointerException(MUTLIPAGE_EDITOR_ERROR_NULLPOINTER_ON_FILE_EDITOR_INPUT);
}
//TODO
public void transformModel() {
Resource diagram_resource = EditorInputUtil.getResourceFromEditorInput(getEditorInput());
URI sourceURI = diagram_resource.getURI();
sourceURI = sourceURI.trimFileExtension();
sourceURI = sourceURI.appendFileExtension("crom");
Path path = new Path(sourceURI.toFileString());
IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
URI targetURI = URI.createPlatformResourceURI(iFile.getFullPath().toString(), true);
/**
* executes the transformation of the IORM to the CROM using the following steps:
* <p>
* Step 1: It gets the resource of the CROM for a diagram.<br>
* Step 2: It executes the transformation using the resources gathered in step 1.
*/
private boolean transformModel() {
//Step 1
Resource diagramResource = EditorInputUtil.getResourceFromEditorInput(getEditorInput());
IFile CROMFile = GeneralUtil.getCROMFileForDiagramResource(diagramResource);
URI targetURI = URI.createPlatformResourceURI(CROMFile.getFullPath().toString(), true);
ResourceSet set = new ResourceSetImpl();
Resource crom_resource = set.createResource(targetURI);
Resource CROMResource = set.createResource(targetURI);
//Step 2
TransformationExecutor exe = new TransformationExecutor();
exe.setSourceModelFile(diagram_resource);
exe.setTargetModelFile(crom_resource);
exe.setSourceModelFile(diagramResource);
exe.setTargetModelFile(CROMResource);
try {
crom_resource.save(Collections.EMPTY_MAP);
CROMResource.save(Collections.EMPTY_MAP);
exe.execute();
return true;
} catch (Exception e) { e.printStackTrace(); }
return false;
}
/**
......
......@@ -29,6 +29,7 @@ public class EditorInputUtil {
* @return the generated editor input
*/
public static IFileEditorInput getIFileEditorInputForResource(Resource resource) {
System.out.println(resource);
IPath path = new Path(resource.getURI().toFileString());
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
return new FileEditorInput(file);
......
......@@ -2,8 +2,13 @@ package org.framed.iorm.ui.util;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.graphiti.features.IFeature;
import org.eclipse.graphiti.features.IMappingProvider; //*import for javadoc link
import org.eclipse.graphiti.features.context.ICreateContext;
......@@ -147,7 +152,7 @@ public class GeneralUtil {
}
/**
* find the a feature by its name in an array of features
* finds the a feature by its name in an array of features
* @param array the array with features to search in
* @param featureName the name of the feature to find
* @return the found feature or null if it was not found
......@@ -159,4 +164,17 @@ public class GeneralUtil {
}
return null;
}
/**
* gets the {@link IFile} of the CROM for a diagram
* @param diagram_resource the resource of the diagram to get the CROM file for
* @return the file of the CROM
*/
public static IFile getCROMFileForDiagramResource(Resource diagram_resource) {
URI sourceURI = diagram_resource.getURI();
sourceURI = sourceURI.trimFileExtension();
sourceURI = sourceURI.appendFileExtension("crom");
Path path = new Path(sourceURI.toFileString());
return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment