Search in sources :

Example 16 with PageComponent

use of com.twinsoft.convertigo.beans.ngx.components.PageComponent in project convertigo by convertigo.

the class NgxPageComponentTreeObject method editPageTsFile.

public void editPageTsFile() {
    final PageComponent page = (PageComponent) getObject();
    try {
        // Refresh project resource
        String projectName = page.getProject().getName();
        IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
        // Close editor
        String filePath = page.getProject().getMobileBuilder().getTempTsRelativePath(page);
        IFile file = project.getFile(filePath);
        closeComponentFileEditor(file);
        // Write temporary file
        page.getProject().getMobileBuilder().writePageTempTs(page);
        file.refreshLocal(IResource.DEPTH_ZERO, null);
        // Open file in editor
        if (file.exists()) {
            IEditorInput input = new ComponentFileEditorInput(file, page);
            if (input != null) {
                IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
                IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                String editorId = desc.getId();
                IEditorPart editorPart = activePage.openEditor(input, editorId);
                addMarkers(file, editorPart);
                editorPart.addPropertyListener(new IPropertyListener() {

                    boolean isFirstChange = false;

                    @Override
                    public void propertyChanged(Object source, int propId) {
                        if (source instanceof ITextEditor) {
                            if (propId == IEditorPart.PROP_DIRTY) {
                                if (!isFirstChange) {
                                    isFirstChange = true;
                                    return;
                                }
                                isFirstChange = false;
                                ITextEditor editor = (ITextEditor) source;
                                IDocumentProvider dp = editor.getDocumentProvider();
                                IDocument doc = dp.getDocument(editor.getEditorInput());
                                FormatedContent scriptContent = new FormatedContent(MobileBuilder.getMarkers(doc.get()));
                                NgxPageComponentTreeObject.this.setPropertyValue("scriptContent", scriptContent);
                            }
                        }
                    }
                });
            }
        }
    } catch (Exception e) {
        ConvertigoPlugin.logException(e, "Unable to open typescript file for page '" + page.getName() + "'!");
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ComponentFileEditorInput(com.twinsoft.convertigo.eclipse.editors.ngx.ComponentFileEditorInput) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) IProject(org.eclipse.core.resources.IProject) IPropertyListener(org.eclipse.ui.IPropertyListener) EngineException(com.twinsoft.convertigo.engine.EngineException) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) FormatedContent(com.twinsoft.convertigo.beans.common.FormatedContent) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 17 with PageComponent

use of com.twinsoft.convertigo.beans.ngx.components.PageComponent in project convertigo by convertigo.

the class NgxPageComponentTreeObject method rename.

@Override
public boolean rename(String newName, boolean bDialog) {
    PageComponent page = getObject();
    String oldName = page.getName();
    boolean isRenamed = super.rename(newName, bDialog);
    if (isRenamed && !oldName.equals(newName)) {
        String oldSegment = page.getSegment();
        if (oldSegment.equals(PageComponent.SEGMENT_PREFIX + oldName.toLowerCase())) {
            // path-to-<page_name>
            page.setSegment(oldSegment.replace(oldName.toLowerCase(), newName.toLowerCase()));
            Engine.logEngine.debug("For page renamed to \"" + newName + "\", segment has been replaced with \"" + page.getSegment() + "\"");
        }
    }
    return isRenamed;
}
Also used : PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent)

Example 18 with PageComponent

use of com.twinsoft.convertigo.beans.ngx.components.PageComponent in project convertigo by convertigo.

the class ApplicationComponentEditor method highlightComponent.

public void highlightComponent(MobileComponent mobileComponent, boolean selectPage) {
    C8oBrowser.run(() -> {
        if (selectPage && mobileComponent instanceof UIComponent) {
            PageComponent pageComponent = ((UIComponent) mobileComponent).getPage();
            if (pageComponent != null) {
                selectPage(pageComponent.getSegment());
            }
        }
        Document doc = browser.mainFrame().get().document().get();
        MobileComponent mc = mobileComponent;
        if (mc instanceof UIUseShared) {
            UISharedComponent uisc = ((UIUseShared) mc).getTargetSharedComponent();
            if (uisc != null) {
                try {
                    mc = uisc.getUIComponentList().get(0);
                } catch (IndexOutOfBoundsException ioobe) {
                }
            }
        }
        while (doc.findElementsByClassName("class" + mc.priority).isEmpty()) {
            DatabaseObject parent = mc.getParent();
            if (parent instanceof MobileComponent) {
                mc = (MobileComponent) parent;
            } else {
                return;
            }
        }
        c8oBrowser.executeJavaScriptAndReturnValue("_c8o_highlight_class('class" + mc.priority + "');");
    });
}
Also used : UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) Document(com.teamdev.jxbrowser.dom.Document) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) MobileComponent(com.twinsoft.convertigo.beans.ngx.components.MobileComponent)

