001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.web.jsf;
043:
044: import java.awt.Image;
045: import java.io.Serializable;
046: import javax.swing.JComponent;
047: import javax.swing.JEditorPane;
048: import javax.swing.JPanel;
049: import javax.swing.text.Document;
050: import org.netbeans.core.spi.multiview.CloseOperationState;
051: import org.netbeans.core.spi.multiview.MultiViewDescription;
052: import org.netbeans.core.spi.multiview.MultiViewElement;
053: import org.netbeans.core.spi.multiview.MultiViewElementCallback;
054: import org.netbeans.core.spi.multiview.MultiViewFactory;
055: import org.netbeans.modules.web.jsf.api.editor.JSFConfigEditorContext;
056: import org.openide.awt.UndoRedo;
057: import org.openide.loaders.DataObject;
058: import org.openide.loaders.DataObjectNotFoundException;
059: import org.openide.text.CloneableEditor;
060: import org.openide.text.NbDocument;
061: import org.openide.util.Exceptions;
062: import org.openide.util.HelpCtx;
063: import org.openide.windows.TopComponent;
064:
065: /*
066: * @author Petr Pisl
067: */
068:
069: public class JSFConfigMultiviewDescriptor implements
070: MultiViewDescription, Serializable {
071: static final long serialVersionUID = -6305897237371751564L;
072: private final static String XML_CONSTANT = "XML"; //NOI18N
073:
074: private JSFConfigEditorContext context;
075:
076: /** Creates a new instance of StrutsConfigMultiviewDescriptor */
077: public JSFConfigMultiviewDescriptor(JSFConfigEditorContext context) {
078: this .context = context;
079: }
080:
081: public int getPersistenceType() {
082: return TopComponent.PERSISTENCE_ONLY_OPENED;
083: }
084:
085: public String getDisplayName() {
086: return XML_CONSTANT;
087: }
088:
089: private static final Image JSFConfigIcon = org.openide.util.Utilities
090: .loadImage("org/netbeans/modules/web/jsf/resources/JSFConfigIcon.png"); // NOI18N
091:
092: public Image getIcon() {
093: return JSFConfigIcon;
094: }
095:
096: public HelpCtx getHelpCtx() {
097: return null;
098: }
099:
100: public String preferredID() {
101: return XML_CONSTANT;
102: }
103:
104: public MultiViewElement createElement() {
105: MultiViewElement element = null;
106: try {
107: DataObject dObject = DataObject.find(context
108: .getFacesConfigFile());
109: JSFConfigDataObject jsfDataObject = (JSFConfigDataObject) dObject;
110: element = new JSFConfigMultiviewElement(context,
111: jsfDataObject.getEditorSupport());
112: } catch (DataObjectNotFoundException ex) {
113: Exceptions.printStackTrace(ex);
114: }
115: return element;
116: }
117:
118: class JSFConfigMultiviewElement extends CloneableEditor implements
119: MultiViewElement, Serializable {
120: static final long serialVersionUID = -6305897237371751564L;
121:
122: private JSFConfigEditorContext context;
123: private transient JComponent toolbar;
124: private transient JSFConfigDataObject jsfDataObject;
125:
126: public JSFConfigMultiviewElement(
127: JSFConfigEditorContext context,
128: JSFConfigEditorSupport support) {
129: super (support);
130: support.initializeCloneableEditor(this );
131: this .context = context;
132: init();
133: }
134:
135: private void init() {
136: try {
137: DataObject dObject = DataObject.find(context
138: .getFacesConfigFile());
139:
140: jsfDataObject = (org.netbeans.modules.web.jsf.JSFConfigDataObject) dObject;
141: } catch (DataObjectNotFoundException ex) {
142: java.util.logging.Logger.getLogger("global").log(
143: java.util.logging.Level.SEVERE,
144: ex.getMessage(), ex);
145: }
146: }
147:
148: public JComponent getVisualRepresentation() {
149: return this ;
150: }
151:
152: public JComponent getToolbarRepresentation() {
153: if (toolbar == null) {
154: JEditorPane editorPane = getEditorPane();
155: if (editorPane != null) {
156: Document doc = editorPane.getDocument();
157: if (doc instanceof NbDocument.CustomToolbar)
158: toolbar = ((NbDocument.CustomToolbar) doc)
159: .createToolbar(editorPane);
160: }
161: if (toolbar == null)
162: toolbar = new JPanel();
163: }
164: return toolbar;
165: }
166:
167: @Override
168: public void componentOpened() {
169: super .componentOpened();
170: }
171:
172: @Override
173: public void componentClosed() {
174: super .componentClosed();
175: }
176:
177: @Override
178: public void componentShowing() {
179: super .componentShowing();
180: }
181:
182: @Override
183: public void componentHidden() {
184: super .componentHidden();
185: }
186:
187: @Override
188: public void componentActivated() {
189: super .componentActivated();
190: }
191:
192: @Override
193: public void componentDeactivated() {
194: super .componentDeactivated();
195: }
196:
197: @Override
198: public UndoRedo getUndoRedo() {
199: return super .getUndoRedo();
200: }
201:
202: public void setMultiViewCallback(
203: MultiViewElementCallback callback) {
204: context
205: .setMultiViewTopComponent(callback
206: .getTopComponent());
207: }
208:
209: public CloseOperationState canCloseElement() {
210: // the savin operation is handled by CloseHander form JSFCOnfigEditorSuport
211: return MultiViewFactory.createUnsafeCloseState(
212: "ID_FACES_CONFIG_CLOSING",
213: MultiViewFactory.NOOP_CLOSE_ACTION,
214: MultiViewFactory.NOOP_CLOSE_ACTION);
215: }
216:
217: @Override
218: public javax.swing.Action[] getActions() {
219: return super.getActions();
220: }
221: }
222: }
|