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 196810
Collapse All | Expand All

(-)java.source/nbproject/project.xml (+9 lines)
Lines 85-90 Link Here
85
                    </run-dependency>
85
                    </run-dependency>
86
                </dependency>
86
                </dependency>
87
                <dependency>
87
                <dependency>
88
                    <code-name-base>org.netbeans.core.multiview</code-name-base>
89
                    <build-prerequisite/>
90
                    <compile-dependency/>
91
                    <run-dependency>
92
                        <release-version>1</release-version>
93
                        <specification-version>1.24</specification-version>
94
                    </run-dependency>
95
                </dependency>
96
                <dependency>
88
                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
97
                    <code-name-base>org.netbeans.libs.javacapi</code-name-base>
89
                    <build-prerequisite/>
98
                    <build-prerequisite/>
90
                    <compile-dependency/>
99
                    <compile-dependency/>
(-)java.source/src/org/netbeans/modules/java/Bundle.properties (+2 lines)
Lines 67-69 Link Here
67
TP_NeedsCompileBadge=Needs to be compiled.
67
TP_NeedsCompileBadge=Needs to be compiled.
68
TP_ExecutableBadge=Contains main class.
68
TP_ExecutableBadge=Contains main class.
69
TXT_OpenClassFile= Open Class File
69
TXT_OpenClassFile= Open Class File
70
71
CTL_SourceTabCaption=&Source
(-)java.source/src/org/netbeans/modules/java/JavaDataObject.java (-5 / +31 lines)
Lines 48-58 Link Here
48
import com.sun.source.tree.CompilationUnitTree;
48
import com.sun.source.tree.CompilationUnitTree;
49
import com.sun.source.tree.Tree;
49
import com.sun.source.tree.Tree;
50
import java.io.IOException;
50
import java.io.IOException;
51
import javax.swing.event.DocumentEvent;
52
import javax.swing.event.DocumentListener;
53
import javax.swing.text.Document;
54
import javax.swing.text.EditorKit;
55
import javax.swing.text.StyledDocument;
56
import org.netbeans.api.java.source.Task;
51
import org.netbeans.api.java.source.Task;
57
import org.netbeans.api.java.source.JavaSource;
52
import org.netbeans.api.java.source.JavaSource;
58
import org.netbeans.api.java.source.JavaSource.Phase;
53
import org.netbeans.api.java.source.JavaSource.Phase;
Lines 60-65 Link Here
60
import org.netbeans.api.java.source.TreeUtilities;
55
import org.netbeans.api.java.source.TreeUtilities;
61
import org.netbeans.api.java.source.WorkingCopy;
56
import org.netbeans.api.java.source.WorkingCopy;
62
import org.netbeans.api.java.source.TreeMaker;
57
import org.netbeans.api.java.source.TreeMaker;
58
import org.netbeans.core.api.multiview.MultiViews;
59
import org.netbeans.core.spi.multiview.MultiViewElement;
60
import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
63
import org.openide.cookies.EditCookie;
61
import org.openide.cookies.EditCookie;
64
import org.openide.cookies.EditorCookie;
62
import org.openide.cookies.EditorCookie;
65
import org.openide.cookies.OpenCookie;
63
import org.openide.cookies.OpenCookie;
Lines 81-86 Link Here
81
import org.openide.text.DataEditorSupport;
79
import org.openide.text.DataEditorSupport;
82
import org.openide.util.Lookup;
80
import org.openide.util.Lookup;
83
import org.openide.windows.CloneableOpenSupport;
81
import org.openide.windows.CloneableOpenSupport;
82
import org.openide.windows.CloneableTopComponent;
83
import org.openide.windows.Mode;
84
import org.openide.windows.TopComponent;
85
import org.openide.windows.WindowManager;
84
86
85
public final class JavaDataObject extends MultiDataObject {
87
public final class JavaDataObject extends MultiDataObject {
86
    
88
    
Lines 199-204 Link Here
199
        }
201
        }
