Search in sources :

Example 16 with ProjectExplorerView

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView in project convertigo by convertigo.

the class DatabaseObjectIncreasePriorityAction 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<TreeParent>();
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            TreeObject[] treeObjects = explorerView.getSelectedTreeObjects();
            String[] selectedPaths = new String[treeObjects.length];
            if (treeObjects != null) {
                // Increase priority
                TreeObject treeObject = null;
                for (int i = 0; i < treeObjects.length; i++) {
                    treeObject = treeObjects[i];
                    selectedPaths[i] = treeObject.getPath();
                    increasePriority(treeObject);
                }
                // Updating the tree and the properties panel
                Enumeration<TreeParent> enumeration = Collections.enumeration(treeNodesToUpdate);
                TreeParent parentTreeObject = null;
                while (enumeration.hasMoreElements()) {
                    parentTreeObject = enumeration.nextElement();
                    explorerView.reloadTreeObject(parentTreeObject);
                }
                // Restore selection
                TreeObjectEvent treeObjectEvent;
                for (int i = 0; i < selectedPaths.length; i++) {
                    String previousPath = selectedPaths[i];
                    treeObject = explorerView.findTreeObjectByPath(parentTreeObject, previousPath);
                    if (treeObject != null) {
                        treeObjects[i] = treeObject;
                        treeObjectEvent = new TreeObjectEvent(treeObject);
                        explorerView.fireTreeObjectPropertyChanged(treeObjectEvent);
                    }
                }
                explorerView.setSelectedTreeObjects(treeObjects);
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to increase priority!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) TreeParent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent) Cursor(org.eclipse.swt.graphics.Cursor) Shell(org.eclipse.swt.widgets.Shell) PropertyTableRowTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableRowTreeObject) PropertyTableColumnTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableColumnTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) PropertyTableTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.PropertyTableTreeObject) FolderTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.FolderTreeObject) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent) Display(org.eclipse.swt.widgets.Display)

Example 17 with ProjectExplorerView

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView in project convertigo by convertigo.

the class CreateNgxApplicationTranslationsFileAction 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();
            List<String> textList = new ArrayList<String>();
            if ((databaseObject != null) && (databaseObject instanceof ApplicationComponent)) {
                ApplicationComponent application = (ApplicationComponent) databaseObject;
                new WalkHelper() {

                    @Override
                    protected void walk(DatabaseObject databaseObject) throws Exception {
                        String text = null;
                        if (databaseObject instanceof PageComponent) {
                            PageComponent page = (PageComponent) databaseObject;
                            text = page.getTitle();
                        } else if (databaseObject instanceof UIUseShared) {
                            UIUseShared uius = (UIUseShared) databaseObject;
                            UISharedComponent uisc = uius.getTargetSharedComponent();
                            if (uisc != null && !uius.isRecursive()) {
                                super.walk(uisc);
                            }
                        } else if (databaseObject instanceof UIText) {
                            UIText uiText = (UIText) databaseObject;
                            MobileSmartSourceType msst = uiText.getTextSmartType();
                            if (Mode.PLAIN.equals(msst.getMode())) {
                                text = msst.getValue();
                            }
                        }
                        if (text != null && !textList.contains(text)) {
                            textList.add(text);
                        }
                        super.walk(databaseObject);
                    }
                }.init(application);
                MobileApplicationTranslationsDialog dlg = new MobileApplicationTranslationsDialog(shell);
                int ret = dlg.open();
                if (ret != Window.OK) {
                    return;
                }
                Locale from = dlg.getLocaleFrom();
                Locale to = dlg.getLocaleTo();
                boolean auto = dlg.isAuto();
                File i18nDir = new File(application.getProject().getDirPath(), "DisplayObjects/mobile/assets/i18n");
                // store source file
                File source = new File(i18nDir, from.getLanguage() + ".json");
                TranslateUtils.storeTranslations(textList, source);
                ConvertigoPlugin.logDebug(source.getName() + " file successfully created or updated.");
                // store target file
                if (!to.equals(from)) {
                    File target = new File(i18nDir, to.getLanguage() + ".json");
                    // translate with google api
                    if (auto) {
                        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
                        dialog.run(true, false, new IRunnableWithProgress() {

                            @Override
                            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                                monitor.beginTask("translating", IProgressMonitor.UNKNOWN);
                                Translator translator = TranslateUtils.newTranslator();
                                try {
                                    translator.translate(from, source, to, target);
                                    ConvertigoPlugin.logDebug(target.getName() + " file successfully translated.");
                                } catch (Exception e) {
                                    ConvertigoPlugin.logError(e.getMessage(), false);
                                    try {
                                        TranslateUtils.storeTranslations(textList, target);
                                    } catch (Exception ex) {
                                    }
                                }
                                monitor.done();
                            }
                        });
                    } else // do not translate
                    {
                        TranslateUtils.storeTranslations(textList, target);
                    }
                    ConvertigoPlugin.logDebug(target.getName() + " file successfully created or updated.");
                }
                // regenerate app templates
                try {
                    application.markApplicationAsDirty();
                    for (PageComponent page : application.getPageComponentList()) {
                        if (page.isEnabled()) {
                            page.markPageAsDirty();
                        }
                    }
                } catch (Throwable t) {
                }
                ConvertigoPlugin.logInfo("Translations file(s) successfully created or updated.", true);
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create the Mobile application translations file(s)!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Locale(java.util.Locale) MobileApplicationTranslationsDialog(com.twinsoft.convertigo.eclipse.dialogs.MobileApplicationTranslationsDialog) MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) ArrayList(java.util.ArrayList) WalkHelper(com.twinsoft.convertigo.engine.helpers.WalkHelper) Cursor(org.eclipse.swt.graphics.Cursor) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) Translator(com.twinsoft.convertigo.engine.mobile.TranslateUtils.Translator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIText(com.twinsoft.convertigo.beans.ngx.components.UIText) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Example 18 with ProjectExplorerView

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView in project convertigo by convertigo.

the class ClipboardCutAction 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) {
            String sXml;
            if (explorerView.isEditing()) {
                sXml = explorerView.getEditingText();
                explorerView.setEditingText("");
            } else {
                // copy to clipboard manager
                sXml = cut(explorerView);
            }
            // copy to system clipboard
            if (sXml != null) {
                Clipboard clipboard = new Clipboard(display);
                TextTransfer textTransfer = TextTransfer.getInstance();
                clipboard.setContents(new String[] { sXml }, new Transfer[] { textTransfer });
                clipboard.dispose();
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to cut!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) Clipboard(org.eclipse.swt.dnd.Clipboard) Cursor(org.eclipse.swt.graphics.Cursor) Display(org.eclipse.swt.widgets.Display) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 19 with ProjectExplorerView

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView in project convertigo by convertigo.

the class ClipboardPasteAction 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();
        TreeObject selectedTreeObject = explorerView.getFirstSelectedTreeObject();
        String source = null;
        if (!clipboardManager.isCut) {
            Clipboard clipboard = new Clipboard(display);
            TextTransfer textTransfer = TextTransfer.getInstance();
            source = (String) clipboard.getContents(textTransfer);
            clipboard.dispose();
        }
        if (explorerView.isEditing()) {
            explorerView.setEditingText(source);
        } else
            paste(source, shell, explorerView, selectedTreeObject);
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to paste!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) Clipboard(org.eclipse.swt.dnd.Clipboard) Cursor(org.eclipse.swt.graphics.Cursor) Display(org.eclipse.swt.widgets.Display) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 20 with ProjectExplorerView

