use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.
the class TreeDropAdapter method performDrop.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
*/
@Override
public boolean performDrop(Object data) {
MobileBuilder mb = null;
Engine.logStudio.info("---------------------- Drop started ----------------------");
try {
Object targetObject = getCurrentTarget();
IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
if (editorPart != null) {
IEditorInput input = editorPart.getEditorInput();
if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
}
// Handle tree objects reordering with Drag and Drop
if (data instanceof String) {
boolean insertBefore = (feedback & DND.FEEDBACK_INSERT_BEFORE) != 0;
boolean insertAfter = (feedback & DND.FEEDBACK_INSERT_AFTER) != 0;
if (insertBefore || insertAfter) {
Object sourceObject = getSelectedObject();
TreeParent targetTreeParent = ((TreeObject) targetObject).getParent();
List<? extends TreeObject> children = targetTreeParent.getChildren();
int destPosition = children.indexOf(targetObject);
int srcPosition = children.indexOf(sourceObject);
int delta = destPosition - srcPosition;
int count = (delta < 0) ? (insertBefore ? delta : delta + 1) : (insertBefore ? delta - 1 : delta);
if (count != 0) {
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
if (count < 0) {
new DatabaseObjectIncreasePriorityAction(Math.abs(count)).run();
} else {
new DatabaseObjectDecreasePriorityAction(Math.abs(count)).run();
}
BatchOperationHelper.stop();
}
return true;
}
}
// Handle objects copy or move with Drag and drop
if (targetObject instanceof TreeObject) {
TreeObject targetTreeObject = (TreeObject) targetObject;
if (targetTreeObject != null) {
ProjectExplorerView explorerView = ConvertigoPlugin.getDefault().getProjectExplorerView();
Document document = null;
try {
Shell shell = Display.getDefault().getActiveShell();
try {
// Try to parse text data into an XML document
String source = data.toString();
document = XMLUtils.getDefaultDocumentBuilder().parse(new InputSource(new StringReader(source)));
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
ClipboardAction.dnd.paste(source, shell, explorerView, targetTreeObject, true);
BatchOperationHelper.stop();
return true;
} catch (SAXException sax) {
BatchOperationHelper.cancel();
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
// Parse failed probably because data was not XML but an XPATH String
// in this case, create DatabaseObjects of the correct Type according to the folder where the XPATH is dropped on
performDrop(data, explorerView, targetTreeObject);
BatchOperationHelper.stop();
return true;
}
} catch (Exception e) {
BatchOperationHelper.cancel();
if (e instanceof ObjectWithSameNameException) {
document = null;
}
if (e instanceof InvalidOperationException) {
document = null;
}
// Case of unauthorized databaseObject paste
if (document != null) {
try {
if (!(targetTreeObject instanceof IPropertyTreeObject)) {
Element rootElement = document.getDocumentElement();
NodeList nodeList = rootElement.getChildNodes();
boolean unauthorized = false;
int len = nodeList.getLength();
Node node;
// case of folder, retrieve owner object
targetTreeObject = explorerView.getFirstSelectedDatabaseObjectTreeObject(targetTreeObject);
if (detail == DND.DROP_COPY) {
for (int i = 0; i < len; i++) {
node = (Node) nodeList.item(i);
if (node.getNodeType() != Node.TEXT_NODE) {
// Special objects paste
if (!paste(node, targetTreeObject)) {
// Real unauthorized databaseObject paste
unauthorized = true;
}
}
}
reloadTreeObject(explorerView, targetTreeObject);
} else if (detail == DND.DROP_MOVE) {
for (int i = 0; i < len; i++) {
node = (Node) nodeList.item(i);
if (node.getNodeType() != Node.TEXT_NODE) {
// Special objects move
if (!move(node, targetTreeObject)) {
// Real unauthorized databaseObject move
unauthorized = true;
}
}
}
reloadTreeObject(explorerView, targetTreeObject);
} else {
// Real unauthorized databaseObject
unauthorized = true;
}
if (unauthorized) {
throw e;
}
return true;
}
} catch (Exception ex) {
ConvertigoPlugin.errorMessageBox(ex.getMessage());
return false;
}
} else {
ConvertigoPlugin.errorMessageBox(e.getMessage());
return false;
}
}
}
}
return false;
} finally {
Engine.logStudio.info("---------------------- Drop ended ----------------------");
BatchOperationHelper.cancel();
}
}
use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.
the class ProjectExplorerView method edit.
private void edit(TreeObject treeObject) {
final Tree tree = viewer.getTree();
final TreeEditor editor = new TreeEditor(tree);
final Color black = getSite().getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK);
TreeItem[] items = tree.getSelection();
if (items.length > 0) {
final TreeItem item = items[0];
final TreeObject theTreeObject = treeObject;
if (treeObject instanceof ProjectTreeObject) {
if (((ProjectTreeObject) treeObject).getModified()) {
// Project need to be saved to avoid xsd/wsdl modification errors - Fix ticket #2265
ConvertigoPlugin.warningMessageBox("Please save project before renaming it.");
return;
}
}
if (treeObject.getObject() instanceof HandlerStatement) {
return;
}
if ((item != null) && lastItem.length > 0 && (item == lastItem[0])) {
boolean isCarbon = SWT.getPlatform().equals("carbon");
final Composite composite = new Composite(tree, SWT.NONE);
if (!isCarbon) {
composite.setBackground(black);
}
final Text text = new Text(composite, SWT.NONE);
final int inset = isCarbon ? 0 : 1;
composite.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
Rectangle rect = composite.getClientArea();
text.setBounds(rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height - inset * 2);
}
});
Listener textListener = new Listener() {
public void handleEvent(final Event e) {
MobileBuilder mba = null;
MobileBuilder mbo = null;
IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
if (editorPart != null) {
IEditorInput input = editorPart.getEditorInput();
if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mba = editorInput.getApplication().getProject().getMobileBuilder();
}
if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mba = editorInput.getApplication().getProject().getMobileBuilder();
}
}
if (theTreeObject instanceof DatabaseObjectTreeObject) {
mbo = ((DatabaseObjectTreeObject) theTreeObject).getObject().getProject().getMobileBuilder();
}
String newName = null;
String oldName = null;
boolean needRefresh = false;
boolean needProjectReload = false;
if (theTreeObject instanceof DatabaseObjectTreeObject) {
oldName = ((DatabaseObject) ((DatabaseObjectTreeObject) theTreeObject).getObject()).getName();
} else if (theTreeObject instanceof TraceTreeObject) {
oldName = ((TraceTreeObject) theTreeObject).getName();
} else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
oldName = ((DesignDocumentViewTreeObject) theTreeObject).getName();
} else if (theTreeObject instanceof DesignDocumentFunctionTreeObject) {
oldName = ((DesignDocumentFunctionTreeObject) theTreeObject).getName();
}
switch(e.type) {
case SWT.FocusOut:
editingTextCtrl = null;
composite.dispose();
break;
case SWT.Verify:
String newText = text.getText();
String leftText = newText.substring(0, e.start);
String rightText = newText.substring(e.end, newText.length());
GC gc = new GC(text);
Point size = gc.textExtent(leftText + e.text + rightText);
gc.dispose();
size = text.computeSize(size.x, SWT.DEFAULT);
editor.horizontalAlignment = SWT.LEFT;
Rectangle itemRect = item.getBounds(), rect = tree.getClientArea();
editor.minimumWidth = Math.max(size.x, itemRect.width) + inset * 2;
int left = itemRect.x, right = rect.x + rect.width;
editor.minimumWidth = Math.min(editor.minimumWidth, right - left);
editor.minimumHeight = size.y + inset * 2;
editor.layout();
break;
case SWT.Traverse:
switch(e.detail) {
case SWT.TRAVERSE_RETURN:
Engine.logStudio.info("---------------------- Rename started ----------------------");
if (mba != null) {
mba.prepareBatchBuild();
}
newName = text.getText();
// Save and close editors
if (theTreeObject instanceof IClosableTreeObject) {
((IClosableTreeObject) theTreeObject).closeAllEditors(true);
}
if (theTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject dbObjectTreeObject = (DatabaseObjectTreeObject) theTreeObject;
if (dbObjectTreeObject.rename(newName, Boolean.TRUE)) {
item.setText(newName);
needRefresh = true;
if (theTreeObject instanceof ProjectTreeObject) {
needProjectReload = true;
}
}
} else if (theTreeObject instanceof TraceTreeObject) {
TraceTreeObject traceTreeObject = (TraceTreeObject) theTreeObject;
traceTreeObject.rename(newName);
if (traceTreeObject.hasChanged) {
item.setText(newName);
traceTreeObject.hasChanged = false;
needRefresh = true;
}
} else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
DesignDocumentViewTreeObject ddvto = (DesignDocumentViewTreeObject) theTreeObject;
if (ddvto.rename(newName, Boolean.TRUE)) {
item.setText(newName);
needRefresh = true;
}
} else if (theTreeObject instanceof DesignDocumentFunctionTreeObject) {
DesignDocumentFunctionTreeObject ddfto = (DesignDocumentFunctionTreeObject) theTreeObject;
if (ddfto.rename(newName, Boolean.TRUE)) {
item.setText(newName);
needRefresh = true;
}
}
// FALL THROUGH
case SWT.TRAVERSE_ESCAPE:
editingTextCtrl = null;
composite.dispose();
e.doit = false;
}
break;
}
if (needRefresh) {
boolean updateDlg = false;
boolean updateReferences = false;
int update = 0;
// Updates references to object if needed
if ((theTreeObject instanceof ProjectTreeObject) || (theTreeObject instanceof SequenceTreeObject) || (theTreeObject instanceof ConnectorTreeObject) || (theTreeObject instanceof TransactionTreeObject) || (theTreeObject instanceof VariableTreeObject2) || (theTreeObject instanceof IDesignTreeObject) || (theTreeObject instanceof MobilePageComponentTreeObject) || (theTreeObject instanceof MobileUIComponentTreeObject) || (theTreeObject instanceof NgxPageComponentTreeObject) || (theTreeObject instanceof NgxUIComponentTreeObject)) {
String objectType = "";
if (theTreeObject instanceof ProjectTreeObject) {
objectType = "project";
updateDlg = true;
} else if (theTreeObject instanceof SequenceTreeObject) {
objectType = "sequence";
updateDlg = true;
} else if (theTreeObject instanceof ConnectorTreeObject) {
objectType = "connector";
updateDlg = true;
} else if (theTreeObject instanceof TransactionTreeObject) {
objectType = "transaction";
updateDlg = true;
} else if (theTreeObject instanceof VariableTreeObject2) {
objectType = "variable";
updateDlg = ((DatabaseObject) theTreeObject.getObject()) instanceof RequestableVariable ? true : false;
} else if (theTreeObject instanceof DesignDocumentTreeObject) {
objectType = "document";
updateDlg = true;
} else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
objectType = "view";
updateDlg = true;
} else if (theTreeObject instanceof DesignDocumentFilterTreeObject) {
objectType = "filter";
updateDlg = true;
} else if (theTreeObject instanceof DesignDocumentUpdateTreeObject) {
objectType = "update";
updateDlg = true;
} else if (theTreeObject instanceof DesignDocumentValidateTreeObject) {
objectType = "validate";
updateDlg = true;
} else if (theTreeObject instanceof MobilePageComponentTreeObject) {
objectType = "page";
updateDlg = true;
} else if (theTreeObject instanceof NgxPageComponentTreeObject) {
objectType = "page";
updateDlg = true;
} else if (theTreeObject instanceof MobileUIComponentTreeObject) {
DatabaseObject dbo = (DatabaseObject) theTreeObject.getObject();
if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UIDynamicMenu) {
objectType = "menu";
updateDlg = true;
}
if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UIActionStack) {
objectType = "shared action";
updateDlg = true;
}
if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UISharedComponent) {
objectType = "shared component";
updateDlg = true;
}
if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UIStackVariable) {
objectType = "variable";
updateDlg = true;
}
if (dbo instanceof com.twinsoft.convertigo.beans.mobile.components.UICompVariable) {
objectType = "variable";
updateDlg = true;
}
} else if (theTreeObject instanceof NgxUIComponentTreeObject) {
DatabaseObject dbo = (DatabaseObject) theTreeObject.getObject();
if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenu) {
objectType = "menu";
updateDlg = true;
}
if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UIActionStack) {
objectType = "shared action";
updateDlg = true;
}
if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) {
objectType = "shared component";
updateDlg = true;
}
if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UIStackVariable) {
objectType = "variable";
updateDlg = true;
}
if (dbo instanceof com.twinsoft.convertigo.beans.ngx.components.UICompVariable) {
objectType = "variable";
updateDlg = true;
}
}
if (updateDlg) {
Shell shell = Display.getDefault().getActiveShell();
CustomDialog customDialog = new CustomDialog(shell, "Update object references", "Do you want to update " + objectType + " 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;
}
}
}
TreeObjectEvent treeObjectEvent = null;
if (updateReferences) {
treeObjectEvent = new TreeObjectEvent(theTreeObject, "name", oldName, newName, update);
} else {
treeObjectEvent = new TreeObjectEvent(theTreeObject, "name", oldName, newName);
}
BatchOperationHelper.start();
ProjectExplorerView.this.refreshTree();
ProjectExplorerView.this.setSelectedTreeObject(theTreeObject);
ProjectExplorerView.this.fireTreeObjectPropertyChanged(treeObjectEvent);
if (updateReferences && needProjectReload) {
((ProjectTreeObject) theTreeObject).save(false);
}
if (mbo != null) {
if (theTreeObject instanceof MobilePageComponentTreeObject) {
try {
mbo.pageRenamed((com.twinsoft.convertigo.beans.mobile.components.PageComponent) theTreeObject.getObject(), oldName);
} catch (EngineException e1) {
e1.printStackTrace();
}
}
if (theTreeObject instanceof NgxPageComponentTreeObject) {
try {
mbo.pageRenamed((com.twinsoft.convertigo.beans.ngx.components.PageComponent) theTreeObject.getObject(), oldName);
} catch (EngineException e1) {
e1.printStackTrace();
}
}
}
BatchOperationHelper.stop();
Engine.logStudio.info("---------------------- Rename ended ----------------------");
StructuredSelection structuredSelection = new StructuredSelection(theTreeObject);
ISelectionListener listener = null;
// refresh properties view
listener = ConvertigoPlugin.getDefault().getPropertiesView();
if (listener != null)
listener.selectionChanged((IWorkbenchPart) ProjectExplorerView.this, structuredSelection);
// refresh references view
listener = ConvertigoPlugin.getDefault().getReferencesView();
if (listener != null)
listener.selectionChanged((IWorkbenchPart) ProjectExplorerView.this, structuredSelection);
}
if (needProjectReload) {
Engine.theApp.databaseObjectsManager.clearCache(newName);
reloadProject(theTreeObject);
refreshTree();
}
}
};
text.addListener(SWT.FocusOut, textListener);
text.addListener(SWT.Traverse, textListener);
text.addListener(SWT.Verify, textListener);
editor.setEditor(composite, item);
if (theTreeObject instanceof DatabaseObjectTreeObject) {
text.setText(((DatabaseObjectTreeObject) theTreeObject).getName());
} else if (theTreeObject instanceof TraceTreeObject) {
text.setText(((TraceTreeObject) theTreeObject).getName());
} else if (theTreeObject instanceof DesignDocumentViewTreeObject) {
text.setText(((DesignDocumentViewTreeObject) theTreeObject).getName());
} else if (theTreeObject instanceof DesignDocumentFunctionTreeObject) {
text.setText(((DesignDocumentFunctionTreeObject) theTreeObject).getName());
}
text.selectAll();
text.setFocus();
editingTextCtrl = text;
}
lastItem[0] = item;
}
}
use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.
the class CLI method generateMobileBuilder.
public void generateMobileBuilder(Project project, String mode) throws Exception {
MobileBuilder mb = project.getMobileBuilder();
MobileBuilderBuildMode bm = MobileBuilderBuildMode.production;
try {
bm = MobileBuilderBuildMode.valueOf(mode);
} catch (Exception e) {
}
mb.setAppBuildMode(bm);
List<Project> projects = new ArrayList<>();
projects.add(project);
int i = 0;
do {
for (Reference ref : projects.get(i).getReferenceList()) {
if (ref instanceof ProjectSchemaReference) {
ProjectSchemaReference pref = (ProjectSchemaReference) ref;
Project p = Engine.theApp.referencedProjectManager.importProject(pref.getParser());
if (p == null) {
Engine.logConvertigo.warn("Failed to import project reference: " + pref.getProjectName() + " (ignored)");
} else if (!projects.contains(p)) {
projects.add(p);
}
}
}
} while (++i < projects.size());
Collections.reverse(projects);
for (Project p : projects) {
MobileBuilder.initBuilder(p, true);
}
Collections.reverse(projects);
for (Project p : projects) {
MobileBuilder.releaseBuilder(p, true);
}
}
use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.
the class ApplicationComponentEditor method createToolbar.
private void createToolbar(Composite parent) {
toolbar = new ToolBar(parent, SWT.VERTICAL);
GridData gd = new GridData(GridData.FILL, GridData.FILL, false, true);
gd.verticalSpan = 2;
gd.verticalIndent = 4;
toolbar.setLayoutData(gd);
ToolItem item = new ToolItem(toolbar, SWT.DROP_DOWN);
item.setToolTipText("Select device viewport. Click to toggle the custom device bar.");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/core/images/mobiledevice_color_16x16.png")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.ARROW) {
ToolItem item = (ToolItem) e.widget;
Rectangle rect = item.getBounds();
Point pt = item.getParent().toDisplay(new Point(rect.x + 8, rect.y + 8));
devicesMenu.setLocation(pt);
devicesMenu.setVisible(true);
} else {
setDeviceBarVisible(!deviceBar.getVisible());
}
}
});
new ToolItem(toolbar, SWT.SEPARATOR);
item = new ToolItem(toolbar, SWT.PUSH);
item.setToolTipText("Change orientation");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/connectors/images/fullsyncconnector_color_16x16.png")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String width = deviceWidth.getText();
deviceWidth.setText(deviceHeight.getText());
deviceHeight.setText(width);
updateBrowserSize();
}
});
new ToolItem(toolbar, SWT.SEPARATOR);
item = new ToolItem(toolbar, SWT.PUSH);
item.setToolTipText("Refresh");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/refresh.gif")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doReload();
}
});
item = new ToolItem(toolbar, SWT.PUSH);
item.setToolTipText("Back");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/undo.gif")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
C8oBrowser.run(() -> {
int index = c8oBrowser.getCurrentNavigationEntryIndex();
if (index > 2) {
c8oBrowser.goBack();
}
});
}
});
new ToolItem(toolbar, SWT.SEPARATOR);
item = new ToolItem(toolbar, SWT.PUSH);
item.setToolTipText("Remove highlight");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/write_wait_zone.d.gif")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
exHighlightElement = null;
exHighlightMobileComponent = null;
C8oBrowser.run(() -> c8oBrowser.executeJavaScriptAndReturnValue("_c8o_remove_all_overlay()"));
}
});
new ToolItem(toolbar, SWT.SEPARATOR);
item = new ToolItem(toolbar, SWT.PUSH);
item.setToolTipText("Show debug");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/debug.gif")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MobileDebugView view = ConvertigoPlugin.getDefault().getMobileDebugView(true);
getSite().getPage().activate(view);
view.onActivated(ApplicationComponentEditor.this);
}
});
item = new ToolItem(toolbar, SWT.PUSH);
item.setToolTipText("Open in default browser");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/com/twinsoft/convertigo/beans/statements/images/ContinueWithSiteClipperStatement_color_16x16.png")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
C8oBrowser.run(() -> {
String url = c8oBrowser.getURL();
if (url.startsWith("http")) {
org.eclipse.swt.program.Program.launch(url);
}
});
}
});
new ToolItem(toolbar, SWT.SEPARATOR);
item = new ToolItem(toolbar, SWT.CHECK);
item.setToolTipText("Toggle auto build");
item.setSelection(true);
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/accumulate.gif")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MobileBuilder mb = applicationEditorInput.application.getProject().getMobileBuilder();
mb.setAutoBuild(((ToolItem) e.widget).getSelection());
}
});
item = new ToolItem(toolbar, SWT.PUSH);
item.setToolTipText("Manage modules");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/show_blocks.gif")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MessageDialog dialog = new MessageDialog(null, "Node_module Update / Reinstall", null, "This will update or reinstall all your project's node_module dependencies. Update when you just " + "added a new dependency to your ionicTpl/package.json file, or re-install if you want clean all your node_modules and do a fresh install (takes more time).", MessageDialog.QUESTION, new String[] { "Update", "Re-install", "Cancel" }, 0);
int result = dialog.open();
if (result < 2) {
launchBuilder(true, result == 1);
}
}
});
final ToolItem buildModeItem = item = new ToolItem(toolbar, SWT.DROP_DOWN);
final Menu buildModeMenu = new Menu(parent.getShell());
SelectionListener buildModeListener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
dialogBuild(buildModeItem, (MenuItem) e.widget);
}
};
for (MobileBuilderBuildMode mode : MobileBuilderBuildMode.values()) {
MenuItem menuItem = new MenuItem(buildModeMenu, SWT.NONE);
menuItem.setText(mode.label());
menuItem.setToolTipText(mode.description());
menuItem.setData(mode);
menuItem.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream(mode.icon())));
menuItem.addSelectionListener(buildModeListener);
if (mode.equals(buildMode)) {
item.setImage(menuItem.getImage());
item.setToolTipText(mode.description());
}
}
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.detail == SWT.ARROW) {
ToolItem item = (ToolItem) e.widget;
Rectangle rect = item.getBounds();
Point pt = item.getParent().toDisplay(new Point(rect.x + 8, rect.y + 8));
buildModeMenu.setLocation(pt);
buildModeMenu.setVisible(true);
} else {
dialogBuild(buildMode);
}
}
});
new ToolItem(toolbar, SWT.SEPARATOR);
item = new ToolItem(toolbar, SWT.DROP_DOWN);
item.setToolTipText("Select dataset");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_show_history.gif")));
SelectionListener selectionListener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setDataset(((MenuItem) e.widget).getText());
}
};
Image iDataset = new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_checkin.gif"));
Image iDatasetSelected = new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_checkout.gif"));
final Menu mDataset = new Menu(toolbar);
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (MenuItem item : mDataset.getItems()) {
item.dispose();
}
MenuItem menuItem = new MenuItem(mDataset, SWT.NONE);
menuItem.setText("none");
for (String fDataset : datasetDir.list()) {
Matcher m = pDatasetFile.matcher(fDataset);
if (m.matches()) {
menuItem = new MenuItem(mDataset, SWT.NONE);
menuItem.setText(m.group(1));
}
}
for (MenuItem item : mDataset.getItems()) {
if (item.getText().equals(dataset)) {
item.setImage(iDatasetSelected);
} else {
item.setImage(iDataset);
}
item.addSelectionListener(selectionListener);
}
ToolItem item = (ToolItem) e.widget;
Rectangle rect = item.getBounds();
Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
mDataset.setLocation(pt);
mDataset.setVisible(true);
}
});
item = new ToolItem(toolbar, SWT.PUSH);
item.setToolTipText("Save dataset");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_add.gif")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String[] name = { dataset.equals("none") ? "" : dataset };
String extra = "";
int response;
do {
MessageDialog dialog = new MessageDialog(null, "Dataset name", null, "What is the name of the dataset ?" + extra, MessageDialog.QUESTION, 0, new String[] { "Save", "Cancel" }) {
@Override
protected Control createCustomArea(Composite parent) {
Text t = new Text(parent, SWT.NONE);
t.setLayoutData(new GridData(GridData.FILL_BOTH));
t.setText(name[0]);
t.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
name[0] = t.getText();
}
});
return t;
}
};
response = dialog.open();
extra = "";
if (response == 0) {
if (StringUtils.isBlank(name[0])) {
extra = " (cannot be empty)";
} else if (name[0].equals("none")) {
extra = " (cannot override 'none')";
}
}
} while (!extra.isEmpty());
if (response == 0) {
C8oBrowser.run(() -> {
String value = c8oBrowser.executeJavaScriptAndReturnValue("sessionStorage._c8ocafsession_storage_data");
try {
FileUtils.write(new File(datasetDir, name[0] + ".json"), new JSONArray(value).toString(2), "UTF-8");
toast("Dataset '" + name[0] + "' saved !");
dataset = name[0];
} catch (Exception e1) {
toast("Dataset '" + name[0] + "' NOT saved ! " + e1.getMessage());
}
});
}
}
});
item = new ToolItem(toolbar, SWT.PUSH);
item.setToolTipText("Remove dataset");
item.setImage(new Image(parent.getDisplay(), getClass().getResourceAsStream("/studio/cvs_delete.gif")));
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (!dataset.equals("none")) {
boolean ok = MessageDialog.openQuestion(null, "Delete '" + dataset + "' ?", "You really want delete'" + dataset + "' ?");
if (ok) {
new File(datasetDir, dataset + ".json").delete();
toast("Dataset '" + dataset + "' removed !");
setDataset("none");
}
} else {
toast("No dataset selected !");
}
}
});
}
use of com.twinsoft.convertigo.engine.mobile.MobileBuilder in project convertigo by convertigo.
the class ApplicationComponentEditor method launchBuilder.
public void launchBuilder(boolean forceInstall, boolean forceClean) {
final int buildCount = ++this.buildCount;
final boolean isDark = SwtUtils.isDark();
// Close editors (*.temp.ts) to avoid npm error at build launch
ConvertigoPlugin.getDisplay().syncExec(new Runnable() {
public void run() {
try {
ApplicationComponent app = applicationEditorInput.application;
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (activePage != null) {
IEditorReference[] editorRefs = activePage.getEditorReferences();
for (int i = 0; i < editorRefs.length; i++) {
IEditorReference editorRef = (IEditorReference) editorRefs[i];
try {
IEditorInput editorInput = editorRef.getEditorInput();
if (editorInput != null && editorInput instanceof ComponentFileEditorInput) {
if (((ComponentFileEditorInput) editorInput).is(app) || ((ComponentFileEditorInput) editorInput).isChildOf(app)) {
activePage.closeEditor(editorRef.getEditor(false), false);
}
}
} catch (Exception e) {
}
}
}
} catch (Throwable t) {
}
}
});
// Launch build
Engine.execute(() -> {
try {
String loader = IOUtils.toString(getClass().getResourceAsStream("loader.html"), "UTF-8");
if (isDark) {
loader = loader.replace("lightblue", "rgb(47,47,47); color: white");
}
c8oBrowser.setText(loader);
} catch (Exception e1) {
throw new RuntimeException(e1);
}
project = applicationEditorInput.application.getProject();
ionicDir = new File(project.getDirPath(), "_private/ionic");
nodeModules = new File(ionicDir, "node_modules");
String nodeVersion = ProcessUtils.getNodeVersion(project);
nodeDir = ProcessUtils.getDefaultNodeDir();
try {
nodeDir = ProcessUtils.getNodeDir(nodeVersion, (r, t, x) -> {
appendOutput("Downloading nodejs " + nodeVersion + ": " + Math.round((r * 100f) / t) + "%");
});
} catch (Exception e1) {
}
{
String versions = "Will use nodejs " + ProcessUtils.getNodeVersion(nodeDir) + " and npm " + ProcessUtils.getNpmVersion(nodeDir);
appendOutput(versions);
Engine.logStudio.info(versions);
}
String path = nodeDir.getAbsolutePath();
terminateNode(false);
MobileBuilder mb = project.getMobileBuilder();
if (forceInstall || !nodeModules.exists() || mb.getNeedPkgUpdate()) {
boolean[] running = { true };
try {
new File(ionicDir, "package-lock.json").delete();
new File(ionicDir, "pnpm-lock.yaml").delete();
if (forceClean) {
appendOutput("...", "...", "Removing existing node_modules... This can take several seconds...");
Engine.logStudio.info("Removing existing node_modules... This can take several seconds...");
com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules);
}
appendOutput("Installing node_modules... This can take several minutes depending on your network connection speed...");
Engine.logStudio.info("Installing node_modules... This can take several minutes depending on your network connection speed...");
ProcessBuilder pb;
Process p;
// set to true to enable yarn again.
boolean useYarn = false;
if (useYarn) {
File yarnFile = new File(ionicDir.toString() + "/node_modules/.bin/yarn");
if (!yarnFile.exists()) {
Engine.logStudio.info("Installing Yarn...");
pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "install", "yarn");
pb.redirectErrorStream(true);
pb.directory(ionicDir);
p = pb.start();
p.waitFor();
}
pb = ProcessUtils.getNpmProcessBuilder(path + File.pathSeparator + ionicDir.toString() + "/node_modules/.bin/", "yarn");
pb.redirectErrorStream(true);
pb.directory(ionicDir);
p = pb.start();
} else {
File pnpmFile = new File(ionicDir.toString() + "/node_modules/.bin/pnpm");
if (!pnpmFile.exists()) {
Engine.logStudio.info("Installing Pnpm...");
pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "install", "pnpm");
pb.redirectErrorStream(true);
pb.directory(ionicDir);
p = pb.start();
p.waitFor();
}
pb = ProcessUtils.getNpmProcessBuilder(path + File.pathSeparator + ionicDir.toString() + "/node_modules/.bin/", "pnpm", "install", "--shamefully-hoist");
pb.redirectErrorStream(true);
pb.directory(ionicDir);
p = pb.start();
}
/*
Engine.execute(() -> {
try {
while (running[0]) {
appendOutput("Collecting node_modules: " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)) + " (" + Math.round(System.currentTimeMillis() - start) / 1000 + " sec)");
Engine.logStudio.info("Installing, node_module size is now : " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)));
Thread.sleep(1000);
}
} catch (Exception e) {
appendOutput("Something wrong during the install: " + e);
}
});
*/
processes.add(p);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
line = pRemoveEchap.matcher(line).replaceAll("");
if (StringUtils.isNotBlank(line)) {
Engine.logStudio.info(line);
appendOutput(line);
}
}
Engine.logStudio.info(line);
appendOutput("\\o/");
} catch (Exception e) {
appendOutput(":( " + e);
}
running[0] = false;
}
mb.setNeedPkgUpdate(false);
build(path, buildCount, mb);
});
}
Aggregations