Search in sources :

Example 1 with ModelPropertyChangeEvent

use of org.eclipse.sapphire.modeling.ModelPropertyChangeEvent 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)

Aggregations

ScriptLanguageType (com.liferay.ide.kaleo.core.model.ScriptLanguageType)1 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)1 DocumentEvent (org.eclipse.jface.text.DocumentEvent)1 IDocumentListener (org.eclipse.jface.text.IDocumentListener)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 PropertyEditorAssistDecorator (org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator)1 SapphireToolBarActionPresentation (org.eclipse.sapphire.ui.swt.renderer.SapphireToolBarActionPresentation)1 Composite (org.eclipse.swt.widgets.Composite)1 Control (org.eclipse.swt.widgets.Control)1 Label (org.eclipse.swt.widgets.Label)1 ToolBar (org.eclipse.swt.widgets.ToolBar)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IEditorSite (org.eclipse.ui.IEditorSite)1 PartInitException (org.eclipse.ui.PartInitException)1 EditorDescriptor (org.eclipse.ui.internal.registry.EditorDescriptor)1