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-2006 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.core.spi.multiview;
043:
044: import javax.swing.JComponent;
045: import javax.swing.JToolBar;
046: import javax.swing.text.Document;
047: import org.openide.text.CloneableEditor;
048: import org.openide.text.CloneableEditorSupport;
049: import org.openide.text.NbDocument;
050:
051: /**
052: * @author mkleint
053: */
054: abstract class MultiViewCloneableEditor extends CloneableEditor
055: implements MultiViewElement {
056:
057: private static final long serialVersionUID = -3126744316644172415L;
058:
059: private transient MultiViewElementCallback multiViewObserver;
060: private transient JToolBar bar;
061:
062: /** Creates a new instance of MultiViewClonableEditor */
063: public MultiViewCloneableEditor() {
064: this (null);
065: }
066:
067: public MultiViewCloneableEditor(CloneableEditorSupport support) {
068: super (support);
069: }
070:
071: public JComponent getToolbarRepresentation() {
072: Document doc = getEditorPane().getDocument();
073: if (doc instanceof NbDocument.CustomToolbar) {
074: if (bar == null) {
075: bar = ((NbDocument.CustomToolbar) doc)
076: .createToolbar(getEditorPane());
077: }
078: return bar;
079: }
080: return null;
081: }
082:
083: public javax.swing.JComponent getVisualRepresentation() {
084: return this ;
085: }
086:
087: public final void setMultiViewCallback(
088: MultiViewElementCallback callback) {
089: multiViewObserver = callback;
090: }
091:
092: protected final MultiViewElementCallback getElementObserver() {
093: return multiViewObserver;
094: }
095:
096: public void componentActivated() {
097: super .componentActivated();
098: }
099:
100: public void componentClosed() {
101: super .componentClosed();
102: }
103:
104: public void componentDeactivated() {
105: super .componentDeactivated();
106: }
107:
108: public void componentHidden() {
109: super .componentHidden();
110: }
111:
112: public void componentOpened() {
113: super .componentOpened();
114: }
115:
116: public void componentShowing() {
117: if (multiViewObserver != null) {
118: updateName();
119: }
120: super .componentShowing();
121: }
122:
123: public javax.swing.Action[] getActions() {
124: return super .getActions();
125: }
126:
127: public org.openide.util.Lookup getLookup() {
128: return super .getLookup();
129: }
130:
131: public String preferredID() {
132: return super .preferredID();
133: }
134:
135: public void requestVisible() {
136: if (multiViewObserver != null) {
137: multiViewObserver.requestVisible();
138: } else {
139: super .requestVisible();
140: }
141: }
142:
143: public void requestActive() {
144: if (multiViewObserver != null) {
145: multiViewObserver.requestActive();
146: } else {
147: super .requestActive();
148: }
149: }
150:
151: public void updateName() {
152: super .updateName();
153: if (multiViewObserver != null) {
154: multiViewObserver.updateTitle(getDisplayName());
155: }
156: }
157:
158: public void open() {
159: if (multiViewObserver != null) {
160: multiViewObserver.requestVisible();
161: } else {
162: super .open();
163: }
164:
165: }
166:
167: public CloseOperationState canCloseElement() {
168: throw new IllegalStateException("Not implemented yet.");
169: // return CloseOperationState.STATE_OK;
170: }
171:
172: }
|