EclipseJDT ASTViewer Source Viewer

Home|eclipse_jdt_astviewer/src/org/eclipse/jdt/astview/views/DynamicBindingProperty.java
1/*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 *     IBM Corporation - initial API and implementation
13 *******************************************************************************/
14
15package org.eclipse.jdt.astview.views;
16
17import org.eclipse.jdt.core.dom.IBinding;
18
19import org.eclipse.swt.graphics.Image;
20
21
22public abstract class DynamicBindingProperty extends ExceptionAttribute {
23
24    protected static final String N_A"N/A"//$NON-NLS-1$
25    private final Binding fParent;
26
27    private Binding fViewerElement;
28    private String fLabel"<unknown>";
29
30    public DynamicBindingProperty(Binding parent) {
31        fParentparent;
32    }
33
34    @Override
35    public Object getParent() {
36        return fParent;
37    }
38
39    @Override
40    public Object[] getChildren() {
41        return EMPTY;
42    }
43
44    public void setViewerElement(Binding viewerElement) {
45        if (fViewerElement == viewerElement)
46            return;
47
48        fViewerElementviewerElement;
49        fExceptionnull;
50        IBinding trayBindingfParent.getBinding();
51        StringBuilder buf= new StringBuilder(getName());
52        if (viewerElement != null) {
53            IBinding viewerBindingviewerElement.getBinding();
54            try {
55                String queryResultexecuteQuery(viewerBindingtrayBinding);
56                buf.append(queryResult);
57            } catch (RuntimeException e) {
58                fExceptione;
59                buf.append(e.getClass().getName());
60                buf.append(" for \""); //$NON-NLS-1$
61                if (viewerBinding == null)
62                    buf.append("null"); //$NON-NLS-1$
63                else
64                    buf.append('"').append(viewerBinding.getKey());
65                buf.append("\" and "); //$NON-NLS-1$
66                buf.append(trayBinding.getKey()).append('"');
67            }
68        } else {
69            buf.append(N_A);
70        }
71        fLabelbuf.toString();
72    }
73
74    /**
75     * Executes this dynamic binding property's query in a protected environment.
76     * A {@link RuntimeException} thrown by this method is made available via
77     * {@link #getException()}.
78     *
79     * @param viewerBinding the binding of the element selected in the AST viewer, or <code>null</code> iff none
80     * @param trayBinding the binding of the element selected in the comparison tray, or <code>null</code> iff none
81     * @return this property's result
82     */
83    protected abstract String executeQuery(IBinding viewerBindingIBinding trayBinding);
84
85    /**
86     * @return a description of the dynamic property
87     */
88    protected abstract String getName();
89
90    @Override
91    public String getLabel() {
92        return fLabel;
93    }
94
95    @Override
96    public Image getImage() {
97        return null;
98    }
99}
100
MembersX
DynamicBindingProperty:getLabel
DynamicBindingProperty:fLabel
DynamicBindingProperty:setViewerElement:Block:trayBinding
DynamicBindingProperty:N_A
DynamicBindingProperty:DynamicBindingProperty
DynamicBindingProperty:executeQuery
DynamicBindingProperty:setViewerElement:Block:Block:viewerBinding
DynamicBindingProperty:setViewerElement:Block:buf
DynamicBindingProperty:getName
DynamicBindingProperty:fViewerElement
DynamicBindingProperty:fParent
DynamicBindingProperty:setViewerElement
DynamicBindingProperty:setViewerElement:Block:Block:Block:queryResult
DynamicBindingProperty:getParent
DynamicBindingProperty:getImage
DynamicBindingProperty:getChildren
Members
X