Search in sources :

Example 1 with PropertyEditorAssistDecorator

use of org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator in project liferay-ide by liferay.

the class CodePropertyEditorRenderer method createContents.

@Override
protected void createContents(Composite parent) {
    PropertyEditorPart part = getPart();
    Composite scriptEditorParent = createMainComposite(parent, new CreateMainCompositeDelegate(part) {

        @Override
        public boolean canScaleVertically() {
            return true;
        }
    });
    context.adapt(scriptEditorParent);
    int textFieldParentColumns = 1;
    SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation(getActionPresentationManager());
    boolean actionsToolBarNeeded = toolBarActionsPresentation.hasActions();
    if (actionsToolBarNeeded || true)
        textFieldParentColumns++;
    scriptEditorParent.setLayout(glayout(textFieldParentColumns, 0, 0, 0, 0));
    Composite nestedComposite = new Composite(scriptEditorParent, SWT.NONE);
    nestedComposite.setLayoutData(gdfill());
    nestedComposite.setLayout(glspacing(glayout(2, 0, 0), 2));
    this.context.adapt(nestedComposite);
    PropertyEditorAssistDecorator decorator = createDecorator(nestedComposite);
    decorator.control().setLayoutData(gdvalign(gd(), SWT.TOP));
    decorator.addEditorControl(nestedComposite);
    /*
		 * scriptEditorParent.setLayout( new FillLayout( SWT.HORIZONTAL ) );
		 * scriptEditorParent.setLayoutData( gdhhint( gdfill(), 300 ) );
		 */
    PropertyEditorInput editorInput = new PropertyEditorInput(part.getLocalModelElement(), (ValueProperty) part.getProperty());
    try {
        ScriptLanguageType scriptLang = context.getPart().getLocalModelElement().nearest(IScriptable.class).getScriptLanguage().getContent(false);
        String fileName = scriptLang.getClass().getField(scriptLang.toString()).getAnnotation(DefaultValue.class).text();
        IContentDescription contentDescription = ContentTypeManager.getInstance().getDescriptionFor(editorInput.getStorage().getContents(), fileName, IContentDescription.ALL);
        EditorDescriptor defaultEditor = (EditorDescriptor) PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(editorInput.getName(), contentDescription.getContentType());
        _textEditor = (ITextEditor) defaultEditor.createEditor();
    } catch (Exception e1) {
    }
    IEditorReference ref = new ScriptEditorReference(_textEditor, editorInput);
    IEditorSite site = new ScriptEditorSite(ref, _textEditor, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage());
    try {
        _textEditor.init(site, editorInput);
        _textEditor.getDocumentProvider().getDocument(editorInput).addDocumentListener(new IDocumentListener() {

            public void documentAboutToBeChanged(DocumentEvent event) {
            }

            public void documentChanged(DocumentEvent event) {
                String content = event.getDocument().get();
                part.getLocalModelElement().write(((ValueProperty) part.getProperty()), content);
            }
        });
        ModelPropertyListener modelListener = new ModelPropertyListener() {

            @Override
            public void handlePropertyChangedEvent(ModelPropertyChangeEvent event) {
                CodePropertyEditorRenderer.this.textEditor.getDocumentProvider().getDocument(editorInput).set(part.getLocalModelElement().read(getProperty()).getText());
            }
        };
        part.getLocalModelElement().addListener(modelListener, part.getProperty().getName());
    } catch (PartInitException pie) {
        pie.printStackTrace();
    }
    Control[] prevChildren = scriptEditorParent.getChildren();
    // _textEditor.createPartControl( scriptEditorParent );
    new Label(scriptEditorParent, SWT.NONE);
    Control[] newChildren = scriptEditorParent.getChildren();
    decorator.addEditorControl(newChildren[prevChildren.length], true);
    if (actionsToolBarNeeded) {
        ToolBar toolbar = new ToolBar(scriptEditorParent, SWT.FLAT | SWT.HORIZONTAL);
        toolbar.setLayoutData(gdvfill());
        toolBarActionsPresentation.setToolBar(toolbar);
        toolBarActionsPresentation.render();
        context.adapt(toolbar);
        decorator.addEditorControl(toolbar);
    // relatedControls.add( toolbar );
    }
}
Also used : Label(org.eclipse.swt.widgets.Label) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) PropertyEditorAssistDecorator(org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator) DefaultValue(org.eclipse.sapphire.modeling.annotations.DefaultValue) Control(org.eclipse.swt.widgets.Control) IEditorReference(org.eclipse.ui.IEditorReference) PartInitException(org.eclipse.ui.PartInitException) IContentDescription(org.eclipse.core.runtime.content.IContentDescription) PropertyEditorPart(org.eclipse.sapphire.ui.PropertyEditorPart) ModelPropertyChangeEvent(org.eclipse.sapphire.modeling.ModelPropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent) EditorDescriptor(org.eclipse.ui.internal.registry.EditorDescriptor) PartInitException(org.eclipse.ui.PartInitException) SapphireToolBarActionPresentation(org.eclipse.sapphire.ui.swt.renderer.SapphireToolBarActionPresentation) ModelPropertyListener(org.eclipse.sapphire.modeling.ModelPropertyListener) ToolBar(org.eclipse.swt.widgets.ToolBar) IEditorSite(org.eclipse.ui.IEditorSite)