use of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView in project convertigo by convertigo.

the class CouchAddVariables method run.

public void run() {
    Display display = Display.getDefault();
    Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
    Shell shell = getParentShell();
    shell.setCursor(waitCursor);
    try {
        TreeObject parentTreeObject = null;
        AbstractCouchDbTransaction databaseObject = null;
        ProjectExplorerView explorerView = getProjectExplorerView();
        if (explorerView != null) {
            parentTreeObject = explorerView.getFirstSelectedTreeObject();
            if (parentTreeObject.getObject() instanceof AbstractCouchDbTransaction) {
                databaseObject = (AbstractCouchDbTransaction) parentTreeObject.getObject();
                PropertyDescriptor[] props = CachedIntrospector.getBeanInfo(databaseObject).getPropertyDescriptors();
                props = cleanProps(databaseObject, props);
                if (props.length > 0) {
                    CouchVariablesDialog couchVariablesDialog = new CouchVariablesDialog(shell, databaseObject, props);
                    couchVariablesDialog.open();
                    explorerView.reloadTreeObject(parentTreeObject);
                } else {
                    MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.OK);
                    messageBox.setMessage("No parameters are available for this transaction.");
                    messageBox.setText("No availables parameters");
                    messageBox.open();
                }
            }
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to create a new database object '" + databaseObjectClassName + "'!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) PropertyDescriptor(java.beans.PropertyDescriptor) CouchVariablesDialog(com.twinsoft.convertigo.eclipse.dialogs.CouchVariablesDialog) AbstractCouchDbTransaction(com.twinsoft.convertigo.beans.transactions.couchdb.AbstractCouchDbTransaction) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) Cursor(org.eclipse.swt.graphics.Cursor) Display(org.eclipse.swt.widgets.Display) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)175 Cursor (org.eclipse.swt.graphics.Cursor)144 Display (org.eclipse.swt.widgets.Display)144 Shell (org.eclipse.swt.widgets.Shell)144 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)113 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)73 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)49 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)38 Sequence (com.twinsoft.convertigo.beans.core.Sequence)35 EngineException (com.twinsoft.convertigo.engine.EngineException)26 Project (com.twinsoft.convertigo.beans.core.Project)24 Step (com.twinsoft.convertigo.beans.core.Step)22 TreeObjectEvent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)22 ProjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ProjectTreeObject)22 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)21 StepWithExpressions (com.twinsoft.convertigo.beans.core.StepWithExpressions)19 CompositeEvent (com.twinsoft.convertigo.eclipse.editors.CompositeEvent)19 StepEvent (com.twinsoft.convertigo.beans.core.StepEvent)15 Transaction (com.twinsoft.convertigo.beans.core.Transaction)14 File (java.io.File)14