Example 19 with PageComponent

use of com.twinsoft.convertigo.beans.ngx.components.PageComponent in project convertigo by convertigo.

the class SetNgxRootPageAction 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) {
            NgxPageComponentTreeObject pageTreeObject = (NgxPageComponentTreeObject) explorerView.getFirstSelectedTreeObject();
            PageComponent page = (PageComponent) pageTreeObject.getObject();
            ApplicationComponent application = (ApplicationComponent) page.getParent();
            NgxPageComponentTreeObject rootPageTreeObject = null;
            PageComponent rootPage = application.getRootPage();
            if (rootPage != null) {
                rootPageTreeObject = (NgxPageComponentTreeObject) explorerView.findTreeObjectByUserObject(rootPage);
            }
            application.setRootPage(page);
            application.markRootAsDirty();
            if (rootPageTreeObject != null) {
                rootPageTreeObject.isDefault = false;
                rootPageTreeObject.hasBeenModified(true);
            }
            pageTreeObject.isDefault = true;
            pageTreeObject.hasBeenModified(true);
            // Updating the tree
            explorerView.refreshTreeObject(pageTreeObject.getParentDatabaseObjectTreeObject());
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to set page to root one!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) Cursor(org.eclipse.swt.graphics.Cursor) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) Display(org.eclipse.swt.widgets.Display)

Example 20 with PageComponent

use of com.twinsoft.convertigo.beans.ngx.components.PageComponent in project convertigo by convertigo.

the class DisableNgxPageComponentAction 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) {
            DatabaseObjectTreeObject treeObject = null;
            PageComponent component = null;
            TreeObject[] treeObjects = explorerView.getSelectedTreeObjects();
            for (int i = treeObjects.length - 1; i >= 0; i--) {
                treeObject = (DatabaseObjectTreeObject) treeObjects[i];
                if (treeObject instanceof NgxPageComponentTreeObject) {
                    NgxPageComponentTreeObject componentTreeObject = GenericUtils.cast(treeObject);
                    component = (PageComponent) componentTreeObject.getObject();
                    component.setEnabled(false);
                    componentTreeObject.setEnabled(false);
                    componentTreeObject.hasBeenModified(true);
                    TreeObjectEvent treeObjectEvent = new TreeObjectEvent(componentTreeObject, "isEnabled", true, false);
                    explorerView.fireTreeObjectPropertyChanged(treeObjectEvent);
                }
            }
            explorerView.refreshSelectedTreeObjects();
        }
    } catch (Throwable e) {
        ConvertigoPlugin.logException(e, "Unable to disable page!");
    } finally {
        shell.setCursor(null);
        waitCursor.dispose();
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) NgxPageComponentTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.NgxPageComponentTreeObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent) Cursor(org.eclipse.swt.graphics.Cursor) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) Display(org.eclipse.swt.widgets.Display)

Aggregations

PageComponent (com.twinsoft.convertigo.beans.ngx.components.PageComponent)36 IPageComponent (com.twinsoft.convertigo.beans.core.IPageComponent)21 EngineException (com.twinsoft.convertigo.engine.EngineException)14 File (java.io.File)13 ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)11 IOException (java.io.IOException)10 UIComponent (com.twinsoft.convertigo.beans.ngx.components.UIComponent)7 IApplicationComponent (com.twinsoft.convertigo.beans.core.IApplicationComponent)6 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)5 UIActionStack (com.twinsoft.convertigo.beans.ngx.components.UIActionStack)5 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)5 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)5 ArrayList (java.util.ArrayList)5 Cursor (org.eclipse.swt.graphics.Cursor)5 Display (org.eclipse.swt.widgets.Display)5 Shell (org.eclipse.swt.widgets.Shell)5 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)4 Contributor (com.twinsoft.convertigo.beans.ngx.components.Contributor)4 UIUseShared (com.twinsoft.convertigo.beans.ngx.components.UIUseShared)4 TreeObjectEvent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)4