use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class DatabaseObjectDeleteAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
treeNodesToUpdate = new ArrayList<>();
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject[] selectedTreeObjects = explorerView.getSelectedTreeObjects();
if (selectedTreeObjects != null) {
Collection<DatabaseObjectTreeObject> treeObjects = new HashSet<>(selectedTreeObjects.length);
for (TreeObject t : Arrays.asList(selectedTreeObjects)) {
if (t instanceof DatabaseObjectTreeObject) {
treeObjects.add((DatabaseObjectTreeObject) t);
}
}
;
if (treeObjects.size() > 1) {
for (DatabaseObjectTreeObject t : new ArrayList<>(treeObjects)) {
TreeObject parent = t.getParent();
while (parent != null) {
if (treeObjects.contains(parent)) {
treeObjects.remove(t);
parent = null;
} else {
parent = parent.getParent();
}
}
}
;
}
if (treeObjects.size() > 1) {
List<DatabaseObjectTreeObject> list = new ArrayList<>(treeObjects);
Collections.sort(list, new Comparator<DatabaseObjectTreeObject>() {
@Override
public int compare(DatabaseObjectTreeObject o1, DatabaseObjectTreeObject o2) {
if (o1 instanceof ProjectTreeObject) {
if (o2 instanceof ProjectTreeObject) {
return o1.getName().compareTo(o2.getName());
}
return -1;
} else if (o2 instanceof ProjectTreeObject) {
return 1;
}
return o1.getName().compareTo(o2.getName());
}
});
treeObjects = list;
}
MultipleDeletionDialog dialog = new MultipleDeletionDialog(shell, "Object Deletion", treeObjects.size() != 1);
for (DatabaseObjectTreeObject treeObject : treeObjects) {
String message = java.text.MessageFormat.format("Do you really want to delete the {0} \"{1}\" and all its sub-objects?", treeObject instanceof ProjectTreeObject ? "project" : "object", treeObject.getName());
if (treeObject instanceof ProjectTreeObject) {
message += "\nProject location: " + ((Project) treeObject.getObject()).getDirPath();
dialog.setToggle("Delete project content on disk (cannot be undone)", false);
} else {
dialog.removeToggle();
}
if (!dialog.shouldBeDeleted(message)) {
continue;
}
try {
if (treeObject instanceof ProjectTreeObject) {
((ProjectTreeObject) treeObject).closeAllEditors();
} else if (treeObject instanceof SequenceTreeObject) {
((ProjectTreeObject) ((SequenceTreeObject) treeObject).getParent().getParent()).closeSequenceEditors((Sequence) treeObject.getObject());
} else if (treeObject instanceof ConnectorTreeObject) {
((ProjectTreeObject) ((ConnectorTreeObject) treeObject).getParent().getParent()).closeConnectorEditors((Connector) treeObject.getObject());
} else if (treeObject instanceof StepTreeObject) {
// We close the editor linked with the SimpleStep (=SequenceJsStep)
if (treeObject.getObject() instanceof SimpleStep) {
boolean find = false;
SimpleStep simpleStep = (SimpleStep) treeObject.getObject();
IWorkbenchPage page = this.getActivePage();
IEditorReference[] editors = page.getEditorReferences();
int _i = 0;
while (find != true && _i < editors.length) {
IEditorReference editor = editors[_i];
IEditorInput input = editor.getEditorInput();
if (input instanceof JScriptEditorInput) {
if (simpleStep.equals(((JScriptEditorInput) input).getDatabaseObject())) {
find = true;
IEditorPart editorPart = page.findEditor(input);
if (editorPart != null) {
page.activate(editorPart);
page.closeEditor(editorPart, false);
}
}
}
++_i;
}
}
} else if (treeObject instanceof MobileComponentTreeObject) {
((MobileComponentTreeObject) treeObject).closeAllEditors(false);
}
if (treeObject instanceof ProjectTreeObject) {
explorerView.removeProjectTreeObject(treeObject);
final Project project = (Project) treeObject.getObject();
Job rmProject = new Job("Remove '" + project.getName() + "' project") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
delete(project, dialog.getToggleState());
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to delete the '" + project.getName() + "' project.");
return new MultiStatus(ConvertigoPlugin.PLUGIN_UNIQUE_ID, IStatus.ERROR, "Failed to remove the '" + project.getName() + "' project.", e);
}
return Status.OK_STATUS;
}
};
rmProject.schedule();
} else {
delete(treeObject);
// prevents treeObject and its childs to receive further TreeObjectEvents
if (treeObject instanceof TreeObjectListener) {
explorerView.removeTreeObjectListener(treeObject);
}
treeObject.removeAllChildren();
}
explorerView.fireTreeObjectRemoved(new TreeObjectEvent(treeObject));
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to delete the current selected object.");
}
}
;
// Updating the tree and the properties panel
Enumeration<DatabaseObjectTreeObject> enumeration = Collections.enumeration(treeNodesToUpdate);
DatabaseObjectTreeObject parentTreeObject;
while (enumeration.hasMoreElements()) {
parentTreeObject = enumeration.nextElement();
if (parentTreeObject != null) {
explorerView.reloadTreeObject(parentTreeObject);
explorerView.setSelectedTreeObject(parentTreeObject);
}
}
// Refresh tree to show potential 'broken' steps
explorerView.refreshTree();
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to delete object!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class OpenFlowViewerAction method run.
@Override
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
if ((treeObject != null) && (treeObject instanceof SequenceTreeObject)) {
SequenceTreeObject sequenceTreeObject = (SequenceTreeObject) treeObject;
Sequence sequence = sequenceTreeObject.getObject();
ConvertigoPlugin.getDefault().openFlowViewerEditor(sequence);
}
}
} catch (NoSuchElementException e) {
ConvertigoPlugin.logException(e, "No previous XML file found");
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to execute the selected sequence!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class MobilePickerContentProvider method addSequences.
private void addSequences(Map<String, Set<String>> map, TVObject tvs, Object object, boolean isReferenced) {
if (object != null) {
if (object instanceof Project) {
Project project = (Project) object;
for (Sequence s : project.getSequencesList()) {
String label = isReferenced ? s.getQName() : s.getName();
SourceData sd = null;
try {
sd = Filter.Sequence.toSourceData(new JSONObject().put("sequence", s.getQName()));
} catch (JSONException e) {
e.printStackTrace();
}
tvs.add(new TVObject(label, s, sd));
Set<String> infos = map.get(s.getQName());
if (infos != null) {
for (String info : infos) {
try {
JSONObject jsonInfo = new JSONObject(info);
if (jsonInfo.has("marker")) {
String marker = jsonInfo.getString("marker");
if (!marker.isEmpty()) {
sd = Filter.Sequence.toSourceData(new JSONObject().put("sequence", s.getQName()).put("marker", marker));
tvs.add(new TVObject(label + "#" + marker, s, sd, jsonInfo));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
}
}
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class MobileSmartSource method getDatabaseObject.
public DatabaseObject getDatabaseObject(String rootDboName) {
List<String> sourceData = getSources();
String sourceInput = sourceData.size() > 0 ? sourceData.get(0) : null;
if (sourceInput != null) {
if (Filter.Action.equals(getFilter())) {
Matcher m = actionPattern.matcher(sourceInput);
if (m.find()) {
String stack = m.group(1);
try {
String p = stack.replaceFirst("stack\\[", "").replaceFirst("\\]", "");
// ignore quotes
p = p.substring(1, p.length() - 1);
long priority = Long.valueOf(p, 10);
return findDatabaseObject(rootDboName, priority);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Shared.equals(getFilter())) {
Matcher m = sharedPattern.matcher(sourceInput);
if (m.find()) {
String shared = m.group(1);
try {
long priority = Long.valueOf(shared.replaceFirst("params", ""), 10);
return findDatabaseObject(rootDboName, priority);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Iteration.equals(getFilter())) {
Matcher m = directivePattern.matcher(sourceInput);
if (m.find()) {
String item = m.group(1);
try {
long priority = Long.valueOf(item.replaceFirst("item", ""), 10);
return findDatabaseObject(rootDboName, priority);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Form.equals(getFilter())) {
Matcher m = formPattern.matcher(sourceInput);
if (m.find()) {
String form = m.group(1);
try {
long priority = Long.valueOf(form.replaceFirst("form", ""), 10);
return findDatabaseObject(rootDboName, priority);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Global.equals(getFilter())) {
Matcher m = globalPattern.matcher(sourceInput);
if (m.find()) {
try {
String projectName = getProjectName();
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
DatabaseObject dbo = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
return dbo;
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Database.equals(getFilter())) {
Matcher m = cafPattern.matcher(sourceInput);
if (m.find()) {
try {
String name = m.group(1);
name = name.replaceFirst("fs://", "");
name = name.replaceFirst("\\.view", "");
name = name.replaceFirst("\\.get", "");
int i = name.indexOf('#');
if (i != -1) {
name = name.substring(0, i);
}
int index = name.indexOf('.');
String projectName = index != -1 ? name.substring(0, index) : getProjectName();
String dbName = index != -1 ? name.substring(index + 1) : name;
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
FullSyncConnector connector = (FullSyncConnector) project.getConnectorByName(dbName);
String documentName = getParameters().get("ddoc");
DesignDocument ddoc = (DesignDocument) connector.getDocumentByName(documentName);
return ddoc;
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (Filter.Sequence.equals(getFilter())) {
Matcher m = cafPattern.matcher(sourceInput);
if (m.find()) {
try {
String name = m.group(1);
int i = name.indexOf('#');
if (i != -1) {
name = name.substring(0, i);
}
int index = name.indexOf('.');
String projectName = index != -1 ? name.substring(0, index) : getProjectName();
projectName = projectName.isEmpty() ? getProjectName() : projectName;
String sequenceName = index != -1 ? name.substring(index + 1) : name;
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
Sequence sequence = project.getSequenceByName(sequenceName);
return sequence;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return null;
}
use of com.twinsoft.convertigo.beans.core.Sequence in project convertigo by convertigo.
the class SequenceStep method getTargetSequence.
public Sequence getTargetSequence() throws EngineException {
Project p = getTargetProject(projectName);
if (p == null) {
throw new EngineException("There is no project named \"" + projectName + "\" found.");
}
List<Sequence> v = p.getSequencesList();
Sequence targetSequence = (sequenceName.equals("") ? (v.isEmpty() ? null : (Sequence) v.get(0)) : p.getSequenceByName(sequenceName));
return targetSequence;
}
Aggregations