This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 239088
Collapse All | Expand All

(-)core.multiview/apichanges.xml (+13 lines)
Lines 110-115 Link Here
110
    <!-- ACTUAL CHANGES BEGIN HERE: -->
110
    <!-- ACTUAL CHANGES BEGIN HERE: -->
111
111
112
  <changes>
112
  <changes>
113
    <change id="Multiview.AddRemoveTabsAtRuntime">
114
        <api name="multiview_api"/>
115
        <summary>Add/Remove MultiView elements to an existing MultiView TopComponent at runtime.</summary>
116
        <version major="1" minor="38"/>
117
        <date day="5" month="12" year="2013"/>
118
        <author login="saubrecht"/>
119
        <compatibility addition="yes" semantic="compatible"/>
120
        <description>
121
	    It is possible to add/remove multiview elements at runtime.
122
        </description>
123
        <class package="org.netbeans.core.api.multiview" name="MultiViewHandler"/>
124
        <issue number="239088"/>
125
    </change>
113
    <change id="Multiview.Spliting">
126
    <change id="Multiview.Spliting">
114
        <summary>MultiView TopComponent spliting</summary>
127
        <summary>MultiView TopComponent spliting</summary>
115
        <version major="1" minor="35"/>
128
        <version major="1" minor="35"/>
(-)core.multiview/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.core.multiview/1
2
OpenIDE-Module: org.netbeans.core.multiview/1
3
OpenIDE-Module-Specification-Version: 1.37
3
OpenIDE-Module-Specification-Version: 1.38
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/multiview/resources/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/multiview/resources/Bundle.properties
5
OpenIDE-Module-Layer: org/netbeans/core/multiview/resources/mf-layer.xml
5
OpenIDE-Module-Layer: org/netbeans/core/multiview/resources/mf-layer.xml
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
(-)core.multiview/src/org/netbeans/core/api/multiview/MultiViewHandler.java (+23 lines)
Lines 45-50 Link Here
45
package org.netbeans.core.api.multiview;
45
package org.netbeans.core.api.multiview;
46
46
47
import org.netbeans.core.multiview.MultiViewHandlerDelegate;
47
import org.netbeans.core.multiview.MultiViewHandlerDelegate;
48
import org.netbeans.core.spi.multiview.MultiViewDescription;
48
49
49
/**
50
/**
50
 * A handler for the  multiview's {@link org.openide.windows.TopComponent}, obtainable via
51
 * A handler for the  multiview's {@link org.openide.windows.TopComponent}, obtainable via
Lines 108-113 Link Here
108
        del.requestVisible(desc);
109
        del.requestVisible(desc);
109
    }
110
    }
110
    
111
    
112
    /**
113
     * Adds another multiview element to an existing multiview TopComponent. 
114
     * Such elements are not persisted.
115
     * @param descr The description of the element to be added.
116
     * @param position Position of the new element or -1 to append the element to the end.
117
     * @since 1.38
118
     */
119
    public void addMultiViewDescription(MultiViewDescription descr, int position) {
120
        del.addMultiViewDescription( descr, position );
121
    }
111
    
122
    
123
    /**
124
     * Removes multiview element that was added at runtime.
125
     * @param descr The description of the element that was previously passed to 
126
     * addMultiViewDescription method.
127
     * @since 1.38
128
     * @see #addMultiViewDescription(org.netbeans.core.spi.multiview.MultiViewDescription, int) 
129
     */
130
    public void removeMultiViewDescription(MultiViewDescription descr) {
131
        del.removeMultiViewDescription( descr );
132
    }
112
 
133
 
134
    
135
 