200
202
201
        @Override
203
        @Override
204
        protected Pane createPane() {
205
            CloneableTopComponent mvtc = MultiViews.createCloneableMultiView("text/x-java", getDataObject());
206
207
            // dock into editor mode if possible.
208
            Mode editorMode = WindowManager.getDefault().findMode(CloneableEditorSupport.EDITOR_MODE);
209
            if (editorMode != null) {
210
                editorMode.dockInto(mvtc);
211
            }
212
            return (CloneableEditorSupport.Pane)mvtc;
213
        }
214
        
215
        @Override
202
        protected boolean asynchronousOpen() {
216
        protected boolean asynchronousOpen() {
203
            return true;
217
            return true;
204
        }
218
        }
Lines 208-213 Link Here
208
        }
222
        }
209
    }
223
    }
210
    
224
    
225
    @MultiViewElement.Registration(
226
        displayName="#CTL_SourceTabCaption",
227
        iconBase="org/netbeans/modules/java/resources/class.gif",
228
        persistenceType=TopComponent.PERSISTENCE_ONLY_OPENED,
229
        preferredID="java.source",
230
        mimeType="text/x-java",
231
        position=2000
232
    )
233
    public static MultiViewEditorElement createMultiViewEditorElement(Lookup context) {
234
        return new MultiViewEditorElement(context);
235
    }
