Skip to content

Commit

Permalink
Issue31 add progress bar (#44)
Browse files Browse the repository at this point in the history
* apply multiple sterotypes at same time. Only works if all elements in the selection are the same.

* if selection has classes and associations selected at the same time validate rule for only the object that had the click.

* apply same stereotype for all elements selected

* fix update stereotype when selection multiple objects.

* when user selects more than one object do not apply constraints

* added new Fixed menu - now suggests stereotypes only when 1 class is selected or all selected classes have the same super class.

* fixed action behavior in context menu of the model explorer

* fixed context menu when selecting stereotypes from model explorer

* progressBar first version

* progress bar when calling diagram verification

* progresspanel - WIP

* fixes - wip

* progresbar with threads. Now user can cancel the request.

* fixed bug in case of exception or response null

* added message when user cancel the request.

* added progress bar to export to json after user selects the filename and file directory

* first close the progess bar then show the dialog

* added progress bar when exporting to gufo

* removed duplcated code.

* bug fixed when selecting an invalid endpoint

* bug fixed when handling model verification response

* added progress dialog to the functions that connects to the server. Improved the way the progress dialog works.

* improved in how the loading box closes.

* Fixed null pointer when canceling the model export

Co-authored-by: Victor Viola <[email protected]>
Co-authored-by: Tiago Prince Sales <[email protected]>
  • Loading branch information
3 people authored Apr 11, 2020
1 parent e6f5b28 commit c8a80c8
Show file tree
Hide file tree
Showing 8 changed files with 604 additions and 268 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
package it.unibz.inf.ontouml.vp.controllers;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.awt.Component;

import com.vp.plugin.ApplicationManager;
import com.vp.plugin.action.VPAction;
import com.vp.plugin.action.VPActionController;
import com.vp.plugin.diagram.IClassDiagramUIModel;
import com.vp.plugin.diagram.IDiagramUIModel;
import com.vp.plugin.view.IDialog;
import com.vp.plugin.view.IDialogHandler;

import it.unibz.inf.ontouml.vp.model.ModelElement;
import it.unibz.inf.ontouml.vp.utils.OntoUMLServerUtils;
import it.unibz.inf.ontouml.vp.utils.ServerRequest;
import it.unibz.inf.ontouml.vp.utils.ViewUtils;
import it.unibz.inf.ontouml.vp.views.ProgressPanel;

/**
* Implementation of toolbar button action responsible for performing diagram verification.
*
*/
public class DiagramVerificationAction implements VPActionController {

private ProgressPanel progressPanel;
private ProgressDialog loading;
private IDialog mainDialog;
DiagramVerificationRequest request;
Thread thread;

/**
*
* Performs OntoUML diagram verification.
Expand All @@ -33,25 +42,14 @@ public void performAction(VPAction action) {
ViewUtils.simpleDialog("Diagram Verification", "Please open a diagram before running this command.");
return;
}

ExecutorService executor = Executors.newFixedThreadPool(10);
executor.execute(new Runnable() {

@Override
public void run() {
try {
ViewUtils.clearLog(ViewUtils.SCOPE_PLUGIN);
final String response = OntoUMLServerUtils.requestModelVerification(ModelElement.generateModel(true));
request = new DiagramVerificationRequest();

if (response != null) {
ViewUtils.logDiagramVerificationResponse(response);
}
} catch (Exception e) {
e.printStackTrace();
}
}
loading = new ProgressDialog();
ApplicationManager.instance().getViewManager().showDialog(loading);

});
Thread thread = new Thread(request);
thread.start();
}

/**
Expand All @@ -72,8 +70,67 @@ private static boolean hasOpenedClassDiagram() {
for (IDiagramUIModel diagram : diagramArray)
if (diagram instanceof IClassDiagramUIModel && diagram.isOpened())
return true;

return false;
}

protected class ProgressDialog implements IDialogHandler {

@Override
public Component getComponent() {
progressPanel = new ProgressPanel(request);
return progressPanel;
}

@Override
public void prepare(IDialog dialog) {
mainDialog = dialog;
mainDialog.setTitle("Verification Service");
mainDialog.setModal(false);
mainDialog.setResizable(false);
dialog.setSize(progressPanel.getWidth(), progressPanel.getHeight() + 20);
progressPanel.setContainerDialog(mainDialog);
}

@Override
public void shown() {
}

@Override
public boolean canClosed() {
mainDialog.close();
return true;
}

}

public class DiagramVerificationRequest extends ServerRequest {

@Override
public void run() {
while (keepRunning()) {
try {
final String response = OntoUMLServerUtils.requestModelVerification(ModelElement.generateModel(true), loading);

if (keepRunning()) {
if (response != null) {
mainDialog.close();
request.doStop();
ViewUtils.logDiagramVerificationResponse(response);
} else {
loading.canClosed();
request.doStop();
}
} else {
loading.canClosed();
request.doStop();
ViewUtils.cleanAndShowMessage("Request cancelled by the user.");
}

} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package it.unibz.inf.ontouml.vp.controllers;

import java.awt.Component;
import java.awt.FileDialog;
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

import com.vp.plugin.ApplicationManager;
import com.vp.plugin.action.VPAction;
import com.vp.plugin.action.VPActionController;
import com.vp.plugin.view.IDialog;
import com.vp.plugin.view.IDialogHandler;

import it.unibz.inf.ontouml.vp.model.ModelElement;
import it.unibz.inf.ontouml.vp.utils.Configurations;
import it.unibz.inf.ontouml.vp.utils.OntoUMLServerUtils;
import it.unibz.inf.ontouml.vp.utils.ProjectConfigurations;
import it.unibz.inf.ontouml.vp.utils.ServerRequest;
import it.unibz.inf.ontouml.vp.utils.ViewUtils;
import it.unibz.inf.ontouml.vp.views.ProgressPanel;

/**
* Implementation of toolbar button Export to gUFO.
Expand All @@ -28,33 +32,25 @@
*/
public class ExportToGUFOAction implements VPActionController {

private ProgressPanel progressPanel;
private ProgressDialog loading;
private IDialog mainDialog;
ExportToGUFORequest request;

@Override
public void performAction(VPAction action) {

ExecutorService executor = Executors.newFixedThreadPool(1);
executor.execute(new Runnable() {
request = new ExportToGUFORequest();

@Override
public void run() {
try {
final BufferedReader gufo = OntoUMLServerUtils
.transformToGUFO(ModelElement.generateModel(true),
"http://api.ontouml.org/", "turtle", "name");
if(gufo != null) {
saveFile(gufo);
}
} catch (Exception e) {
// ViewUtils.exportToGUFOIssueDialog("Some error occurred while exporting the model");
e.printStackTrace();
}
}
loading = new ProgressDialog();
ApplicationManager.instance().getViewManager().showDialog(loading);

});
Thread thread = new Thread(request);
thread.start();
}

/**
* Called when the menu containing the button is accessed allowing for action
* manipulation, such as enable/disable or selecting the button.
* Called when the menu containing the button is accessed allowing for action manipulation, such as enable/disable or selecting the button.
*
* OBS: DOES NOT apply to this class.
*/
Expand All @@ -65,23 +61,20 @@ public void update(VPAction action) {
private void saveFile(BufferedReader buffer) throws IOException {
final Configurations configs = Configurations.getInstance();
final ProjectConfigurations projectConfigurations = configs.getProjectConfigurations();
final FileDialog fd = new FileDialog((Frame) ApplicationManager.instance().getViewManager().getRootFrame(),
"Choose destination", FileDialog.SAVE);
final FileDialog fd = new FileDialog((Frame) ApplicationManager.instance().getViewManager().getRootFrame(), "Choose destination", FileDialog.SAVE);

String suggestedFolderPath = projectConfigurations.getExportGUFOFolderPath();
String suggestedFileName = projectConfigurations.getExportGUFOFilename();

if(suggestedFileName.isEmpty()){
if (suggestedFileName.isEmpty()) {
String projectName = ApplicationManager.instance().getProjectManager().getProject().getName();
suggestedFileName = projectName+".ttl";
suggestedFileName = projectName + ".ttl";
}

fd.setDirectory(suggestedFolderPath);
fd.setFile(suggestedFileName);
fd.setVisible(true);



if (fd.getDirectory() != null && fd.getFile() != null) {
final String fileDirectory = fd.getDirectory();
final String fileName = !fd.getFile().endsWith(".ttl") ? fd.getFile() + ".ttl" : fd.getFile();
Expand All @@ -94,4 +87,64 @@ private void saveFile(BufferedReader buffer) throws IOException {
}
}

public class ProgressDialog implements IDialogHandler {

@Override
public Component getComponent() {
progressPanel = new ProgressPanel(request);
return progressPanel;
}

@Override
public void prepare(IDialog dialog) {
mainDialog = dialog;
mainDialog.setTitle("Export to GUFO");
mainDialog.setModal(false);
mainDialog.setResizable(false);
dialog.setSize(progressPanel.getWidth(), progressPanel.getHeight() + 20);
progressPanel.setContainerDialog(mainDialog);
}

@Override
public void shown() {
}

@Override
public boolean canClosed() {
mainDialog.close();
return true;
}
}

public class ExportToGUFORequest extends ServerRequest {

@Override
public void run() {
while (keepRunning()) {
try {
final BufferedReader gufo = OntoUMLServerUtils.transformToGUFO(ModelElement.generateModel(true), "http://api.ontouml.org/", "turtle", "name", loading);

if (keepRunning()) {
if (gufo != null) {
saveFile(gufo);
ViewUtils.cleanAndShowMessage("Model exported successfully.");
request.doStop();
} else {
loading.canClosed();
request.doStop();
ViewUtils.cleanAndShowMessage("Unable to transform to GUFO. Please check your model.");
}
} else {
loading.canClosed();
request.doStop();
ViewUtils.cleanAndShowMessage("Request cancelled by the user.");
}

} catch (Exception e) {
e.printStackTrace();
}
}
}
}

}
Loading

0 comments on commit c8a80c8

Please sign in to comment.