Example 2 with PropertyEditorAssistDecorator

use of org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator 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 3 with PropertyEditorAssistDecorator

use of org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator in project liferay-ide by liferay.

the class PossibleValuesRadioPropertyEditorPresentation method createContents.

@Override
protected void createContents(final Composite parent) {
    final PropertyEditorPart part = part();
    final boolean showLabel = part.label() != null;
    final int leftMargin = part.getMarginLeft();
    PropertyEditorAssistDecorator decorator = null;
    final Composite composite = createMainComposite(parent, new CreateMainCompositeDelegate(part) {

        @Override
        public boolean getShowLabel() {
            return false;
        }

        @Override
        public boolean getSpanBothColumns() {
            return true;
        }
    });
    composite.setLayout(glspacing(glayout(2, 0, 0), 2, 5));
    decorator = createDecorator(composite);
    decorator.addEditorControl(composite);
    if (showLabel) {
        decorator.control().setLayoutData(gdvalign(gd(), SWT.CENTER));
        final Label label = new Label(composite, SWT.WRAP);
        label.setLayoutData(gd());
        final Runnable updateLabelOp = new Runnable() {

            public void run() {
                label.setText(part.label(CapitalizationType.FIRST_WORD_ONLY, true));
            }
        };
        final org.eclipse.sapphire.Listener listener = new org.eclipse.sapphire.Listener() {

            @Override
            public void handle(final org.eclipse.sapphire.Event event) {
                if (event instanceof LabelChangedEvent) {
                    updateLabelOp.run();
                    PossibleValuesRadioPropertyEditorPresentation.this.layout();
                }
            }
        };
        part.attach(listener);
        updateLabelOp.run();
        label.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(final DisposeEvent event) {
                part.detach(listener);
            }
        });
        decorator.addEditorControl(label);
    } else {
        decorator.control().setLayoutData(gdvindent(gdvalign(gd(), SWT.TOP), 4));
    }
    _control = new RadioButtonsGroup(composite, true);
    if (showLabel) {
        _control.setLayoutData(gdhindent(gdhspan(gdhfill(), 2), leftMargin + 20));
    } else {
        _control.setLayoutData(gdhfill());
    }
    binding = new PossibleValuesRadioButtonsGroupBinding<>(this, (RadioButtonsGroup) _control);
    _control.setData(DATA_BINDING, binding);
    decorator.addEditorControl(_control, true);
    addControl(_control);
}
Also used : PropertyEditorPart(org.eclipse.sapphire.ui.forms.PropertyEditorPart) DisposeListener(org.eclipse.swt.events.DisposeListener) DisposeListener(org.eclipse.swt.events.DisposeListener) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) LabelChangedEvent(org.eclipse.sapphire.ui.SapphirePart.LabelChangedEvent) RadioButtonsGroup(org.eclipse.sapphire.ui.forms.swt.RadioButtonsGroup) DisposeEvent(org.eclipse.swt.events.DisposeEvent) PropertyEditorAssistDecorator(org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator) DisposeEvent(org.eclipse.swt.events.DisposeEvent) LabelChangedEvent(org.eclipse.sapphire.ui.SapphirePart.LabelChangedEvent)

Aggregations

PropertyEditorAssistDecorator (org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator)3 Composite (org.eclipse.swt.widgets.Composite)3 DocumentEvent (org.eclipse.jface.text.DocumentEvent)2 IDocumentListener (org.eclipse.jface.text.IDocumentListener)2 PropertyEditorPart (org.eclipse.sapphire.ui.forms.PropertyEditorPart)2 Control (org.eclipse.swt.widgets.Control)2 Label (org.eclipse.swt.widgets.Label)2 ToolBar (org.eclipse.swt.widgets.ToolBar)2 IEditorSite (org.eclipse.ui.IEditorSite)2 ScriptLanguageType (com.liferay.ide.kaleo.core.model.ScriptLanguageType)1 ArrayList (java.util.ArrayList)1 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)1 IDocument (org.eclipse.jface.text.IDocument)1 Element (org.eclipse.sapphire.Element)1 ValueProperty (org.eclipse.sapphire.ValueProperty)1 ModelPropertyChangeEvent (org.eclipse.sapphire.modeling.ModelPropertyChangeEvent)1 ModelPropertyListener (org.eclipse.sapphire.modeling.ModelPropertyListener)1 DefaultValue (org.eclipse.sapphire.modeling.annotations.DefaultValue)1 PropertyEditorPart (org.eclipse.sapphire.ui.PropertyEditorPart)1 LabelChangedEvent (org.eclipse.sapphire.ui.SapphirePart.LabelChangedEvent)1