113
}
136
}
(-)core.multiview/src/org/netbeans/core/multiview/MultiViewHandlerDelegate.java (+5 lines)
Lines 45-50 Link Here
45
package org.netbeans.core.multiview;
45
package org.netbeans.core.multiview;
46
46
47
import org.netbeans.core.api.multiview.MultiViewPerspective;
47
import org.netbeans.core.api.multiview.MultiViewPerspective;
48
import org.netbeans.core.spi.multiview.MultiViewDescription;
48
49
49
/**
50
/**
50
 * delegate to implement by MultiViewTopComponent
51
 * delegate to implement by MultiViewTopComponent
Lines 64-67 Link Here
64
        void requestActive(MultiViewPerspective desc);
65
        void requestActive(MultiViewPerspective desc);
65
66
66
        void requestVisible(MultiViewPerspective desc);
67
        void requestVisible(MultiViewPerspective desc);
68
69
        void addMultiViewDescription(MultiViewDescription descr, int position);
70
        
71
        void removeMultiViewDescription(MultiViewDescription descr);
67
}
72
}
(-)core.multiview/src/org/netbeans/core/multiview/MultiViewModel.java (+4 lines)
Lines 146-151 Link Here
146
       return col;
146
       return col;
147
    }
147
    }
148
    
148
    
149
    synchronized Map<MultiViewDescription, MultiViewElement> getCreatedElementsMap() {
150
        return new HashMap<MultiViewDescription, MultiViewElement>(nestedElements);
151
    }
152
    
149
    /**
153
    /**
150
     * keeps track of already shown elements, so that componentOpened() is not called multiple Times on a single element.
154
     * keeps track of already shown elements, so that componentOpened() is not called multiple Times on a single element.
151
     *
155
     *
(-)core.multiview/src/org/netbeans/core/multiview/MultiViewPeer.java (-1 / +116 lines)
Lines 58-63 Link Here
58
import java.util.ArrayList;
58
import java.util.ArrayList;
59
import java.util.Arrays;
59
import java.util.Arrays;
60
import java.util.Collection;
60
import java.util.Collection;
61
import java.util.Collections;
61
import java.util.HashMap;
62
import java.util.HashMap;
62
import java.util.Iterator;
63
import java.util.Iterator;
63
import java.util.List;
64
import java.util.List;
Lines 181-190 Link Here
181
    
182
    
182
    public void setMultiViewDescriptions(MultiViewDescription[] descriptions, MultiViewDescription defaultDesc) {
183
    public void setMultiViewDescriptions(MultiViewDescription[] descriptions, MultiViewDescription defaultDesc) {
183
        assert context == null;
184
        assert context == null;
185
        _setMultiViewDescriptions(descriptions, defaultDesc);
186
    }
187
    
188
    private void _setMultiViewDescriptions(MultiViewDescription[] descriptions, MultiViewDescription defaultDesc) {
189
        Map<MultiViewDescription, MultiViewElement> createdElements = Collections.emptyMap();
184
        if (model != null) {
190
        if (model != null) {
185
            model.removeElementSelectionListener(selListener);
191
            model.removeElementSelectionListener(selListener);
192
            createdElements = model.getCreatedElementsMap();
186
        }
193
        }
187
        model = new MultiViewModel(descriptions, defaultDesc, factory);
194
        model = new MultiViewModel(descriptions, defaultDesc, factory, createdElements);
188
        model.addElementSelectionListener(selListener);
195
        model.addElementSelectionListener(selListener);
189
        tabs.setModel(model);
196
        tabs.setModel(model);
190
    }
197
    }
Lines 607-612 Link Here
607
        int currIndexSplit = 0;
614
        int currIndexSplit = 0;
608
615
609
        for (int i = 0; i < descs.length; i++) {
616
        for (int i = 0; i < descs.length; i++) {
617
            if( descs[i] instanceof RuntimeMultiViewDescription ) {
618
                continue; //don't store multiview elements added at runtime
619
            }
610
            if (!fromMime) {
620
            if (!fromMime) {
611
                out.writeObject(descs[i]);
621
                out.writeObject(descs[i]);
612
            } else {
622
            } else {
Lines 933-942 Link Here
933
//            return model.getMVComponentForDescription(desc);
943
//            return model.getMVComponentForDescription(desc);
934
//        }
944
//        }
935
        
945
        
946
        @Override
947
        public void addMultiViewDescription(MultiViewDescription descr, int position) {
948
            if( -1 != splitOrientation )
949
                peerClearSplit(0);
950
            MultiViewDescription[] oldDesc = model.getDescriptions();
951
            if( position < 0 || position >= oldDesc.length/2 )
952
                position = oldDesc.length/2;
953
            RuntimeMultiViewDescription wrapper = new RuntimeMultiViewDescription(descr, false);
954
            RuntimeMultiViewDescription splitWrapper = new RuntimeMultiViewDescription(descr, true);
955
            MultiViewDescription[] newDesc = new MultiViewDescription[oldDesc.length+2];
956
            int index = 0;
957
            for( int i=0; i<newDesc.length/2; i++ ) {
958
                if( i == position ) {
959
                    newDesc[2*i] = wrapper;
960
                    newDesc[2*i+1] = splitWrapper;
961
                } else {
962
                    newDesc[2*i] = oldDesc[index++];
963
                    newDesc[2*i+1] = oldDesc[index++];
964
                }
965
            }
966
            _setMultiViewDescriptions(newDesc, null);
967
            tabs.changeActiveManually(wrapper);
968
        }
936
        
969
        
970
        @Override
971
        public void removeMultiViewDescription(MultiViewDescription descr) {
972
            MultiViewDescription[] oldDesc = model.getDescriptions();
973
            int position = -1;
974
            for( int i=0; i<oldDesc.length/2; i++ ) {
975
                if( oldDesc[2*i] instanceof RuntimeMultiViewDescription ) {
976
                    RuntimeMultiViewDescription runtimeDesc = (RuntimeMultiViewDescription) oldDesc[2*i];
977
                    if( runtimeDesc.delegate.equals(descr) ) {
978
                        position = i;
979
                        break;
937
    }
980
    }
981
                }
982
            }
983
            if( position < 0 )
984
                return; //trying to remove multiview description that isn't in our model
938
    
985
    
986
            if( -1 != splitOrientation )
987
                peerClearSplit(0);
939
988
989
            MultiViewDescription[] newDesc = new MultiViewDescription[oldDesc.length-2];
990
            int index = 0;
991
            for( int i=0; i<oldDesc.length/2; i++ ) {
992
                if( i == position ) {
993
                    continue;
994
                }
995
                newDesc[index++] = oldDesc[2*i];
996
                newDesc[index++] = oldDesc[2*i+1];
997
            }
998
            _setMultiViewDescriptions(newDesc, null);
999
            tabs.changeActiveManually(newDesc[0]);
1000
            model.setActiveDescription(newDesc[0]);
1001
            showCurrentElement();
1002
        }
1003
    }
1004
    
1005
    private static class RuntimeMultiViewDescription implements ContextAwareDescription {
1006
        private final MultiViewDescription delegate;
1007
        private final boolean split;
1008
        
1009
        public RuntimeMultiViewDescription( MultiViewDescription delegate, boolean split ) {
1010
            this.delegate = delegate;
1011
            this.split = split;
1012
        }
1013
1014
        @Override
1015
        public ContextAwareDescription createContextAwareDescription(Lookup context, boolean isSplitDescription) {
1016
            return new RuntimeMultiViewDescription(delegate, isSplitDescription);
1017
        }
1018
1019
        @Override
1020
        public boolean isSplitDescription() {
1021
            return split;
1022
        }
1023
1024
        @Override
1025
        public int getPersistenceType() {
1026
            return delegate.getPersistenceType();
1027
        }
1028
1029
        @Override
1030
        public String getDisplayName() {
1031
            return delegate.getDisplayName();
1032
        }
1033
1034
        @Override
1035
        public Image getIcon() {
1036
            return delegate.getIcon();
1037
        }
1038
1039
        @Override
1040
        public HelpCtx getHelpCtx() {
1041
            return delegate.getHelpCtx();
1042
        }
1043
1044
        @Override
1045
        public String preferredID() {
1046
            return delegate.preferredID();
1047
        }
1048
1049
        @Override
1050
        public MultiViewElement createElement() {
1051
            return delegate.createElement();
1052
        }
1053
    }
1054
940
    private class AccessTogglesAction extends AbstractAction {
1055
    private class AccessTogglesAction extends AbstractAction {
941
        
1056
        
942
        AccessTogglesAction() {
1057
        AccessTogglesAction() {
(-)core.multiview/src/org/netbeans/core/multiview/TabsComponent.java (+2 lines)
Lines 137-142 Link Here
137
        this.model = model;
137
        this.model = model;
138
138
139
        cardLayout = new CardLayout();
139
        cardLayout = new CardLayout();
140
        componentPanel.removeAll();
140
        componentPanel.setLayout(cardLayout);
141
        componentPanel.setLayout(cardLayout);
141
        if( null != layerUI ) {
142
        if( null != layerUI ) {
142
            add(new JLayer( componentPanel, layerUI), BorderLayout.CENTER);
143
            add(new JLayer( componentPanel, layerUI), BorderLayout.CENTER);
Lines 667-672 Link Here
667
            if (innerbar == null) {
668
            if (innerbar == null) {
668
                innerbar = getEmptyInnerToolBar();
669
                innerbar = getEmptyInnerToolBar();
669
            }
670
            }
671
            innerbar.setOpaque(false);
670
            innerbar.putClientProperty(TOOLBAR_MARKER, "X"); //NOI18N
672
            innerbar.putClientProperty(TOOLBAR_MARKER, "X"); //NOI18N
671
            // need to set it to null, because CloneableEditor set's the border for the editor bar part only..
673
            // need to set it to null, because CloneableEditor set's the border for the editor bar part only..
672
            if (!AQUA) {
674
            if (!AQUA) {

Return to bug 239088