KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > grapheditor > widget > OperationWidget


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.widget;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.Font JavaDoc;
24 import java.util.EnumSet JavaDoc;
25
26 import org.netbeans.api.visual.action.ActionFactory;
27 import org.netbeans.api.visual.action.InplaceEditorProvider;
28 import org.netbeans.api.visual.action.TextFieldInplaceEditor;
29 import org.netbeans.api.visual.widget.LabelWidget;
30 import org.netbeans.api.visual.widget.Scene;
31 import org.netbeans.api.visual.widget.Widget;
32 import org.netbeans.api.visual.widget.LabelWidget.Alignment;
33 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
34 import org.netbeans.modules.xml.wsdl.model.Operation;
35 import org.netbeans.modules.xml.xam.ui.XAMUtils;
36 import org.openide.nodes.Node;
37 import org.openide.util.Lookup;
38
39 /**
40  * Represents an Operation in the WSDL model. In general this class is
41  * not instantiated directly, but rather its subclasses are created.
42  * In that case, the caller should use the WidgetFactory to create the
43  * appropriate instance for the model component.
44  */

45 public abstract class OperationWidget<T extends Operation>
46         extends AbstractWidget<Operation> {
47     private T mOperationConstruct;
48     private LabelWidget mOperationNameLabelWidget;
49     protected RectangleWidget mOperationRectangleWidget;
50     
51     public OperationWidget(Scene scene, T operation, Lookup lookup) {
52         super(scene, operation, lookup);
53         
54         mOperationConstruct = operation;
55         mOperationNameLabelWidget = new LabelWidget(getScene());
56         mOperationNameLabelWidget.setLabel(mOperationConstruct.getName());
57         mOperationNameLabelWidget.setAlignment(Alignment.CENTER);
58         mOperationNameLabelWidget.setFont(getScene().getDefaultFont().deriveFont(Font.BOLD));
59         mOperationNameLabelWidget.getActions().addAction(ActionFactory.createInplaceEditorAction(new TextFieldInplaceEditor() {
60             
61             public void setText(Widget widget, String JavaDoc text) {
62                 AnalysisUtilities.locallyRenameRefactor(getWSDLComponent(), text);
63             }
64             
65             public boolean isEnabled(Widget widget) {
66                 if (getWSDLComponent() != null) {
67                     return !isImported() && XAMUtils.isWritable(getWSDLComponent().getModel());
68                 }
69                 return false;
70             }
71             
72             public String JavaDoc getText(Widget widget) {
73                 return mOperationConstruct.getName();
74             }
75             
76         },
77                 EnumSet.<InplaceEditorProvider.ExpansionDirection>of(InplaceEditorProvider.ExpansionDirection.LEFT,
78                 InplaceEditorProvider.ExpansionDirection.RIGHT)));
79         mOperationRectangleWidget = new RectangleWidget(getScene(), 10, 67);
80         
81         if (isImported()) mOperationRectangleWidget.setColor(Color.GRAY);
82     }
83     
84     /**
85      * Indicates if this is a right-sided operation.
86      *
87      * @return true if right-sided, false if left-sided.
88      */

89     public boolean isRightSided() {
90         Lookup lookup = getLookup();
91         DirectionCookie dc = (DirectionCookie) lookup.lookup(DirectionCookie.class);
92         return dc == null ? false : dc.isRightSided();
93     }
94     
95     /**
96      * Set the direction of this operation.
97      *
98      * @param rightSided true for right-sided, false for left-sided.
99      */

100     public void setRightSided(boolean rightSided) {
101         Lookup lookup = getLookup();
102         DirectionCookie dc = (DirectionCookie) lookup.lookup(DirectionCookie.class);
103         if (dc == null) {
104             dc = new DirectionCookie(rightSided);
105             getLookupContent().add(dc);
106         } else {
107             dc.setRightSided(rightSided);
108         }
109     }
110     
111     /**
112      * Returns the WSDL operation this widget represents.
113      *
114      * @return the WSDL operation.
115      */

116     public T getOperation() {
117         return mOperationConstruct;
118     }
119     
120     protected LabelWidget getLabel() {
121         return mOperationNameLabelWidget;
122     }
123     
124     @Override JavaDoc
125     public void updateContent() {
126         if (!mOperationNameLabelWidget.getLabel().equals(mOperationConstruct.getName())) {
127             mOperationNameLabelWidget.setLabel(mOperationConstruct.getName());
128         }
129     }
130     
131     protected boolean isImported() {
132         if (getWSDLComponent() != null) {
133             return getModel() != getWSDLComponent().getModel();
134         }
135         return false;
136     }
137     
138     @Override JavaDoc
139     protected Node getNodeFilter(Node original) {
140         if (isImported()) return new ReadOnlyWidgetFilterNode(original);
141             
142         return super.getNodeFilter(original);
143     }
144     
145 }
146
Popular Tags