use of com.twinsoft.convertigo.eclipse.dialogs.CustomDialog in project convertigo by convertigo.
the class CicsTransactionImportCopybookAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
boolean bInputMap = true;
CustomDialog customDialog = new CustomDialog(shell, "Import a copybook", "Do you want to import the copybook into the transaction input map or output map?", 500, 150, new ButtonSpec("Input map", true), new ButtonSpec("Outut map", false), new ButtonSpec(IDialogConstants.CANCEL_LABEL, false));
int index = customDialog.open();
switch(index) {
case 0:
bInputMap = true;
break;
case 1:
bInputMap = false;
break;
case 2:
return;
}
String filePath = null;
FileDialog fileDialog = new FileDialog(shell);
fileDialog.setText("Import a copybook");
fileDialog.setFilterPath(Engine.PROJECTS_PATH);
filePath = fileDialog.open();
if (filePath != null) {
ConvertigoPlugin.logDebug("Import copybook from file \"" + filePath + "\"");
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
Object databaseObject = treeObject.getObject();
if ((databaseObject != null) && (databaseObject instanceof CicsTransaction)) {
CicsTransaction transaction = (CicsTransaction) databaseObject;
FileReader reader = null;
try {
reader = new FileReader(filePath);
transaction.importCopyBook(bInputMap, reader);
} finally {
if (reader != null) {
reader.close();
}
}
explorerView.updateFirstSelectedTreeObject();
StructuredSelection structuredSelection = new StructuredSelection(treeObject);
ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged(explorerView, structuredSelection);
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to import the copybook!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.eclipse.dialogs.CustomDialog 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.eclipse.dialogs.CustomDialog in project convertigo by convertigo.
the class ProjectTreeObject method checkMissingProjects.
public void checkMissingProjects(final boolean doReload) {
synchronized (this) {
if (isCheckMissingProjects) {
return;
}
isCheckMissingProjects = true;
}
final Project project = getObject();
Job.create("Check missing project for " + project.getName(), (monitor) -> {
try {
final Set<String> missingProjects = project.getMissingProjects().keySet();
final Set<String> missingProjectReferences = project.getMissingProjectReferences().keySet();
if (!missingProjects.isEmpty() || !missingProjectReferences.isEmpty()) {
List<String> allProjects = Engine.theApp.databaseObjectsManager.getAllProjectNamesList(false);
for (Iterator<String> i = missingProjects.iterator(); i.hasNext(); ) {
String targetProjectName = i.next();
if (allProjects.contains(targetProjectName)) {
Display.getDefault().syncExec(() -> {
try {
ProjectExplorerView pev = ConvertigoPlugin.getDefault().getProjectExplorerView();
TreeObject obj = pev.getProjectRootObject(targetProjectName);
if (obj != null && obj instanceof UnloadedProjectTreeObject) {
pev.loadProject(((UnloadedProjectTreeObject) obj));
i.remove();
}
} catch (Exception e) {
Engine.logStudio.warn("Failed to open \"" + targetProjectName + "\"", e);
}
});
}
}
Map<String, ProjectUrlParser> refToImport = new HashMap<>();
for (Reference ref : project.getReferenceList()) {
if (ref instanceof ProjectSchemaReference) {
ProjectSchemaReference prjRef = (ProjectSchemaReference) ref;
if (missingProjects.contains(prjRef.getParser().getProjectName()) && prjRef.getParser().isValid()) {
refToImport.put(prjRef.getParser().getProjectName(), prjRef.getParser());
}
}
}
if (!refToImport.isEmpty()) {
Engine.execute(() -> {
boolean loaded = false;
for (ProjectUrlParser parser : refToImport.values()) {
try {
loaded |= Engine.theApp.referencedProjectManager.importProject(parser) != null;
} catch (Exception e) {
Engine.logStudio.warn("Failed to load '" + parser.getProjectName() + "'", e);
}
}
if (loaded) {
Engine.theApp.fireMigrationFinished(new EngineEvent(""));
}
});
return;
}
String message = "For \"" + project.getName() + "\" project :\n";
for (String targetProjectName : missingProjects) {
message += " > The project \"" + targetProjectName + "\" is missing\n";
}
for (String targetProjectName : missingProjectReferences) {
message += " > The reference to project \"" + targetProjectName + "\" is missing\n";
}
message += "\nPlease create missing reference(s) and import missing project(s), or correct your project.";
if (!missingProjectReferences.isEmpty()) {
final String msg = message;
final String warn = message;
Display.getDefault().syncExec(() -> {
CustomDialog customDialog = new CustomDialog(null, "Project references", msg + "\n\nDo you want to automatically add reference objects ?", 670, 250, new ButtonSpec("Always", true), new ButtonSpec("Never", false));
String autoCreate = ConvertigoPlugin.getProperty(ConvertigoPlugin.PREFERENCE_AUTO_CREATE_PROJECT_REFERENCE);
int response = autoCreate.isEmpty() ? customDialog.open() : (autoCreate.equalsIgnoreCase("true") ? 0 : 1);
ConvertigoPlugin.setProperty(ConvertigoPlugin.PREFERENCE_AUTO_CREATE_PROJECT_REFERENCE, response == 0 ? "true" : "false");
if (response == 0) {
for (String targetProjectName : missingProjectReferences) {
try {
ProjectSchemaReference reference = new ProjectSchemaReference();
String projectName = targetProjectName;
reference.setName(targetProjectName + "_reference");
projectName = ProjectUrlParser.getUrl(projectName);
reference.setProjectName(projectName);
reference.hasChanged = true;
project.add(reference);
} catch (Exception e) {
ConvertigoPlugin.logException(e, "failed to add a reference to '" + targetProjectName + "'");
}
}
try {
if (doReload || autoCreate.isEmpty()) {
ProjectExplorerView pev = ConvertigoPlugin.getDefault().getProjectExplorerView();
pev.reloadTreeObject(ProjectTreeObject.this);
}
} catch (Exception e) {
e.printStackTrace();
}
hasBeenModified(true);
} else {
Engine.logBeans.warn(warn);
}
});
} else if (!missingProjects.isEmpty()) {
ConvertigoPlugin.warningMessageBox(message);
}
}
} finally {
isCheckMissingProjects = false;
}
}).schedule();
}
Aggregations