Search in sources :

Example 1 with JavaProperty

use of org.eclipse.wb.internal.core.model.property.JavaProperty 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 2 with JavaProperty

use of org.eclipse.wb.internal.core.model.property.JavaProperty in project windowbuilder by eclipse.

the class PropertyTest method test_JavaProperty_getTitle.

/**
 * Test for {@link JavaProperty#getTitle()}.
 */
public void test_JavaProperty_getTitle() throws Exception {
    ContainerInfo panel = parseContainer("// filler filler filler", "public class Test extends JPanel {", "  public Test() {", "  }", "}");
    JavaProperty property = (JavaProperty) panel.getPropertyByTitle("enabled");
    // default title
    assertEquals("enabled", property.getTitle());
    // update title
    property.setTitle("newTitle");
    assertEquals("newTitle", property.getTitle());
}
Also used : JavaProperty(org.eclipse.wb.internal.core.model.property.JavaProperty) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo)

Example 3 with JavaProperty

use of org.eclipse.wb.internal.core.model.property.JavaProperty in project windowbuilder by eclipse.

the class PropertyTest method test_JavaProperty_getJavaInfo.

// //////////////////////////////////////////////////////////////////////////
// 
// JavaProperty
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * Test for {@link JavaProperty#getJavaInfo()}.
 */
public void test_JavaProperty_getJavaInfo() throws Exception {
    ContainerInfo panel = parseContainer("// filler filler filler", "public class Test extends JPanel {", "  public Test() {", "  }", "}");
    JavaProperty property = (JavaProperty) panel.getPropertyByTitle("enabled");
    // 
    assertSame(panel, property.getObjectInfo());
    assertSame(panel, property.getJavaInfo());
    assertSame(panel, property.getAdapter(ObjectInfo.class));
}
Also used : JavaProperty(org.eclipse.wb.internal.core.model.property.JavaProperty) ContainerInfo(org.eclipse.wb.internal.swing.model.component.ContainerInfo) ObjectInfo(org.eclipse.wb.core.model.ObjectInfo)

Example 4 with JavaProperty

use of org.eclipse.wb.internal.core.model.property.JavaProperty in project windowbuilder by eclipse.

the class TableViewerColumnSorterPropertyEditor method doubleClick.

// //////////////////////////////////////////////////////////////////////////
// 
// Editing
// 
// //////////////////////////////////////////////////////////////////////////
@Override
public void doubleClick(Property _property, Point location) throws Exception {
    JavaProperty property = (JavaProperty) _property;
    final JavaInfo javaInfo = property.getJavaInfo();
    ASTNode node = (ASTNode) property.getValue();
    // open in source, if exists
    if (node != null) {
        IDesignPageSite site = IDesignPageSite.Helper.getSite(javaInfo);
        if (site != null) {
            site.openSourcePosition(node.getStartPosition());
        }
        return;
    }
    // no sorter, generate
    AstEditor editor = javaInfo.getEditor();
    ProjectUtils.ensureResourceType(editor.getJavaProject(), Activator.getDefault().getBundle(), "org.eclipse.wb.swt.TableViewerColumnSorter");
    ExecutionUtils.run(javaInfo, new RunnableEx() {

        @Override
        public void run() throws Exception {
            String source = CodeUtils.getSource("new org.eclipse.wb.swt.TableViewerColumnSorter(" + TemplateUtils.getExpression(javaInfo) + ") {", "\t@Override", "\tprotected int doCompare(org.eclipse.jface.viewers.Viewer viewer, Object e1, Object e2) {", "\t\t// TODO Remove this method, if your getValue(Object) returns Comparable.", "\t\t// Typical Comparable are String, Integer, Double, etc.", "\t\treturn super.doCompare(viewer, e1, e2);", "\t}", "\t@Override", "\tprotected Object getValue(Object o) {", "\t\t// TODO remove this method, if your EditingSupport returns value", "\t\treturn super.getValue(o);", "\t}", "}");
            javaInfo.addExpressionStatement(source);
        }
    });
    // open in source
    doubleClick(_property, location);
}
Also used : IDesignPageSite(org.eclipse.wb.core.editor.IDesignPageSite) AstEditor(org.eclipse.wb.internal.core.utils.ast.AstEditor) JavaProperty(org.eclipse.wb.internal.core.model.property.JavaProperty) ASTNode(org.eclipse.jdt.core.dom.ASTNode) JavaInfo(org.eclipse.wb.core.model.JavaInfo) RunnableEx(org.eclipse.wb.internal.core.utils.execution.RunnableEx)

Example 5 with JavaProperty

use of org.eclipse.wb.internal.core.model.property.JavaProperty in project windowbuilder by eclipse.

the class StringsAddPropertyEditor method getItems.

// //////////////////////////////////////////////////////////////////////////
// 
// Items
// 
// //////////////////////////////////////////////////////////////////////////
/**
 * @return the items specified in value of given {@link Property}.
 */
String[] getItems(Property _property) throws Exception {
    JavaInfo javaInfo = ((JavaProperty) _property).getJavaInfo();
    // prepare "add" invocations
    List<MethodInvocation> invocations;
    {
        invocations = javaInfo.getMethodInvocations(m_addMethodSignature);
        ExecutionFlowDescription flowDescription = EditorState.get(javaInfo.getEditor()).getFlowDescription();
        JavaInfoUtils.sortNodesByFlow(flowDescription, false, invocations);
    }
    // fill items
    List<String> items = Lists.newArrayList();
    for (MethodInvocation invocation : invocations) {
        Expression itemExpression = DomGenerics.arguments(invocation).get(0);
        String item = (String) JavaInfoEvaluationHelper.getValue(itemExpression);
        items.add(item);
    }
    // return as array
    return items.toArray(new String[items.size()]);
}
Also used : Expression(org.eclipse.jdt.core.dom.Expression) JavaProperty(org.eclipse.wb.internal.core.model.property.JavaProperty) JavaInfo(org.eclipse.wb.core.model.JavaInfo) MethodInvocation(org.eclipse.jdt.core.dom.MethodInvocation) ExecutionFlowDescription(org.eclipse.wb.core.eval.ExecutionFlowDescription)

Aggregations

JavaProperty (org.eclipse.wb.internal.core.model.property.JavaProperty)5 JavaInfo (org.eclipse.wb.core.model.JavaInfo)3 RunnableEx (org.eclipse.wb.internal.core.utils.execution.RunnableEx)2 ContainerInfo (org.eclipse.wb.internal.swing.model.component.ContainerInfo)2 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 Expression (org.eclipse.jdt.core.dom.Expression)1 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)1 IDesignPageSite (org.eclipse.wb.core.editor.IDesignPageSite)1 ExecutionFlowDescription (org.eclipse.wb.core.eval.ExecutionFlowDescription)1 ObjectInfo (org.eclipse.wb.core.model.ObjectInfo)1 AstEditor (org.eclipse.wb.internal.core.utils.ast.AstEditor)1