001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.xslt.tmap.multiview;
020:
021: import java.util.ArrayList;
022: import java.util.List;
023: import java.util.Set;
024:
025: import org.netbeans.core.api.multiview.MultiViewHandler;
026: import org.netbeans.core.api.multiview.MultiViewPerspective;
027: import org.netbeans.core.api.multiview.MultiViews;
028: import org.netbeans.core.spi.multiview.MultiViewDescription;
029: import org.netbeans.core.spi.multiview.MultiViewFactory;
030: import org.netbeans.modules.xslt.tmap.TMapDataEditorSupport;
031: import org.netbeans.modules.xslt.tmap.TMapDataObject;
032: import org.netbeans.modules.xslt.tmap.multiview.designer.DesignerMultiViewElementDesc;
033: import org.netbeans.modules.xslt.tmap.multiview.source.TMapSourceMultiViewElementDesc;
034: import org.netbeans.modules.xslt.tmap.multiview.tree.TreeMultiViewElementDesc;
035: import org.openide.loaders.DataObject;
036: import org.openide.windows.CloneableTopComponent;
037: import org.openide.windows.TopComponent;
038:
039: /**
040: *
041: * @author Vitaly Bychkov
042: * @version 1.0
043: */
044: public class TMapMultiViewSupport {
045: private final static TMapMultiViewSupport INSTANCE = new TMapMultiViewSupport();
046:
047: private TMapMultiViewSupport() {
048: }
049:
050: public static final TMapMultiViewSupport getInstance() {
051: return INSTANCE;
052: }
053:
054: public static CloneableTopComponent createMultiView(
055: final TMapDataObject dataObject) {
056: MultiViewDescription views[] = {
057: new TMapSourceMultiViewElementDesc(dataObject),
058: new TreeMultiViewElementDesc(dataObject)
059: /** TODO a,
060: new DesignerMultiViewElementDesc( dataObject)*/
061: };
062:
063: CloneableTopComponent multiview = MultiViewFactory
064: .createCloneableMultiView(views, views[0],
065: // TODO a views[1],
066: new TMapDataEditorSupport.CloseHandler(
067: dataObject));
068: String name = dataObject.getNodeDelegate().getDisplayName();
069: multiview.setDisplayName(name);
070: multiview.setName(name);
071: return multiview;
072: }
073:
074: public void requestViewOpen(TMapDataEditorSupport support) {
075:
076: List<TopComponent> associatedTCs = new ArrayList<TopComponent>();
077: DataObject targetDO = support.getDataObject();
078: TopComponent activeTC = TopComponent.getRegistry()
079: .getActivated();
080: if (targetDO == (DataObject) activeTC.getLookup().lookup(
081: DataObject.class)) {
082: associatedTCs.add(activeTC);
083: }
084: Set openTCs = TopComponent.getRegistry().getOpened();
085: for (Object tc : openTCs) {
086: TopComponent topComponent = (TopComponent) tc;
087: if (targetDO == (DataObject) topComponent.getLookup()
088: .lookup(DataObject.class)) {
089: associatedTCs.add(topComponent);
090: }
091: }
092:
093: // Use the first TC in the list that has the desired perspective
094: boolean found = false;
095: for (TopComponent targetTC : associatedTCs) {
096: MultiViewHandler handler = MultiViews
097: .findMultiViewHandler(targetTC);
098: if (handler == null) {
099: continue;
100: }
101: MultiViewPerspective[] p = handler.getPerspectives();
102: for (MultiViewPerspective mvp : p) {
103: if (!mvp.preferredID().equals(
104: TMapSourceMultiViewElementDesc.PREFERED_ID)) {
105: handler.requestActive(mvp);
106: found = true;
107: break;
108: }
109: }
110: if (found) {
111: break;
112: }
113: }
114:
115: }
116: }
|