use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ProjectExplorerView method fireTreeObjectAdded.
public void fireTreeObjectAdded(TreeObjectEvent treeObjectEvent) {
// Guaranteed to return a non-null array
Object[] listeners = treeObjectListeners.getListenerList();
// those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == TreeObjectListener.class) {
try {
((TreeObjectListener) listeners[i + 1]).treeObjectAdded(treeObjectEvent);
} catch (Exception e) {
String message = "fireTreeObjectAdded failed for treeObject: " + ((TreeObject) listeners[i + 1]).getName();
ConvertigoPlugin.logException(e, message);
}
;
}
}
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
// Case of Project added
if (databaseObject instanceof Project) {
ProjectTreeObject projectTreeObject = (ProjectTreeObject) treeObject;
// Case of project copy : update references in steps if needed
if (treeObjectEvent.oldValue != null) {
String oldName = (String) treeObjectEvent.oldValue;
String newName = (String) treeObjectEvent.newValue;
boolean updateReferences = false;
int update = 0;
if (loadedProjectsHaveReferences()) {
Shell shell = Display.getDefault().getActiveShell();
CustomDialog customDialog = new CustomDialog(shell, "Update object references", "Do you want to update " + "project" + " references ?\n You can replace '" + oldName + "' by '" + newName + "' in all loaded projects \n or replace '" + oldName + "' by '" + newName + "' in current project only.", 670, 200, new ButtonSpec("Replace in all loaded projects", true), new ButtonSpec("Replace in current project", false), new ButtonSpec("Do not replace anywhere", false));
int response = customDialog.open();
if (response == 0) {
updateReferences = true;
update = TreeObjectEvent.UPDATE_ALL;
}
if (response == 1) {
updateReferences = true;
update = TreeObjectEvent.UPDATE_LOCAL;
}
}
if (updateReferences) {
treeObjectEvent.update = update;
fireTreeObjectPropertyChanged(treeObjectEvent);
projectTreeObject.save(false);
}
}
projectTreeObject.checkMissingProjects();
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ProjectExplorerView method loadedProjectsHaveReferences.
private boolean loadedProjectsHaveReferences() {
ViewContentProvider provider = (ViewContentProvider) viewer.getContentProvider();
if (provider != null) {
Object[] objects = provider.getChildren(provider.getTreeRoot());
for (int i = 0; i < objects.length; i++) {
TreeObject treeObject = (TreeObject) objects[i];
if (treeObject instanceof ProjectTreeObject) {
// Check for references on projects
ProjectTreeObject projectTreeObject = (ProjectTreeObject) treeObject;
List<Reference> references = ((Project) projectTreeObject.getObject()).getReferenceList();
if (references.size() > 0) {
for (Reference reference : references) {
if (reference instanceof ProjectSchemaReference) {
return true;
}
}
}
// Check for sequences (potential call steps)
List<Sequence> sequences = ((Project) projectTreeObject.getObject()).getSequencesList();
if (sequences.size() > 0) {
return true;
}
}
}
}
return false;
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ProjectExplorerView method importProject.
public boolean importProject(String filePath, String targetProjectName) throws EngineException, IOException, CoreException {
TreeObject[] projectTreeObject = { null };
if (targetProjectName != null) {
projectTreeObject[0] = ((ViewContentProvider) viewer.getContentProvider()).getProjectRootObject(targetProjectName);
}
// if project already exists, backup it and delete it after
if (projectTreeObject[0] != null) {
if (Engine.isProjectFile(filePath)) {
DatabaseObjectsManager.deleteDir(new File(Engine.projectDir(targetProjectName) + "/_data"));
DatabaseObjectsManager.deleteDir(new File(Engine.projectDir(targetProjectName) + "/_private"));
}
// delete project resource (but not content)
// ConvertigoPlugin.getDefault().deleteProjectPluginResource(false, targetProjectName);
}
ConvertigoPlugin.logInfo("Import project from file \"" + filePath + "\"");
boolean doImport;
if (Engine.isProjectFile(filePath)) {
ConvertigoPlugin.getDefault().declareProject(targetProjectName, new File(filePath));
doImport = true;
} else if (((filePath.endsWith(".car") || filePath.endsWith(".zip")) && (targetProjectName != null)) || filePath.matches("https?://.+")) {
doImport = false;
} else {
return false;
}
Engine.execute(() -> {
Exception[] exception = { null };
try {
Project importedProject = doImport ? Engine.theApp.databaseObjectsManager.importProject(filePath, true) : Engine.theApp.databaseObjectsManager.deployProject(filePath, targetProjectName, true);
viewer.getControl().getDisplay().syncExec(() -> {
try {
// project's name may have been changed because of non-normalized name (fix ticket #788 : Cannot import project 213.car)
String projectName = importedProject.getName();
// loads project into tree view
if (projectTreeObject[0] == null) {
importProjectTreeObject(projectName);
} else {
// recreate project resource
ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
reloadProject(projectTreeObject[0]);
}
refreshTree();
} catch (Exception e) {
exception[0] = e;
}
});
} catch (Exception e) {
exception[0] = e;
}
if (exception[0] != null) {
viewer.getControl().getDisplay().syncExec(() -> {
Engine.logStudio.error("Failed to import project", exception[0]);
ConvertigoPlugin.errorMessageBox("Failed to import project [" + exception[0].getClass().getSimpleName() + "]: " + exception[0].getMessage());
});
}
});
return true;
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ViewLabelProvider method getText.
@Override
public String getText(Object obj) {
if (obj instanceof DatabaseObjectTreeObject) {
DatabaseObject dbo = ((DatabaseObjectTreeObject) obj).getObject();
if (dbo.isSymbolError() || (dbo instanceof Project && ((Project) dbo).undefinedGlobalSymbols)) {
return obj.toString() + " (! undefined symbol !)";
}
String osname = System.getProperty("os.name");
String version = System.getProperty("os.version");
boolean notShownSpecialChar = osname.toLowerCase().startsWith("windows") && Double.parseDouble(version) < 6.2;
boolean isMac = osname.toLowerCase().startsWith("mac");
if (dbo instanceof RequestableObject && !notShownSpecialChar) {
return (((RequestableObject) dbo).getAccessibility() == Accessibility.Private ? "🔒 " : (((RequestableObject) dbo).getAccessibility() == Accessibility.Hidden ? "👓 " : (isMac ? "🚪 " : " 🚪 "))) + (dbo instanceof Sequence ? (((Sequence) dbo).isAutoStart() ? "💡 " : "") : "") + obj.toString();
}
}
return obj.toString();
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ProjectLoadingJob method run.
protected IStatus run(IProgressMonitor monitor) {
this.monitor = monitor;
synchronized (unloadedProjectTreeObject) {
if (unloadedProjectTreeObject.getParent() == null) {
Display.getDefault().asyncExec(() -> viewer.refresh());
return Status.OK_STATUS;
}
try {
int worksNumber = 2 * ConvertigoPlugin.projectManager.getNumberOfObjects(projectName);
monitor.beginTask("Opening project " + projectName + "...", worksNumber);
if (monitor.isCanceled()) {
Status status = new Status(Status.CANCEL, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Project " + projectName + " not loaded because of user abort", null);
return status;
}
Project project;
try {
monitor.subTask("Importing the project...");
Engine.theApp.databaseObjectsManager.clearCacheIfSymbolError(projectName);
project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
if (project == null) {
unloadedProjectTreeObject.getParent().removeChild(unloadedProjectTreeObject);
Status status = new Status(Status.CANCEL, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Project " + projectName + " doesn't exists", null);
return status;
}
monitor.subTask("Refreshing project ressources...");
String projectDir = Engine.projectDir(projectName);
ConvertigoPlugin.projectManager.getProjectExplorerView().createDir(projectName);
ConvertigoPlugin.getDefault().createProjectPluginResource(projectName, projectDir, monitor);
Engine.theApp.databaseObjectsManager.addDatabaseObjectListener(this);
if (project.undefinedGlobalSymbols) {
synchronized (Engine.theApp.databaseObjectsManager) {
// parallel projects opening with undefined symbols, check after the first wizard
project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
if (project.undefinedGlobalSymbols) {
final boolean[] created = { false };
new WalkHelper() {
boolean create = false;
boolean forAll = false;
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (databaseObject.isSymbolError()) {
for (Entry<String, Set<String>> entry : databaseObject.getSymbolsErrors().entrySet()) {
Set<String> undefinedSymbols = Engine.theApp.databaseObjectsManager.symbolsSetCheckUndefined(entry.getValue());
if (!undefinedSymbols.isEmpty()) {
if (!forAll) {
boolean[] response = ConvertigoPlugin.warningGlobalSymbols(projectName, databaseObject.getName(), databaseObject.getDatabaseType(), entry.getKey(), "" + databaseObject.getCompilablePropertySourceValue(entry.getKey()), undefinedSymbols, true);
create = response[0];
forAll = response[1];
created[0] |= create;
}
if (create) {
Engine.theApp.databaseObjectsManager.symbolsCreateUndefined(undefinedSymbols);
}
}
}
}
super.walk(databaseObject);
}
}.init(project);
if (created[0]) {
project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName, false);
}
}
}
}
} finally {
Engine.theApp.databaseObjectsManager.removeDatabaseObjectListener(this);
}
if (monitor.isCanceled()) {
Status status = new Status(Status.CANCEL, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Project " + projectName + " not loaded because of user abort", null);
return status;
}
monitor.subTask("Creating connectors...");
monitor.subTask("Updating tree view...");
TreeParent invisibleRoot = unloadedProjectTreeObject.getParent();
projectTreeObject = new ProjectTreeObject(viewer, project);
defaultConnectorTreeObject = null;
demoTraceTreeObject = null;
invisibleRoot.removeChild(unloadedProjectTreeObject);
invisibleRoot.addChild(projectTreeObject);
ConvertigoPlugin.projectManager.setCurrentProject((ProjectTreeObject) projectTreeObject);
ConvertigoPlugin.getDefault().getProjectPluginResource(projectName, monitor).refreshLocal(IResource.DEPTH_INFINITE, monitor);
loadDatabaseObject(projectTreeObject, project);
// Comment out the following line to disable the resources tree part
// loadResource(projectTreeObject, "Resources", resourceProject.members());
Status status = new Status(Status.OK, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Project " + projectName + " loaded", null);
return status;
} catch (Exception e) {
Status status = null;
unloadedProjectTreeObject.isLoadable = false;
if (e.getCause() instanceof ProjectInMigrationProcessException)
status = new Status(Status.WARNING, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Could not open project \"" + projectName + "\" while it was still in migration check process", e);
else
status = new Status(Status.ERROR, ConvertigoPlugin.PLUGIN_UNIQUE_ID, 0, "Error while loading project " + projectName, e);
return status;
} finally {
// Updating the tree viewer
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (projectTreeObject != null) {
viewer.refresh();
ISelection selection = new StructuredSelection(projectTreeObject);
viewer.setSelection(selection, true);
if (defaultConnectorTreeObject != null && ConvertigoPlugin.getAutoOpenDefaultConnector())
defaultConnectorTreeObject.launchEditor();
TreeObjectEvent treeObjectEvent = null;
if (isCopy)
treeObjectEvent = new TreeObjectEvent(projectTreeObject, "name", originalName, projectName, 0);
else
treeObjectEvent = new TreeObjectEvent(projectTreeObject);
ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectAdded(treeObjectEvent);
viewer.getControl().getDisplay().asyncExec(new Runnable() {
public void run() {
if (demoTraceTreeObject != null)
demoTraceTreeObject.play(false);
Engine.execute(() -> {
Project.executeAutoStartSequences(projectName);
});
}
});
}
}
});
}
}
}
Aggregations