Search in sources :

Example 6 with ValueProperty

use of org.eclipse.sapphire.ValueProperty in project liferay-ide by liferay.

the class ResourceBundleJumpActionHandler method run.

/**
 * (non-Javadoc)
 *
 * @see
 * org.eclipse.sapphire.ui.SapphireActionHandler#run(org.eclipse.sapphire.ui.
 * SapphireRenderingContext)
 */
@Override
protected Object run(Presentation context) {
    Element element = getModelElement();
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    ValueProperty property = (ValueProperty) property().definition();
    IProject project = element.adapt(IProject.class);
    Value<Path> value = element.property(property);
    String text = value.text(false);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot wroot = workspace.getRoot();
    IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
    String ioFileName = PortletUtil.convertJavaToIoFileName(text, RB_FILE_EXTENSION);
    for (IClasspathEntry iClasspathEntry : cpEntries) {
        if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
            IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
            entryPath = entryPath.append(ioFileName);
            IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
            if ((resourceBundleFile != null) && resourceBundleFile.exists()) {
                if (window != null) {
                    IWorkbenchPage page = window.getActivePage();
                    IEditorDescriptor editorDescriptor = null;
                    try {
                        editorDescriptor = IDE.getEditorDescriptor(resourceBundleFile.getName());
                    } catch (PartInitException pie) {
                    // No editor was found for this file type.
                    }
                    if (editorDescriptor != null) {
                        try {
                            IDE.openEditor(page, resourceBundleFile, editorDescriptor.getId(), true);
                        } catch (PartInitException pie) {
                            PortletUIPlugin.logError(pie);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Element(org.eclipse.sapphire.Element) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) ValueProperty(org.eclipse.sapphire.ValueProperty) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Example 7 with ValueProperty

use of org.eclipse.sapphire.ValueProperty in project liferay-ide by liferay.

the class ResourceBundleJumpActionHandler method computeEnablementState.

/**
 * (non-Javadoc)
 *
 * @see org.eclipse.sapphire.ui.SapphirePropertyEditorActionHandler#
 * computeEnablementState()
 */
@Override
protected boolean computeEnablementState() {
    Element element = getModelElement();
    IProject project = element.adapt(IProject.class);
    ValueProperty property = (ValueProperty) property().definition();
    String text = element.property(property).text(true);
    boolean enabled = super.computeEnablementState();
    if (enabled && (text != null)) {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot wroot = workspace.getRoot();
        IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
        String ioFileName = PortletUtil.convertJavaToIoFileName(text, RB_FILE_EXTENSION);
        if (cpEntries != null) {
            for (IClasspathEntry iClasspathEntry : cpEntries) {
                if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
                    IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
                    entryPath = entryPath.append(ioFileName);
                    IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
                    if ((resourceBundleFile != null) && resourceBundleFile.exists()) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Element(org.eclipse.sapphire.Element) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) ValueProperty(org.eclipse.sapphire.ValueProperty)

Example 8 with ValueProperty

use of org.eclipse.sapphire.ValueProperty in project liferay-ide by liferay.

the class ScriptPropertyEditorRenderer method createContents.

@Override
protected void createContents(Composite parent) {
    PropertyEditorPart part = part();
    Element element = part.getLocalModelElement();
    ValueProperty property = part.property().nearest(ValueProperty.class);
    CreateMainCompositeDelegate createMainCompositeDelegate = new CreateMainCompositeDelegate(part) {

        @Override
        public boolean canScaleVertically() {
            return true;
        }
    };
    Composite codeEditorParent = createMainComposite(parent, createMainCompositeDelegate);
    // context.adapt( codeEditorParent );
    int codeEditorParentColumns = 1;
    SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation(getActionPresentationManager());
    boolean actionsToolBarNeeded = toolBarActionsPresentation.hasActions();
    if (actionsToolBarNeeded) {
        codeEditorParentColumns++;
    }
    codeEditorParent.setLayout(glayout(codeEditorParentColumns, 0, 0, 0, 0));
    Composite nestedComposite = new Composite(codeEditorParent, SWT.NONE);
    nestedComposite.setLayoutData(gdfill());
    // nestedComposite.setLayout( glspacing( glayout( 2, 0, 0 ), 2 ) );
    addControl(nestedComposite);
    PropertyEditorAssistDecorator decorator = createDecorator(nestedComposite);
    decorator.control().setLayoutData(gdvalign(gd(), SWT.TOP));
    decorator.addEditorControl(nestedComposite);
    ScriptPropertyEditorInput editorInput = new ScriptPropertyEditorInput(element, property);
    List<Control> relatedControls = new ArrayList<>();
    try {
        IEditorSite editorSite = part().adapt(IEditorSite.class);
        _editorPart = createEditorPart(editorInput, editorSite);
        _editorPart.createPartControl(nestedComposite);
        Control editorControl = _editorPart.getAdapter(Control.class);
        // need to find the first child of nestedComposite to relayout
        // editor control
        Composite editorControlParent = null;
        Control control = editorControl;
        while ((editorControlParent == null) && (control != null) && !nestedComposite.equals(control.getParent())) {
            control = control.getParent();
        }
        nestedComposite.setLayout(glspacing(glayout(2, 0, 0), 2));
        control.setLayoutData(gdfill());
        decorator.addEditorControl(editorControl, true);
        editorControl.setData(RELATED_CONTROLS, relatedControls);
    } catch (Exception e) {
        KaleoUI.logError(e);
    }
    if (actionsToolBarNeeded) {
        ToolBar toolbar = new ToolBar(codeEditorParent, SWT.FLAT | SWT.HORIZONTAL);
        toolbar.setLayoutData(gdvfill());
        toolBarActionsPresentation.setToolBar(toolbar);
        toolBarActionsPresentation.render();
        addControl(toolbar);
        decorator.addEditorControl(toolbar);
        relatedControls.add(toolbar);
    }
    List<Class<?>> listenerClasses = part.getRenderingHint(PropertyEditorDef.HINT_LISTENERS, Collections.<Class<?>>emptyList());
    List<ValuePropertyEditorListener> listeners = new ArrayList<>();
    if (ListUtil.isNotEmpty(listenerClasses)) {
        for (Class<?> cl : listenerClasses) {
            try {
                ValuePropertyEditorListener listener = (ValuePropertyEditorListener) cl.newInstance();
                listener.initialize(this);
                listeners.add(listener);
            } catch (Exception e) {
                KaleoUI.logError(e);
            }
        }
    }
    ITextEditor textEditor = null;
    if (_editorPart instanceof ITextEditor) {
        textEditor = (ITextEditor) _editorPart;
    } else {
        ITextEditor textEdit = _editorPart.getAdapter(ITextEditor.class);
        textEditor = textEdit;
    }
    addControl((Control) textEditor.getAdapter(Control.class));
    IDocumentListener documentListener = new IDocumentListener() {

        public void documentAboutToBeChanged(DocumentEvent event) {
        }

        public void documentChanged(DocumentEvent event) {
            Value<Object> elementProperty = element.property(property);
            elementProperty.write(event.getDocument().get());
            if (ListUtil.isNotEmpty(listeners)) {
                for (ValuePropertyEditorListener listener : listeners) {
                    try {
                        listener.handleValueChanged();
                    } catch (Exception e) {
                        KaleoUI.logError(e);
                    }
                }
            }
        }
    };
    IDocumentProvider documentProvider = textEditor.getDocumentProvider();
    IDocument document = documentProvider.getDocument(_editorPart.getEditorInput());
    document.addDocumentListener(documentListener);
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Element(org.eclipse.sapphire.Element) ArrayList(java.util.ArrayList) ValueProperty(org.eclipse.sapphire.ValueProperty) PropertyEditorAssistDecorator(org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator) ValuePropertyEditorListener(org.eclipse.sapphire.ui.listeners.ValuePropertyEditorListener) Control(org.eclipse.swt.widgets.Control) PropertyEditorPart(org.eclipse.sapphire.ui.forms.PropertyEditorPart) Composite(org.eclipse.swt.widgets.Composite) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent) SapphireToolBarActionPresentation(org.eclipse.sapphire.ui.forms.swt.SapphireToolBarActionPresentation) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) ToolBar(org.eclipse.swt.widgets.ToolBar) IEditorSite(org.eclipse.ui.IEditorSite) IDocument(org.eclipse.jface.text.IDocument)

Example 9 with ValueProperty

use of org.eclipse.sapphire.ValueProperty in project liferay-ide by liferay.

the class UrlPathValidationService method compute.

@Override
public Status compute() {
    ValueProperty valueProperty = context(ValueProperty.class);
    Value<?> value = context(Element.class).property(valueProperty);
    String urlPath = value.text();
    if ((urlPath != null) && !urlPath.startsWith("/")) {
        return Status.createErrorStatus(Resources.bind(Resources.invalidUrlPath, valueProperty.getLabel(false, CapitalizationType.FIRST_WORD_ONLY, false)));
    }
    return Status.createOkStatus();
}
Also used : Element(org.eclipse.sapphire.Element) ValueProperty(org.eclipse.sapphire.ValueProperty)

Example 10 with ValueProperty

use of org.eclipse.sapphire.ValueProperty in project liferay-ide by liferay.

the class CreatePortletAppResourceBundleActionHandler method run.

/**
 * (non-Javadoc)
 *
 * @see
 * org.eclipse.sapphire.ui.SapphireActionHandler#run(org.eclipse.sapphire.ui.
 * SapphireRenderingContext)
 */
@Override
protected Object run(Presentation context) {
    Element element = getModelElement();
    IProject project = element.adapt(IProject.class);
    Property property = property();
    Value<Path> resourceBundle = element.property((ValueProperty) property.definition());
    String resourceBundleText = resourceBundle.text();
    int index = resourceBundleText.lastIndexOf(".");
    if (index == -1) {
        index = resourceBundleText.length();
    }
    String packageName = resourceBundleText.substring(0, index);
    String defaultRBFileName = PortletUtil.convertJavaToIoFileName(resourceBundleText, GenericResourceBundlePathService.RB_FILE_EXTENSION);
    IFolder rbSourecFolder = getResourceBundleFolderLocation(project, defaultRBFileName);
    IPath entryPath = rbSourecFolder.getLocation();
    if (getModelElement() instanceof PortletApp) {
        List<IFile> missingRBFiles = new ArrayList<>();
        StringBuilder rbFileBuffer = new StringBuilder("#Portlet Application Resource Bundle \n");
        IFile rbFile = wroot.getFileForLocation(entryPath.append(defaultRBFileName));
        missingRBFiles.add(rbFile);
        createFiles(context, project, packageName, missingRBFiles, rbFileBuffer);
        setEnabled(false);
        Property modelElement = getModelElement().property(property().definition());
        modelElement.refresh();
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Element(org.eclipse.sapphire.Element) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) PortletApp(com.liferay.ide.portlet.core.model.PortletApp) ValueProperty(org.eclipse.sapphire.ValueProperty) Property(org.eclipse.sapphire.Property) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ValueProperty (org.eclipse.sapphire.ValueProperty)11 Element (org.eclipse.sapphire.Element)7 IFile (org.eclipse.core.resources.IFile)5 IProject (org.eclipse.core.resources.IProject)4 IPath (org.eclipse.core.runtime.IPath)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 Property (org.eclipse.sapphire.Property)3 Path (org.eclipse.sapphire.modeling.Path)3 ArrayList (java.util.ArrayList)2 IWorkspace (org.eclipse.core.resources.IWorkspace)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 PortletApp (com.liferay.ide.portlet.core.model.PortletApp)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 IFolder (org.eclipse.core.resources.IFolder)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IDocument (org.eclipse.jface.text.IDocument)1 IDocumentListener (org.eclipse.jface.text.IDocumentListener)1 DisposeEvent (org.eclipse.sapphire.DisposeEvent)1 Event (org.eclipse.sapphire.Event)1