Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vpp interface improvements #12

Merged
merged 12 commits into from
Feb 14, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,25 @@ public class ModelExportAction implements VPActionController {
*/
@Override
public void performAction(VPAction action) {
final ProjectConfigurations configurations = Configurations.getInstance().getProjectConfigurations();
final ProjectConfigurations projectConfigurations = Configurations.getInstance().getProjectConfigurations();
final Configurations configs = Configurations.getInstance();

FileDialog fd = new FileDialog((Frame) ApplicationManager.instance().getViewManager().getRootFrame(),
"Choose destination", FileDialog.SAVE);

fd.setDirectory(configurations.getExportFolderPath());
fd.setFile("*.json");


String suggestedFilename;
fd.setDirectory(projectConfigurations.getExportFolderPath());

if(projectConfigurations.getExportFilename().isEmpty()){
String projectName = ApplicationManager.instance().getProjectManager().getProject().getName();
suggestedFilename = projectName+".json";
fd.setFile(suggestedFilename);
}else{
suggestedFilename = projectConfigurations.getExportFilename();
fd.setFile(suggestedFilename);
}

fd.setVisible(true);

String fileDirectory = fd.getDirectory();
Expand All @@ -51,7 +63,9 @@ public void performAction(VPAction action) {
try {
final String jsonModel = ModelElement.generateModel(true);
Files.write(Paths.get(fileDirectory, fileName), jsonModel.getBytes());
configurations.setExportFolderPath(fileDirectory);
projectConfigurations.setExportFolderPath(fileDirectory);
projectConfigurations.setExportFilename(fileName);
configs.save();
} catch (IOException e) {
ViewUtils.log(
"Export Failed. Please submit your Visual Paradigm's log and the time of the error our developers.",
Expand All @@ -72,4 +86,4 @@ public void performAction(VPAction action) {
public void update(VPAction action) {
}

}
}
39 changes: 27 additions & 12 deletions src/main/java/it/unibz/inf/ontouml/vp/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

/**
*
* Implementation of ModelElement to handle IModel objects
* to be serialized as ontouml-schema/Package
* Implementation of ModelElement to handle IModel objects to be serialized as
* ontouml-schema/Package
*
* @author Claudenir Fonseca
* @author Tiago Prince Sales
Expand Down Expand Up @@ -51,16 +51,15 @@ public class Model implements ModelElement {

/**
*
* Constructs a model to contain all project's model elements independent of a
* <code>IModelElement</code>.
* Constructs a model to contain all project's model elements independent of
* a <code>IModelElement</code>.
*
*/
public Model() {
final IProject project = ApplicationManager.instance().getProjectManager().getProject();
final String[] rootLevelElements = { IModelElementFactory.MODEL_TYPE_PACKAGE,
IModelElementFactory.MODEL_TYPE_MODEL, IModelElementFactory.MODEL_TYPE_CLASS, IModelElementFactory.MODEL_TYPE_DATA_TYPE };
final String[] anyLevelElements = { IModelElementFactory.MODEL_TYPE_GENERALIZATION,
IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET, IModelElementFactory.MODEL_TYPE_ASSOCIATION,
final String[] rootLevelElements = { IModelElementFactory.MODEL_TYPE_PACKAGE, IModelElementFactory.MODEL_TYPE_MODEL, IModelElementFactory.MODEL_TYPE_CLASS,
IModelElementFactory.MODEL_TYPE_DATA_TYPE };
final String[] anyLevelElements = { IModelElementFactory.MODEL_TYPE_GENERALIZATION, IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET, IModelElementFactory.MODEL_TYPE_ASSOCIATION,
IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS };

this.sourceModelElement = null;
Expand Down Expand Up @@ -112,7 +111,7 @@ public String getDescription() {
}

public void setDescription(String description) {
this.description = ModelElement.safeGetString(description);;
this.description = ModelElement.safeGetString(description);
}

public List<ModelElement> getElements() {
Expand All @@ -133,35 +132,51 @@ public void addElement(ModelElement element) {
public boolean removeElement(ModelElement element) {
return this.contents.remove(element);
}

private void addModelElements(IModelElement[] modelElements) {
for (int i = 0; modelElements != null && i < modelElements.length; i++) {
final IModelElement projectElement = modelElements[i];

switch (projectElement.getModelType()) {
case IModelElementFactory.MODEL_TYPE_PACKAGE:
addElement(new Package((IPackage) projectElement));
break;

case IModelElementFactory.MODEL_TYPE_MODEL:
addElement(new Model((IModel) projectElement));
break;

case IModelElementFactory.MODEL_TYPE_CLASS:
addElement(new Class((IClass) projectElement));
break;

case IModelElementFactory.MODEL_TYPE_DATA_TYPE:
addElement(new Class((IDataType) projectElement));
break;

case IModelElementFactory.MODEL_TYPE_GENERALIZATION:
IGeneralization gen = (IGeneralization) projectElement;
if(!(gen.getFrom().getModelType().equals(IModelElementFactory.MODEL_TYPE_STEREOTYPE)&&gen.getTo().getModelType().equals(IModelElementFactory.MODEL_TYPE_STEREOTYPE)))

String fromType = gen.getFrom().getModelType();
boolean isFromClass = fromType.equals(IModelElementFactory.MODEL_TYPE_CLASS);
boolean isFromAssociation = fromType.equals(IModelElementFactory.MODEL_TYPE_ASSOCIATION);

String toType = gen.getTo().getModelType();
boolean isToClass = toType.equals(IModelElementFactory.MODEL_TYPE_CLASS);
boolean isToAssociation = toType.equals(IModelElementFactory.MODEL_TYPE_ASSOCIATION);

if ((isFromClass || isFromAssociation) && (isToClass || isToAssociation))
addElement(new Generalization((IGeneralization) projectElement));
break;

case IModelElementFactory.MODEL_TYPE_ASSOCIATION:
addElement(new Association((IAssociation) projectElement));
break;

case IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET:
addElement(new GeneralizationSet((IGeneralizationSet) projectElement));
break;

case IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS:
addElement(new AssociationClass((IAssociationClass) projectElement));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/it/unibz/inf/ontouml/vp/model/ModelElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static JsonObject transformPropertyAssignments(IModelElement sourceElemen

if(obj.size()==0)
return null;
else
return obj;

return obj;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Class that captures user preferences for a given project and enables JSON serialization.
*
* @author Claudenir Fonseca
* @author Victor Viola
*
*/
public class ProjectConfigurations {
Expand All @@ -18,6 +19,7 @@ public class ProjectConfigurations {
public static final boolean DEFAULT_IS_AUTOMATIC_COLORING_ENABLED = true;
public static final String DEFAULT_SERVER_URL = "https://ontouml.herokuapp.com";
public static final String DEFAULT_EXPORT_PATH = System.getProperty("user.home");
public static final String DEFAULT_EXPORT_FILENAME = "";

@SerializedName("projectId")
@Expose()
Expand All @@ -39,6 +41,10 @@ public class ProjectConfigurations {
@Expose()
private String exportFolderPath;

@SerializedName("exportFileName")
@Expose()
private String exportFileName;

@SerializedName("isExportEnabled")
@Expose()
private boolean isModelExportEnabled;
Expand Down Expand Up @@ -73,6 +79,7 @@ public void resetDefaults() {

this.isModelExportEnabled = ProjectConfigurations.DEFAULT_IS_EXPORT_ENABLED;
this.exportFolderPath = ProjectConfigurations.DEFAULT_EXPORT_PATH;
this.exportFileName = ProjectConfigurations.DEFAULT_EXPORT_FILENAME;

this.isAutomaticColoringEnabled = ProjectConfigurations.DEFAULT_IS_AUTOMATIC_COLORING_ENABLED;;
}
Expand Down Expand Up @@ -179,6 +186,29 @@ public void setExportFolderPath(String exportFolderPath) {
this.exportFolderPath = exportFolderPath;
}

/**
*
* Returns automatic export filename as a String.
*
* @return exportFileName
*
*/
public String getExportFilename() {
return exportFileName;
}


/**
*
* Sets automatic export filename from a String.
*
* @param exportFileName
*
*/
public void setExportFilename(String exportFileName) {
this.exportFileName = exportFileName;
}

/**
*
* Checks if an export folder is set for automatic model export.
Expand Down