236
211
    private static final class JavaEditor extends CloneableEditor {
237
    private static final class JavaEditor extends CloneableEditor {
212
        
238
        
213
        private static final long serialVersionUID = -1;        
239
        private static final long serialVersionUID = -1;        
(-)localhistory/nbproject/project.xml (+18 lines)
Lines 15-20 Link Here
15
                    </run-dependency>
15
                    </run-dependency>
16
                </dependency>
16
                </dependency>
17
                <dependency>
17
                <dependency>
18
                    <code-name-base>org.netbeans.core.multiview</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <release-version>1</release-version>
23
                        <specification-version>1.24</specification-version>
24
                    </run-dependency>
25
                </dependency>
26
                <dependency>
18
                    <code-name-base>org.netbeans.modules.diff</code-name-base>
27
                    <code-name-base>org.netbeans.modules.diff</code-name-base>
19
                    <build-prerequisite/>
28
                    <build-prerequisite/>
20
                    <compile-dependency/>
29
                    <compile-dependency/>
Lines 24-29 Link Here
24
                    </run-dependency>
33
                    </run-dependency>
25
                </dependency>
34
                </dependency>
26
                <dependency>
35
                <dependency>
36
                    <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
37
                    <build-prerequisite/>
38
                    <compile-dependency/>
39
                    <run-dependency>
40
                        <release-version>1</release-version>
41
                        <specification-version>1.23</specification-version>
42
                    </run-dependency>
43
                </dependency>
44
                <dependency>
27
                    <code-name-base>org.netbeans.modules.options.api</code-name-base>
45
                    <code-name-base>org.netbeans.modules.options.api</code-name-base>
28
                    <build-prerequisite/>
46
                    <build-prerequisite/>
29
                    <compile-dependency/>
47
                    <compile-dependency/>
(-)localhistory/src/org/netbeans/modules/localhistory/ui/view/Bundle.properties (+2 lines)
Lines 56-58 Link Here
56
LocalHistoryFolderPanel.jLabel1.text=(yyyy-MM-dd HH\:mm)
56
LocalHistoryFolderPanel.jLabel1.text=(yyyy-MM-dd HH\:mm)
57
57
58
LocalHistoryFolderPanel.revertButton.text=Revert
58
LocalHistoryFolderPanel.revertButton.text=Revert
59
60
CTL_SourceTabCaption=&History
(-)localhistory/src/org/netbeans/modules/localhistory/ui/view/LocalHistoryTopComponent.java (-9 / +126 lines)
Lines 43-67 Link Here
43
 */
43
 */
44
package org.netbeans.modules.localhistory.ui.view;
44
package org.netbeans.modules.localhistory.ui.view;
45
45
46
import java.awt.Color;
47
import java.awt.Dimension;
48
import java.beans.PropertyChangeEvent;
49
import java.beans.PropertyChangeListener;
50
import java.io.File;
46
import java.io.Serializable;
51
import java.io.Serializable;
52
import java.util.Collection;
53
import java.util.HashSet;
54
import java.util.LinkedList;
55
import java.util.List;
56
import java.util.Set;
57
import org.netbeans.core.spi.multiview.CloseOperationState;
58
import org.netbeans.core.spi.multiview.MultiViewElementCallback;
59
import org.openide.util.Exceptions;
47
import org.openide.util.NbBundle;
60
import org.openide.util.NbBundle;
48
import org.openide.windows.TopComponent;
61
import org.openide.windows.TopComponent;
49
import org.openide.awt.UndoRedo;
62
import org.openide.awt.UndoRedo;
50
import org.netbeans.modules.versioning.util.DelegatingUndoRedo;
63
import org.netbeans.modules.versioning.util.DelegatingUndoRedo;
51
64
52
import javax.swing.*;
65
import javax.swing.*;
66
import javax.swing.border.Border;
67
import javax.swing.border.LineBorder;
68
import org.netbeans.core.spi.multiview.MultiViewElement;
69
import org.netbeans.modules.localhistory.LocalHistory;
70
import org.openide.explorer.ExplorerManager;
71
import org.openide.filesystems.FileObject;
72
import org.openide.filesystems.FileUtil;
73
import org.openide.loaders.DataObject;
74
import org.openide.loaders.DataShadow;
75
import org.openide.nodes.Node;
76
import org.openide.util.Lookup;
53
77
54
/**
78
/**
55
 * Top component which displays something.
79
 * Top component which displays something.
56
 * 
80
 * 
57
 * @author Tomas Stupka
81
 * @author Tomas Stupka
58
 */
82
 */
59
final public class LocalHistoryTopComponent extends TopComponent {
83
@MultiViewElement.Registration(
84
        displayName="#CTL_SourceTabCaption", // XXX
85
        iconBase="org/netbeans/modules/java/resources/diff-next.png", // XXX
86
        persistenceType=TopComponent.PERSISTENCE_NEVER,
87
        preferredID="text.history", 
88
        mimeType="",
89
        position=2001
90
)
91
final public class LocalHistoryTopComponent extends TopComponent implements MultiViewElement {
60
92
61
    private static LocalHistoryTopComponent instance;
93
    private static LocalHistoryTopComponent instance;
62
    private LocalHistoryFileView masterView;
94
    private LocalHistoryFileView masterView;
63
    private static final String PREFERRED_ID = "LocalHistoryTopComponent";
95
    static final String PREFERRED_ID = "text.history";
64
    private final DelegatingUndoRedo delegatingUndoRedo = new DelegatingUndoRedo(); 
96
    private final DelegatingUndoRedo delegatingUndoRedo = new DelegatingUndoRedo(); 
97
    private JPanel t;
65
98
66
    public LocalHistoryTopComponent() {
99
    public LocalHistoryTopComponent() {
67
        initComponents();
100
        initComponents();
Lines 72-77 Link Here
72
//        setIcon(Utilities.loadImage(ICON_PATH, true));
105
//        setIcon(Utilities.loadImage(ICON_PATH, true));
73
    }
106
    }
74
107
108
    public LocalHistoryTopComponent(Lookup context) {
109
        this();
110
        DataObject dataObject = context.lookup(DataObject.class);
111
112
        List<File> files = new LinkedList<File>();
113
        if (dataObject instanceof DataShadow) {
114
            dataObject = ((DataShadow) dataObject).getOriginal();
115
        }
116
        if (dataObject != null) {
117
            Collection<File> doFiles = toFileCollection(dataObject.files());
118
            files.addAll(doFiles);
119
        }
120
        init(files.toArray(new File[files.size()]));        
121
    }
122
    
123
    private Collection<File> toFileCollection(Collection<? extends FileObject> fileObjects) {
124
        Set<File> files = new HashSet<File>(fileObjects.size()*4/3+1);
125
        for (FileObject fo : fileObjects) {
126
            files.add(FileUtil.toFile(fo));
127
        }
128
        files.remove(null);
129
        return files;
130
    }        
131
132
    public void init(final File... files) {                
133
        final LocalHistoryFileView fileView = new LocalHistoryFileView();                
134
        LocalHistoryDiffView diffView = new LocalHistoryDiffView(this); 
135
        fileView.getExplorerManager().addPropertyChangeListener(diffView); 
136
        fileView.getExplorerManager().addPropertyChangeListener(new PropertyChangeListener() {
137
            public void propertyChange(PropertyChangeEvent evt) {
138
                if(ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {                            
139
                    LocalHistoryTopComponent.this.setActivatedNodes((Node[]) evt.getNewValue());  
140
                }
141
            } 
142
        });
143
        
144
        // XXX should be solved in a more general way - not ony for LocalHistoryFileView 
145
        this.masterView = fileView; 
146
        splitPane.setTopComponent(masterView.getPanel());   
147
        splitPane.setBottomComponent(diffView.getPanel());                   
148
        
149
        LocalHistory.getInstance().getParallelRequestProcessor().post(new Runnable() {
150
            @Override
151
            public void run() {
152
                fileView.refresh(files);
153
            }
154
        });
155
    }
156
    
75
    /** This method is called from within the constructor to
157
    /** This method is called from within the constructor to
76
     * initialize the form.
158
     * initialize the form.
77
     * WARNING: Do NOT modify this code. The content of this method is
159
     * WARNING: Do NOT modify this code. The content of this method is
Lines 95-107 Link Here
95
    private javax.swing.JSplitPane splitPane;
177
    private javax.swing.JSplitPane splitPane;
96
    // End of variables declaration//GEN-END:variables
178
    // End of variables declaration//GEN-END:variables
97
179
98
    public void init(JPanel diffPanel, LocalHistoryFileView masterView) {                
99
        // XXX should be solved in a more genarel way - not ony for LocalHistoryFileView 
100
        this.masterView = masterView; 
101
        splitPane.setTopComponent(masterView.getPanel());   
102
        splitPane.setBottomComponent(diffPanel);                   
103
    }
104
    
105
    public UndoRedo getUndoRedo() {
180
    public UndoRedo getUndoRedo() {
106
        return delegatingUndoRedo;
181
        return delegatingUndoRedo;
107
    }
182
    }
Lines 146-151 Link Here
146
        return PREFERRED_ID;
221
        return PREFERRED_ID;
147
    }
222
    }
148
223
224
    @Override
225
    public JComponent getVisualRepresentation() {
226
        return this;
227
    }
228
229
    @Override
230
    public JComponent getToolbarRepresentation() {
231
        if( t == null ) { 
232
            t = new JPanel();
233
        }
234
        return t;
235
    }
236
237
    @Override
238
    public void setMultiViewCallback(MultiViewElementCallback callback) {
239
240
    }
241
242
    @Override
243
    public CloseOperationState canCloseElement() {
244
        return CloseOperationState.STATE_OK;
245
    }
246
149
    final static class ResolvableHelper implements Serializable {
247
    final static class ResolvableHelper implements Serializable {
150
        private static final long serialVersionUID = 1L;
248
        private static final long serialVersionUID = 1L;
151
        public Object readResolve() {
249
        public Object readResolve() {
Lines 153-156 Link Here
153
        }
251
        }
154
    }
252
    }
155
253
254
    @Override
255
    public void componentDeactivated() {
256
        super.componentDeactivated();
156
}
257
}
258
259
    @Override
260
    public void componentActivated() {
261
        super.componentActivated();
262
    }
263
264
    @Override
265
    public void componentHidden() {
266
        super.componentHidden();
267
    }
268
269
    @Override
270
    public void componentShowing() {
271
        super.componentShowing();
272
    }    
273
}
(-)localhistory/src/org/netbeans/modules/localhistory/ui/view/ShowLocalHistoryAction.java (-17 / +95 lines)
Lines 43-59 Link Here
43
 */
43
 */
44
package org.netbeans.modules.localhistory.ui.view;
44
package org.netbeans.modules.localhistory.ui.view;
45
45
46
import java.beans.PropertyChangeEvent;
47
import java.beans.PropertyChangeListener;
48
import java.io.File;
46
import java.io.File;
47
import java.util.Collection;
48
import java.util.MissingResourceException;
49
import java.util.Set;
49
import java.util.Set;
50
import javax.swing.SwingUtilities;
50
import javax.swing.SwingUtilities;
51
import org.netbeans.api.editor.mimelookup.MimeLookup;
52
import org.netbeans.api.editor.mimelookup.MimePath;
53
import org.netbeans.core.api.multiview.MultiViewHandler;
54
import org.netbeans.core.api.multiview.MultiViewPerspective;
55
import org.netbeans.core.api.multiview.MultiViews;
56
import org.netbeans.core.spi.multiview.MultiViewDescription;
51
import org.netbeans.modules.versioning.spi.VCSContext;
57
import org.netbeans.modules.versioning.spi.VCSContext;
52
import org.openide.explorer.ExplorerManager;
58
import org.openide.cookies.EditCookie;
59
import org.openide.filesystems.FileObject;
60
import org.openide.filesystems.FileUtil;
61
import org.openide.loaders.DataObject;
62
import org.openide.loaders.DataObjectNotFoundException;
53
import org.openide.nodes.Node;
63
import org.openide.nodes.Node;
64
import org.openide.util.Exceptions;
54
import org.openide.util.HelpCtx;
65
import org.openide.util.HelpCtx;
66
import org.openide.util.Lookup;
55
import org.openide.util.NbBundle;
67
import org.openide.util.NbBundle;
56
import org.openide.util.actions.NodeAction;
68
import org.openide.util.actions.NodeAction;
69
import org.openide.windows.TopComponent;
57
70
58
/**
71
/**
59
 *
72
 *
Lines 71-103 Link Here
71
        VCSContext ctx = VCSContext.forNodes(activatedNodes);
84
        VCSContext ctx = VCSContext.forNodes(activatedNodes);
72
        final Set<File> rootSet = ctx.getRootFiles();                    
85
        final Set<File> rootSet = ctx.getRootFiles();                    
73
86
74
        SwingUtilities.invokeLater(new Runnable() {
75
            public void run() {
76
                File[] files = rootSet.toArray(new File[rootSet.size()]);                
87
                File[] files = rootSet.toArray(new File[rootSet.size()]);                
77
88
89
        if(!files[0].isFile()) {
90
            return;
91
        }
92
93
        File file = files[0];
94
        FileObject fo = FileUtil.toFileObject(file);
95
        if(fo != null) {
96
            DataObject dataObject = null;
97
            try {
98
                dataObject = DataObject.find(fo);
99
            } catch (DataObjectNotFoundException ex) {
100
                Exceptions.printStackTrace(ex);
101
            }
102
            if(dataObject != null) {
103
                if(findInOpenTC(dataObject)) {
104
                    return;
105
                }
106
                if(findInMVDescriptions(dataObject)) {
107
                    return;
108
                }
109
            }
110
        }
111
112
        // fallback opening a LHTopComponent
113
        openTC(files);
114
    }
115
    
116
    private void openTC(final File[] files) throws MissingResourceException {
117
        SwingUtilities.invokeLater(new Runnable() {
118
            @Override
119
            public void run() {
78
                final LocalHistoryTopComponent tc = new LocalHistoryTopComponent();
120
                final LocalHistoryTopComponent tc = new LocalHistoryTopComponent();
79
                tc.setName(NbBundle.getMessage(this.getClass(), "CTL_LocalHistoryTopComponent", files[0].getName()));
121
                tc.setName(NbBundle.getMessage(this.getClass(), "CTL_LocalHistoryTopComponent", files[0].getName()));
80
                tc.open();
122
                tc.open();
81
                tc.requestActive();                                
123
                tc.requestActive();                                
124
                tc.init(files);
125
            }
126
        });
127
    }
82
                
128
                
83
                if(files[0].isFile()) {
129
    /**
84
                    LocalHistoryFileView fileView = new LocalHistoryFileView();                
130
     * XXX HACK temporary solution to find out if the given dataobject provides a multiview
85
                    LocalHistoryDiffView diffView = new LocalHistoryDiffView(tc); 
131
     */
86
                    fileView.getExplorerManager().addPropertyChangeListener(diffView); 
132
    private boolean findInMVDescriptions(DataObject dataObject) {
87
                    fileView.getExplorerManager().addPropertyChangeListener(new PropertyChangeListener() {
133
        String mime = dataObject.getPrimaryFile().getMIMEType();
88
                        public void propertyChange(PropertyChangeEvent evt) {
134
        Lookup l = MimeLookup.getLookup(MimePath.get(mime));
89
                            if(ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) {                            
135
        Collection<? extends MultiViewDescription> descs = l.lookupAll(MultiViewDescription.class);
90
                                tc.setActivatedNodes((Node[]) evt.getNewValue());  
136
        if (descs.size() > 1) {
137
            // LH is registred for every mimetype, so we need at least two
138
            for (MultiViewDescription desc : descs) {
139
                if (desc.preferredID().equals(LocalHistoryTopComponent.PREFERRED_ID)) {
140
                    EditCookie cookie = dataObject.getLookup().lookup(EditCookie.class);
141
                    if (cookie != null) {
142
                        cookie.edit();
143
                        findInOpenTC(dataObject);
144
                        return true;
91
                            }
145
                            }
92
                        } 
146
                        } 
93
                    });
94
                    tc.init(diffView.getPanel(), fileView);
95
                    fileView.refresh(files);
96
                } 
147
                } 
97
            }
148
            }
98
        });
149
        return false;
150
    }
99
151
152
    private boolean findInOpenTC(DataObject dataObject) {
153
        Set<TopComponent> tcs = TopComponent.getRegistry().getOpened();
154
        for (final TopComponent tc : tcs) {
155
            Lookup l = tc.getLookup();
156
            DataObject tcDataObject = l.lookup(DataObject.class);
157
            if (tcDataObject != null && dataObject.equals(tcDataObject)) {
158
                final MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
159
                if (handler != null) {
160
                    MultiViewPerspective[] perspectives = handler.getPerspectives();
161
                    for (final MultiViewPerspective p : perspectives) {
162
                        if(p.preferredID().equals(LocalHistoryTopComponent.PREFERRED_ID)) {
163
                            SwingUtilities.invokeLater(new Runnable() {
164
                                @Override
165
                                public void run() {
166
                                    handler.requestActive(p);
167
                                    tc.requestActive();
100
    }
168
    }
169
                            });
170
                            break;
171
                        } 
172
                    }
173
                    return true;
174
                }
175
            }
176
        }
177
        return false;
178
    }
101
    
179
    
102
    protected boolean enable(Node[] activatedNodes) {     
180
    protected boolean enable(Node[] activatedNodes) {     
103
        if(activatedNodes == null || activatedNodes.length != 1) {
181
        if(activatedNodes == null || activatedNodes.length != 1) {

Return to bug 196810