Search in sources :

Example 1 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class StringPropertyDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite area = (Composite) super.createDialogArea(parent);
    // value
    {
        m_valueText = new Text(area, SWT.BORDER | SWT.MULTI | SWT.WRAP);
        GridDataFactory.create(m_valueText).grab().hintC(80, 8).fill();
        // initial value
        ExecutionUtils.runLog(new RunnableEx() {

            @Override
            public void run() throws Exception {
                Object value = m_property.getValue();
                if (value instanceof String) {
                    m_valueText.setText((String) value);
                }
            }
        });
        // handle Ctrl+Enter as OK
        m_valueText.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.stateMask == SWT.CTRL && e.keyCode == SWT.CR) {
                    okPressed();
                }
            }
        });
    }
    // localization
    if (m_genericProperty != null) {
        Group group = new Group(area, SWT.NONE);
        GridDataFactory.create(group).fill();
        GridLayoutFactory.create(group);
        group.setText(ModelMessages.StringPropertyDialog_localizationGroup);
        // flag of using existing NLS key
        {
            m_nlsButton = new Button(group, SWT.CHECK);
            m_nlsButton.setText(ModelMessages.StringPropertyDialog_localizationUseExisting);
            m_nlsButton.setEnabled(!m_editableSupport.getEditableSources().isEmpty());
            // initial state
            ExecutionUtils.runLog(new RunnableEx() {

                @Override
                public void run() throws Exception {
                    m_nlsButton.setSelection(m_support.isExternalized(m_genericProperty.getExpression()));
                }
            });
            // add selection listener
            m_nlsButton.addListener(SWT.Selection, new Listener() {

                @Override
                public void handleEvent(Event event) {
                    UiUtils.changeControlEnable(m_nlsComposite, m_nlsButton.getSelection());
                    updateSourceKey();
                }
            });
        }
        // NLS container
        {
            m_nlsComposite = new Composite(group, SWT.NONE);
            GridDataFactory.create(m_nlsComposite).grab().fill();
            GridLayoutFactory.create(m_nlsComposite).columns(3).noMargins();
            // source
            {
                new Label(m_nlsComposite, SWT.NONE).setText(ModelMessages.StringPropertyDialog_localizationSourceLabel);
                // 
                m_nlsSourceText = new Text(m_nlsComposite, SWT.BORDER | SWT.READ_ONLY);
                GridDataFactory.create(m_nlsSourceText).grabH().fillH();
            }
            // browse for source/key
            {
                Button browseButton = new Button(m_nlsComposite, SWT.NONE);
                GridDataFactory.create(browseButton).hintHU(50).spanV(2).fill();
                browseButton.setText(ModelMessages.StringPropertyDialog_localizationBrowse);
                // add selection listener
                browseButton.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        StringPropertyKeyDialog keyDialog = new StringPropertyKeyDialog(getShell(), m_editableSupport, m_selectedEditSource, m_selectedKey, m_locale);
                        if (keyDialog.open() == OK) {
                            m_selectedEditSource = keyDialog.getSelectedSource();
                            m_selectedKey = keyDialog.getSelectedKey();
                            updateSourceKey();
                        }
                    }
                });
            }
            // key
            {
                new Label(m_nlsComposite, SWT.NONE).setText(ModelMessages.StringPropertyDialog_localizationKeyLabel);
                // 
                m_nlsKeyText = new Text(m_nlsComposite, SWT.BORDER | SWT.READ_ONLY);
                GridDataFactory.create(m_nlsKeyText).grabH().fillH();
            }
        }
        // update enable state for NLS container
        UiUtils.changeControlEnable(m_nlsComposite, m_nlsButton.getSelection());
    }
    // 
    return area;
}
Also used : Group(org.eclipse.swt.widgets.Group) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) Text(org.eclipse.swt.widgets.Text) KeyEvent(org.eclipse.swt.events.KeyEvent) Button(org.eclipse.swt.widgets.Button) Event(org.eclipse.swt.widgets.Event) KeyEvent(org.eclipse.swt.events.KeyEvent)

Example 2 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class StringPropertyDialog method okPressed.

@Override
protected void okPressed() {
    final String value = m_valueText.getText();
    if (m_component != null) {
        ExecutionUtils.run(m_component, new RunnableEx() {

            @Override
            public void run() throws Exception {
                if (m_genericProperty != null) {
                    // replace with StringLiteral
                    if (!m_nlsButton.getSelection() && m_initialSource != null) {
                        m_initialSource.replace_toStringLiteral(m_genericProperty, value);
                        return;
                    }
                    // use different key in different source
                    if (m_nlsButton.getSelection()) {
                        AbstractSource selectedSource = m_support.getAttachedSource(m_editableSupport, m_selectedEditSource);
                        selectedSource.useKey(m_genericProperty, m_selectedKey);
                        if (isValueDifferentThanInSource()) {
                            m_property.setValue(value);
                        }
                        return;
                    }
                }
                m_property.setValue(value);
            }

            /**
             * @return <code>true</code> if value in NLS source and in editor is not same, so user
             *         changed it and we should update NLS source.
             */
            private boolean isValueDifferentThanInSource() {
                String valueInSource = m_selectedEditSource.getValue(m_locale, m_selectedKey);
                return !value.equals(valueInSource);
            }
        });
    } else {
        ExecutionUtils.runLog(new RunnableEx() {

            @Override
            public void run() throws Exception {
                m_property.setValue(value);
            }
        });
    }
    // close dialog
    super.okPressed();
}
Also used : AbstractSource(org.eclipse.wb.internal.core.nls.model.AbstractSource) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx)

