use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ClipboardCopyProjectRemoteURLAction method run.
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();
Object databaseObject = treeObject.getObject();
if (databaseObject instanceof Project) {
Project project = (Project) databaseObject;
String url = ProjectUrlParser.getUrl(project);
if (!project.getName().equals(url)) {
Clipboard clipboard = new Clipboard(display);
TextTransfer textTransfer = TextTransfer.getInstance();
clipboard.setContents(new String[] { url }, new Transfer[] { textTransfer });
clipboard.dispose();
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to copy!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ConvertMobileUIApplicationToNgxAction method run.
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();
ProjectTreeObject projectTreeObject = treeObject.getProjectTreeObject();
if (projectTreeObject.getModified()) {
ConvertigoPlugin.warningMessageBox("Please save project before converting it.");
return;
}
Project project = projectTreeObject.getObject();
InputDialog dlg = new InputDialog(shell, "Converting Mobile Application to NGX", "Your project '" + project.getName() + "' will be converted to use the new version of the Mobile Builder.\n" + "Please enter a new project name for a converted copy.\n" + "Or convert the current project.", project.getName(), new IInputValidator() {
@Override
public String isValid(String newText) {
if (newText.isBlank()) {
return "cannot be blank";
}
if (!StringUtils.isNormalized(newText)) {
return "don't use special character";
}
if (newText.equals(project.getName())) {
return null;
}
if (Engine.theApp.databaseObjectsManager.existsProject(newText)) {
return "a project with that name already exists";
}
return null;
}
});
if (dlg.open() == Window.CANCEL) {
return;
}
String projectName = dlg.getValue();
if (projectName.equals(project.getName())) {
PlainMessageDialog msg = PlainMessageDialog.getBuilder(shell, "Confirmation").buttonLabels(Arrays.asList("Yes", "No")).image(IconAndMessageDialog.getImage(IconAndMessageDialog.DLG_IMG_MESSAGE_WARNING)).message("You are about to modify the current project.\n" + "The operation cannot be undone.\n" + "Please make a backup of your current version before continuing.\n" + "Are you sure you want to convert now?").build();
int response = msg.open();
if (response == 0) {
File projectDir = project.getDirFile();
explorerView.setSelectedTreeObject(projectTreeObject);
explorerView.unloadSelectedProjectTreeObject();
Job.create("Project '" + projectName + "' converting to NGX", monitor -> {
monitor.beginTask("Converting to NGX...", IProgressMonitor.UNKNOWN);
try {
new NgxConverter(projectDir).convertFile();
} catch (Exception e) {
Engine.logStudio.error("Error while converting to NGX", e);
}
monitor.beginTask("Open the converted project...", IProgressMonitor.UNKNOWN);
display.syncExec(() -> {
try {
TreeObject to = explorerView.getProjectRootObject(projectName);
if (to instanceof UnloadedProjectTreeObject) {
explorerView.loadProject((UnloadedProjectTreeObject) to);
} else {
ConvertigoPlugin.errorMessageBox("Cannot find the '" + projectName + "' project");
}
} catch (EngineException e) {
ConvertigoPlugin.errorMessageBox("Failed to get the '" + projectName + "' project: " + e.getMessage());
}
});
}).schedule();
}
} else {
Job.create("Project '" + projectName + "' converting to NGX", monitor -> {
try {
monitor.beginTask("Exporting '" + project.getName() + "'", IProgressMonitor.UNKNOWN);
File car = CarUtils.makeArchive(project, ArchiveExportOption.all);
monitor.beginTask("Importing '" + projectName + "'", IProgressMonitor.UNKNOWN);
Project prj = Engine.theApp.databaseObjectsManager.deployProject(car.getAbsolutePath(), projectName, true);
if (prj == null) {
return;
}
monitor.beginTask("Converting to NGX...", IProgressMonitor.UNKNOWN);
new NgxConverter(prj.getDirFile()).convertFile();
prj = Engine.theApp.databaseObjectsManager.importProject(Engine.projectYamlFile(projectName), true);
} catch (Exception e) {
Engine.logStudio.error("Error while converting to NGX", e);
}
monitor.beginTask("Open the converted project...", IProgressMonitor.UNKNOWN);
display.syncExec(() -> {
try {
explorerView.importProjectTreeObject(projectName);
} catch (Exception e) {
ConvertigoPlugin.errorMessageBox("Failed to get the '" + projectName + "' project: " + e.getMessage());
}
});
}).schedule();
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to edit mobile component class!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class NgxPickerContentProvider method getChildren.
@Override
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof TVObject) {
return ((TVObject) parentElement).children.toArray();
} else if (parentElement instanceof MobileComponent) {
MobileComponent mobileComponent = (MobileComponent) parentElement;
Project project = mobileComponent.getProject();
ProjectExplorerView projectExplorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
List<String> projectNames = Engine.theApp.databaseObjectsManager.getAllProjectNamesList();
Map<String, Set<String>> map = mobileComponent.getApplication().getInfoMap();
TVObject root = new TVObject("root", mobileComponent, null);
if (filter.equals(Filter.Action)) {
TVObject tvi = root.add(new TVObject("actions"));
TVObject tvEvents = tvi.add(new TVObject("events"));
TVObject tvControls = tvi.add(new TVObject("controls"));
addActions(tvi, mobileComponent);
if (tvEvents.isEmpty()) {
tvi.remove(tvEvents);
}
if (tvControls.isEmpty()) {
tvi.remove(tvControls);
}
}
if (filter.equals(Filter.Shared)) {
TVObject tvi = root.add(new TVObject("shared"));
addSharedComponents(tvi, mobileComponent);
}
if (filter.equals(Filter.Sequence)) {
TVObject tvs = root.add(new TVObject("sequences"));
for (String projectName : projectNames) {
try {
Project p = projectExplorerView.getProject(projectName);
boolean isReferenced = !p.getName().equals(project.getName());
addSequences(map, tvs, isReferenced ? p : project, isReferenced);
} catch (Exception e) {
}
}
}
if (filter.equals(Filter.Database)) {
TVObject tvd = root.add(new TVObject("databases"));
for (String projectName : projectNames) {
try {
Project p = projectExplorerView.getProject(projectName);
boolean isReferenced = !p.getName().equals(project.getName());
addFsObjects(map, tvd, isReferenced ? p : project, isReferenced);
} catch (Exception e) {
}
}
}
if (filter.equals(Filter.Iteration)) {
TVObject tvi = root.add(new TVObject("iterations"));
addIterations(tvi, mobileComponent);
}
if (filter.equals(Filter.Form)) {
TVObject tvi = root.add(new TVObject("forms"));
addForms(tvi, mobileComponent);
}
if (filter.equals(Filter.Global)) {
TVObject tvi = root.add(new TVObject("globals"));
addGlobals(tvi, mobileComponent.getApplication());
}
if (filter.equals(Filter.Local)) {
TVObject tvi = root.add(new TVObject("locals"));
addLocals(tvi, mobileComponent.getApplication());
}
return root.children.toArray();
} else if (parentElement instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) parentElement;
TVObject root = new TVObject("root", jsonObject, null);
addJsonObjects(root);
return root.children.toArray();
}
return new Object[0];
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class NgxPickerContentProvider method addFsObjects.
private void addFsObjects(Map<String, Set<String>> map, TVObject tvd, Object object, boolean isReferenced) {
if (object != null) {
if (object instanceof Project) {
Project project = (Project) object;
for (Connector c : project.getConnectorsList()) {
if (c instanceof FullSyncConnector) {
String label = isReferenced ? c.getQName() : c.getName();
TVObject tvc = tvd.add(new TVObject(label));
for (Document d : c.getDocumentsList()) {
if (d instanceof DesignDocument) {
TVObject tdd = tvc.add(new TVObject(d.getName()));
JSONObject views = CouchKey.views.JSONObject(((DesignDocument) d).getJSONObject());
if (views != null) {
for (Iterator<String> it = GenericUtils.cast(views.keys()); it.hasNext(); ) {
try {
Set<String> infos = null;
String view = it.next();
String key = c.getQName() + "." + d.getName() + "." + view;
TVObject tvv = tdd.add(new TVObject(view));
SourceData sd = null;
try {
sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "get"));
} catch (JSONException e) {
e.printStackTrace();
}
tvv.add(new TVObject("get", d, sd));
infos = map.get(key + ".get");
if (infos == null) {
infos = map.get(c.getQName() + ".get");
}
if (infos != null) {
for (String info : infos) {
try {
JSONObject jsonInfo = new JSONObject(info);
boolean includeDocs = false;
if (jsonInfo.has("include_docs")) {
includeDocs = Boolean.valueOf(jsonInfo.getString("include_docs")).booleanValue();
}
if (jsonInfo.has("marker")) {
String marker = jsonInfo.getString("marker");
if (!marker.isEmpty()) {
String name = "get" + "#" + marker;
sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "get").put("marker", marker).put("includeDocs", includeDocs));
tvv.add(new TVObject(name, d, sd, jsonInfo));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
try {
sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "view"));
} catch (JSONException e) {
e.printStackTrace();
}
tvv.add(new TVObject("view", d, sd));
infos = map.get(key + ".view");
if (infos != null) {
for (String info : infos) {
try {
JSONObject jsonInfo = new JSONObject(info);
boolean includeDocs = false;
if (jsonInfo.has("include_docs")) {
includeDocs = Boolean.valueOf(jsonInfo.getString("include_docs")).booleanValue();
}
if (jsonInfo.has("marker")) {
String marker = jsonInfo.getString("marker");
if (!marker.isEmpty()) {
String name = "view" + "#" + marker;
sd = Filter.Database.toSourceData(new JSONObject().put("connector", c.getQName()).put("document", d.getQName()).put("queryview", view).put("verb", "view").put("marker", marker).put("includeDocs", includeDocs));
tvv.add(new TVObject(name, d, sd, jsonInfo));
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}
}
}
}
}
use of com.twinsoft.convertigo.beans.core.Project in project convertigo by convertigo.
the class ClipboardManager method cutAndPaste.
public void cutAndPaste(final DatabaseObject object, DatabaseObject parentDatabaseObject) throws ConvertigoException {
// Verifying if a sheet with the same browser does not already exist
if (object instanceof Sheet) {
String browser = ((Sheet) object).getBrowser();
Sheet sheet = null;
if (parentDatabaseObject instanceof ScreenClass) {
sheet = ((ScreenClass) parentDatabaseObject).getLocalSheet(browser);
} else if (parentDatabaseObject instanceof RequestableObject) {
sheet = ((RequestableObject) parentDatabaseObject).getSheet(browser);
}
if (sheet != null) {
throw new EngineException("You cannot cut and paste the sheet because a sheet is already defined for the browser \"" + browser + "\" in the screen class \"" + parentDatabaseObject.getName() + "\".");
}
}
if (object instanceof Step) {
if (object instanceof ThenStep) {
throw new EngineException("You cannot cut the \"Then\" step");
}
if (object instanceof ElseStep) {
throw new EngineException("You cannot cut the \"Else\" step");
}
}
if (object instanceof Statement) {
if (object instanceof ThenStatement)
throw new EngineException("You cannot cut the \"Then\" statement");
if (object instanceof ElseStatement)
throw new EngineException("You cannot cut the \"Else\" statement");
}
// Verify object is accepted for paste
if (!DatabaseObjectsManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.MobileComponent) {
if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
if (!com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
String tplVersion = com.twinsoft.convertigo.beans.mobile.components.dynamic.ComponentManager.getTplRequired(object);
throw new EngineException("Template project " + tplVersion + " compatibility required");
}
} else if (parentDatabaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.MobileComponent) {
if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.acceptDatabaseObjects(parentDatabaseObject, object)) {
throw new EngineException("You cannot cut and paste to a " + parentDatabaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
if (!com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.isTplCompatible(parentDatabaseObject, object)) {
String tplVersion = com.twinsoft.convertigo.beans.ngx.components.dynamic.ComponentManager.getTplRequired(object);
throw new EngineException("Template project " + tplVersion + " compatibility required");
}
}
// Verify if a child object with same name exist
boolean bContinue = true;
boolean bIncName = false;
String dboName = object.getName();
while (bContinue) {
try {
if (bIncName) {
dboName = DatabaseObject.incrementName(dboName);
object.setName(dboName);
}
new WalkHelper() {
boolean root = true;
boolean find = false;
@Override
protected boolean before(DatabaseObject databaseObject, Class<? extends DatabaseObject> dboClass) {
boolean isInstance = dboClass.isInstance(object);
find |= isInstance;
return isInstance;
}
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (root) {
root = false;
if (databaseObject instanceof Project) {
if (object instanceof Connector && ((Connector) object).isDefault) {
throw new EngineException("You cannot cut the default connector to another project");
}
} else if (databaseObject instanceof Connector) {
if (object instanceof ScreenClass) {
throw new EngineException("You cannot cut the default screen class to another connector");
} else if (object instanceof Transaction && ((Transaction) object).isDefault) {
throw new EngineException("You cannot cut the default transaction to another connector");
}
} else if (databaseObject instanceof ScreenClass) {
if (object instanceof Criteria && databaseObject.getParent() instanceof Connector) {
throw new EngineException("You cannot cut the criterion of default screen class");
}
} else if (databaseObject instanceof MobileObject) {
if (databaseObject instanceof com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent) {
if (object instanceof com.twinsoft.convertigo.beans.mobile.components.PageComponent) {
com.twinsoft.convertigo.beans.mobile.components.PageComponent pc = GenericUtils.cast(object);
if (pc.isRoot) {
throw new EngineException("You cannot cut the root page to another application");
}
}
} else if (databaseObject instanceof com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) {
if (object instanceof com.twinsoft.convertigo.beans.ngx.components.PageComponent) {
com.twinsoft.convertigo.beans.ngx.components.PageComponent pc = GenericUtils.cast(object);
if (pc.isRoot) {
throw new EngineException("You cannot cut the root page to another application");
}
}
}
}
super.walk(databaseObject);
if (!find) {
throw new EngineException("You cannot cut and paste to a " + databaseObject.getClass().getSimpleName() + " a database object of type " + object.getClass().getSimpleName());
}
} else {
if (object != databaseObject && object.getName().equalsIgnoreCase(databaseObject.getName())) {
throw new ObjectWithSameNameException("Unable to cut the object because an object with the same name already exists in target.");
}
}
}
}.init(parentDatabaseObject);
bContinue = false;
} catch (ObjectWithSameNameException e) {
bIncName = true;
} catch (EngineException e) {
throw e;
} catch (Exception e) {
throw new EngineException("Exception in cutAndPaste", e);
}
}
move(object, parentDatabaseObject);
}
Aggregations