Example 3 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class MethodInvocationArgumentAccessor method setExpression.

@Override
public boolean setExpression(final JavaInfo javaInfo, final String source) throws Exception {
    final List<String> defaultArguments = getMethodDescription(javaInfo).getDefaultArguments();
    // modify expression
    final MethodInvocation invocation = getMethodInvocation(javaInfo);
    if (invocation != null) {
        final AstEditor editor = javaInfo.getEditor();
        final Expression oldArgumentExpression = getArgumentExpression(invocation);
        final String argumentSource = source != null ? source : defaultArguments.get(m_index);
        if (!isSameSource(editor, oldArgumentExpression, argumentSource)) {
            ExecutionUtils.run(javaInfo, new RunnableEx() {

                @Override
                public void run() throws Exception {
                    editor.replaceExpression(oldArgumentExpression, argumentSource);
                    if (isDefaultArguments(javaInfo, invocation)) {
                        editor.removeEnclosingStatement(invocation);
                    }
                }
            });
        }
    } else if (source != null) {
        ExecutionUtils.run(javaInfo, new RunnableEx() {

            @Override
            public void run() throws Exception {
                String argumentsSource = getNewInvocationArguments();
                javaInfo.addMethodInvocation(m_methodSignature, argumentsSource);
            }

            private String getNewInvocationArguments() {
                List<String> arguments = Lists.newArrayList(defaultArguments);
                arguments.set(m_index, source);
                return StringUtils.join(arguments.iterator(), ", ");
            }
        });
    }
    // success
    return true;
}
Also used : AstEditor(org.eclipse.wb.internal.core.utils.ast.AstEditor) CastExpression(org.eclipse.jdt.core.dom.CastExpression) Expression(org.eclipse.jdt.core.dom.Expression) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation)

Example 4 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class StringsAddPropertyEditor method setItems.

/**
 * Sets new items into given {@link Property}.
 */
void setItems(Property _property, final String[] items) throws Exception {
    final JavaInfo javaInfo = ((JavaProperty) _property).getJavaInfo();
    ExecutionUtils.run(javaInfo, new RunnableEx() {

        @Override
        public void run() throws Exception {
            setItems0(items, javaInfo);
        }
    });
}
Also used : JavaProperty(org.eclipse.wb.internal.core.model.property.JavaProperty) JavaInfo(org.eclipse.wb.core.model.JavaInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx)

Example 5 with RunnableEx

use of org.eclipse.wb.internal.core.utils.execution.RunnableEx in project windowbuilder by eclipse.

the class InvocationChildAssociationAccessor method setExpression.

@Override
public boolean setExpression(JavaInfo javaInfo, String source) throws Exception {
    // if given source is "null", use default source (but it also can be "null")
    final String newSource;
    if (source != null) {
        newSource = source;
    } else {
        newSource = m_defaultSource;
    }
    // if we have source to replace current, do this
    if (newSource != null) {
        final AstEditor editor = javaInfo.getEditor();
        final Expression oldExpression = getExpression(javaInfo);
        if (!editor.getSource(oldExpression).equals(source)) {
            ExecutionUtils.run(javaInfo, new RunnableEx() {

                @Override
                public void run() throws Exception {
                    editor.replaceExpression(oldExpression, newSource);
                }
            });
            return true;
        }
    }
    // no changes
    return false;
}
Also used : AstEditor(org.eclipse.wb.internal.core.utils.ast.AstEditor) Expression(org.eclipse.jdt.core.dom.Expression) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx)

Aggregations

RunnableEx (org.eclipse.wb.internal.core.utils.execution.RunnableEx)259 ContainerInfo (org.eclipse.wb.internal.swing.model.component.ContainerInfo)57 ComponentInfo (org.eclipse.wb.internal.swing.model.component.ComponentInfo)55 GridBagLayoutInfo (org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutInfo)42 AbstractGridBagLayoutInfo (org.eclipse.wb.internal.swing.model.layout.gbl.AbstractGridBagLayoutInfo)22 ObjectInfo (org.eclipse.wb.core.model.ObjectInfo)14 List (java.util.List)12 Expression (org.eclipse.jdt.core.dom.Expression)11 IAction (org.eclipse.jface.action.IAction)11 CompositeInfo (org.eclipse.wb.internal.swt.model.widgets.CompositeInfo)11 ControlInfo (org.eclipse.wb.internal.swt.model.widgets.ControlInfo)11 FormLayoutInfo (org.eclipse.wb.internal.swing.FormLayout.model.FormLayoutInfo)10 JavaInfo (org.eclipse.wb.core.model.JavaInfo)9 IMenuItemInfo (org.eclipse.wb.internal.core.model.menu.IMenuItemInfo)9 GridLayoutInfo (org.eclipse.wb.internal.xwt.model.layout.grid.GridLayoutInfo)9 MenuItemInfo (org.eclipse.wb.internal.xwt.model.widgets.menu.MenuItemInfo)9 JavaInfoMemento (org.eclipse.wb.internal.core.model.clipboard.JavaInfoMemento)8 AstEditor (org.eclipse.wb.internal.core.utils.ast.AstEditor)8 ControlInfo (org.eclipse.wb.internal.xwt.model.widgets.ControlInfo)8 JTextField (javax.swing.JTextField)7