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

(-)java/src/org/netbeans/modules/java/JavaDataObject.java (-20 / +35 lines)
Lines 44-49 Link Here
44
import org.openide.src.nodes.ElementNodeFactory;
44
import org.openide.src.nodes.ElementNodeFactory;
45
import org.openide.src.nodes.FilterFactory;
45
import org.openide.src.nodes.FilterFactory;
46
import org.openide.text.CloneableEditorSupport;
46
import org.openide.text.CloneableEditorSupport;
47
import org.openide.text.DataEditorSupport;
47
import org.openide.text.EditorSupport;
48
import org.openide.text.EditorSupport;
48
import org.openide.util.*;
49
import org.openide.util.*;
49
50
Lines 139-145 Link Here
139
            ConnectionCookie.class,
140
            ConnectionCookie.class,
140
            JavaParser.class,
141
            JavaParser.class,
141
            SourceCookie.Editor.class,
142
            SourceCookie.Editor.class,
142
            SynchronizeCodeCookie.class,
143
            SynchronizeCodeCookie.class
143
        };
144
        };
144
        cookies.add(cookieClasses, this);
145
        cookies.add(cookieClasses, this);
145
146
Lines 187-193 Link Here
187
188
188
            parserGlue = new JavaParserGlue(getPrimaryEntry());
189
            parserGlue = new JavaParserGlue(getPrimaryEntry());
189
            if (editorSupport != null) {
190
            if (editorSupport != null) {
190
                parserGlue.cloneableSupportCreated(extractCloneableEditor(editorSupport));
191
                parserGlue.cloneableSupportCreated(editorSupport);
191
            }
192
            }
192
193
193
            // initialize connection support -- this can be delayed up to the first commit,
194
            // initialize connection support -- this can be delayed up to the first commit,
Lines 252-274 Link Here
252
     * implementation.
253
     * implementation.
253
     */
254
     */
254
    protected CloneableEditorSupport findCloneableEditorSupport() {
255
    protected CloneableEditorSupport findCloneableEditorSupport() {
255
        EditorSupport supp = (EditorSupport)getCookie(EditorSupport.class);
256
        return (JavaEditor)getCookie(JavaEditor.class);
256
        return extractCloneableEditor(supp);
257
        //return extractCloneableEditor(supp);
257
    }
258
    }
258
259
259
    /**
260
//    /**
260
     * Extract CloneableEditorSupport instance from the given EditorSupport.
261
//     * Extract CloneableEditorSupport instance from the given EditorSupport.
261
     * The implementation is fragile as it uses package-private member and reflection.
262
//     * The implementation is fragile as it uses package-private member and reflection.
262
     */
263
//     */
263
    private CloneableEditorSupport extractCloneableEditor(EditorSupport supp) {
264
//    private CloneableEditorSupport extractCloneableEditor(EditorSupport supp) {
264
        try {
265
//        try {
265
            java.lang.reflect.Field f = EditorSupport.class.getDeclaredField("del"); // NOI18N
266
//            java.lang.reflect.Field f = EditorSupport.class.getDeclaredField("del"); // NOI18N
266
            f.setAccessible(true);
267
//            f.setAccessible(true);
267
            return (CloneableEditorSupport)f.get(supp);
268
//            return (CloneableEditorSupport)f.get(supp);
268
        } catch (Exception x) {
269
//        } catch (Exception x) {
269
        }
270
//        }
270
        return null;
271
//        return null;
271
    }
272
//    }
272
273
273
    /** Attaches a file change listener to the primary (source) file.
274
    /** Attaches a file change listener to the primary (source) file.
274
     * Optionally removes the listener from previously used file object.
275
     * Optionally removes the listener from previously used file object.
Lines 410-415 Link Here
410
            connectionManager.syncConnections();
411
            connectionManager.syncConnections();
411
        }
412
        }
412
    }
413
    }
414
    
415
    void addSaveCookie(SaveCookie save) {
416
        getCookieSet().add(save);
417
    }
418
    
419
    void removeSaveCookie(SaveCookie save) {
420
        getCookieSet().remove(save);
421
    }
413
422
414
    public void resumeSupports() {
423
    public void resumeSupports() {
415
        connectionAdapter.attachToModel(getModel());
424
        connectionAdapter.attachToModel(getModel());
Lines 556-562 Link Here
556
    * @return the editor support
565
    * @return the editor support
557
    */
566
    */
558
    protected JavaEditor createJavaEditor () {
567
    protected JavaEditor createJavaEditor () {
559
        JavaEditor je = new JavaEditor (getPrimaryEntry ());
568
        JavaEditor je = new JavaEditor (this);
560
        return je;
569
        return je;
561
    }
570
    }
562
571
Lines 595-601 Link Here
595
            synchronized (this) {
604
            synchronized (this) {
596
                editorSupport = createJavaEditor();
605
                editorSupport = createJavaEditor();
597
                if (parserGlue != null)
606
                if (parserGlue != null)
598
                    parserGlue.cloneableSupportCreated(extractCloneableEditor(editorSupport));
607
                    parserGlue.cloneableSupportCreated(editorSupport);
599
            }
608
            }
600
        }
609
        }
601
        return editorSupport;
610
        return editorSupport;
Lines 791-797 Link Here
791
     * may be called more than once.
800
     * may be called more than once.
792
     */
801
     */
793
    public Node.Cookie createCookie(Class klass) {
802
    public Node.Cookie createCookie(Class klass) {
794
	// all execution-related services -> getExecSupport
803
//	if (klass.equals(EditorSupport.class)) {
804
//            ErrorManager.getDefault().log("EditorSupport is deprecated");
805
//            Thread.dumpStack();
806
//            return null;
807
//        }
808
        
809
        // all execution-related services -> getExecSupport
795
        if (klass == ConnectionCookie.class) {
810
        if (klass == ConnectionCookie.class) {
796
            return getConnectionSupport();
811
            return getConnectionSupport();
797
	}
812
	}
(-)java/src/org/netbeans/modules/java/JavaEditor.java (-113 / +118 lines)
Lines 46-54 Link Here
46
import org.openide.DialogDisplayer;
46
import org.openide.DialogDisplayer;
47
import org.openide.NotifyDescriptor;
47
import org.openide.NotifyDescriptor;
48
import org.openide.awt.UndoRedo;
48
import org.openide.awt.UndoRedo;
49
import org.openide.cookies.EditorCookie;
49
import org.openide.cookies.LineCookie;
50
import org.openide.cookies.LineCookie;
51
import org.openide.cookies.OpenCookie;
52
import org.openide.cookies.SaveCookie;
53
import org.openide.filesystems.FileLock;
54
import org.openide.filesystems.FileObject;
50
import org.openide.loaders.DataObject;
55
import org.openide.loaders.DataObject;
51
import org.openide.loaders.MultiDataObject;
52
import org.openide.nodes.Node;
56
import org.openide.nodes.Node;
53
import org.openide.nodes.Children;
57
import org.openide.nodes.Children;
54
import org.openide.src.SourceElement;
58
import org.openide.src.SourceElement;
Lines 59-64 Link Here
59
import org.openide.util.actions.SystemAction;
63
import org.openide.util.actions.SystemAction;
60
import org.openide.windows.*;
64
import org.openide.windows.*;
61
import org.openide.ErrorManager;
65
import org.openide.ErrorManager;
66
import org.openide.windows.CloneableOpenSupport;
62
67
63
68
64
/*
69
/*
Lines 71-77 Link Here
71
*
76
*
72
* @author Petr Hamernik
77
* @author Petr Hamernik
73
*/
78
*/
74
public class JavaEditor extends EditorSupport implements PropertyChangeListener {
79
public class JavaEditor extends DataEditorSupport implements PropertyChangeListener, Node.Cookie, OpenCookie, EditorCookie.Observable {
75
    /** The prefix of all magic strings */
80
    /** The prefix of all magic strings */
76
    final static String MAGIC_PREFIX = "//GEN-"; // NOI18N
81
    final static String MAGIC_PREFIX = "//GEN-"; // NOI18N
77
82
Lines 185-228 Link Here
185
    /** Create a new Editor support for the given Java source.
190
    /** Create a new Editor support for the given Java source.
186
    * @param entry the (primary) file entry representing the Java source file
191
    * @param entry the (primary) file entry representing the Java source file
187
    */
192
    */
188
    public JavaEditor(MultiDataObject.Entry entry) {
193
    public JavaEditor(DataObject dob) {
189
        super(entry);
194
        super(dob, new JavaEditorEnv(dob));
190
        // add change listener
195
        // add change listener
191
        addChangeListener(new JavaEditorChangeListener());
196
        addChangeListener(new JavaEditorChangeListener());
192
        JavaMetamodel.getUndoManager().addPropertyChangeListener(new UndoManagerListener(this));
197
        JavaMetamodel.getUndoManager().addPropertyChangeListener(new UndoManagerListener(this));
193
    }
198
    }
194
199
195
    /** Finds data object the editor belongs to.
200
    private void changeTimeoutElapsed() {
196
    * @return data object or null
201
        parseSource(false, true);
197
    */
198
    DataObject getDataObject() {
199
        return findDataObject();
200
    }
202
    }
201
203
    
202
    synchronized UndoRedo.Manager getUndoRedo() {
204
    protected boolean notifyModified() {
203
        if (undoRedo == null) {
205
        if (! super.notifyModified()) {
204
            undoRedo = super.createUndoRedoManager();
206
            return false;
205
            undoRedoPrecreated = true;
207
        }
208
        JavaDataObject obj = (JavaDataObject) getDataObject();
209
        if (obj.getCookie(SaveCookie.class) == null) {
210
            obj.addSaveCookie(new Save());
211
            obj.setModified(true);
206
        }
212
        }
207
        return undoRedo;
213
        return true;
208
    }
214
    }
209
    
215
    
210
    protected UndoRedo.Manager createUndoRedoManager() {
216
    protected void notifyUnmodified() {
211
        if (undoRedoPrecreated) {
217
        super.notifyUnmodified();
212
            undoRedoPrecreated = false;
218
        JavaDataObject obj = (JavaDataObject) getDataObject();
213
            return undoRedo;
219
        SaveCookie save = (SaveCookie) obj.getCookie(SaveCookie.class);
220
        if (save != null) {
221
            obj.removeSaveCookie(save);
222
            obj.setModified(false);
214
        }
223
        }
215
        undoRedo = super.createUndoRedoManager();
216
        return undoRedo;
217
    }
224
    }
218
    
225
    
219
    private void changeTimeoutElapsed() {
226
    private class Save implements SaveCookie {
220
        parseSource(false, true);
227
        public void save() throws IOException {
228
            saveDocument();
229
            getDataObject().setModified(false);
230
        }
221
    }
231
    }
232
    
222
233
223
    private void parseSource(boolean force, final boolean refreshAnnotations) {
234
    private void parseSource(boolean force, final boolean refreshAnnotations) {
224
        if (force) {
235
        if (force) {
225
            JavaMetamodel.getManager().addModified((JavaDataObject) findDataObject());
236
            JavaMetamodel.getManager().addModified((JavaDataObject) getDataObject());
226
        }
237
        }
227
        ERROR_ANNOTATION_QUEUE.post(new Runnable() {
238
        ERROR_ANNOTATION_QUEUE.post(new Runnable() {
228
            public void run() {
239
            public void run() {
Lines 303-309 Link Here
303
        if (onlyIfRunning && (timer==null || !timer.isRunning()))
314
        if (onlyIfRunning && (timer==null || !timer.isRunning()))
304
            return;
315
            return;
305
316
306
        JavaMetamodel.getManager().addModified((JavaDataObject)findDataObject());
317
        JavaMetamodel.getManager().addModified((JavaDataObject)getDataObject());
307
        
318
        
308
        delay = JavaSettings.getDefault().getAutoParsingDelay();
319
        delay = JavaSettings.getDefault().getAutoParsingDelay();
309
        if (delay<=0)
320
        if (delay<=0)
Lines 320-337 Link Here
320
        timer.restart();
331
        timer.restart();
321
    }
332
    }
322
333
323
    /* Calls superclass.
324
    * @param pos Where to place the caret.
325
    * @return always non null editor
326
    */
327
    protected EditorSupport.Editor openAt(PositionRef pos) {
328
        EditorSupport.Editor ed = super.openAt(pos);
329
        ed.requestActive();
330
        return ed;
331
    }
332
333
    public void openAtPosition(PositionRef begin) {
334
    public void openAtPosition(PositionRef begin) {
334
        openAt(begin);
335
        openAt(begin, -1).getComponent().requestActive();
336
    }
337
    
338
    public void openAt(PositionRef p) {
339
        openAtPosition(p);
335
    }
340
    }
336
    
341
    
337
    public void open() {
342
    public void open() {
Lines 409-415 Link Here
409
                result = (Resource) JavaMetamodel.getDefaultRepository().getByMofId(resourceMofId);
414
                result = (Resource) JavaMetamodel.getDefaultRepository().getByMofId(resourceMofId);
410
            }
415
            }
411
            if (result == null || !result.isValid()) {
416
            if (result == null || !result.isValid()) {
412
                result = JavaMetamodel.getManager().getResource(findDataObject().getPrimaryFile());
417
                result = JavaMetamodel.getManager().getResource(getDataObject().getPrimaryFile());
413
                if (result==null)
418
                if (result==null)
414
                    return null;
419
                    return null;
415
                resourceMofId = result.refMofId();
420
                resourceMofId = result.refMofId();
Lines 439-445 Link Here
439
444
440
        if (filling) {
445
        if (filling) {
441
            GuardedReader reader = new GuardedReader(stream, false,
446
            GuardedReader reader = new GuardedReader(stream, false,
442
                Util.getFileEncoding(entry.getFile()));
447
                Util.getFileEncoding(getDataObject().getPrimaryFile()));
443
            kit.read(reader, doc, 0);
448
            kit.read(reader, doc, 0);
444
            fillSections(reader, doc);
449
            fillSections(reader, doc);
445
            newLineType = reader.getNewLineType();
450
            newLineType = reader.getNewLineType();
Lines 475-481 Link Here
475
    */
480
    */
476
    protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream) throws IOException, BadLocationException {
481
    protected void saveFromKitToStream(StyledDocument doc, EditorKit kit, OutputStream stream) throws IOException, BadLocationException {
477
        OutputStream os = new NewLineOutputStream(stream, newLineType);
482
        OutputStream os = new NewLineOutputStream(stream, newLineType);
478
        String encoding = Util.getFileEncoding(entry.getFile());
483
        String encoding = Util.getFileEncoding(getDataObject().getPrimaryFile());
479
        if (sections != null) {
484
        if (sections != null) {
480
            ArrayList list = new ArrayList(sections.values());
485
            ArrayList list = new ArrayList(sections.values());
481
            if (list.size() > 0) {
486
            if (list.size() > 0) {
Lines 492-519 Link Here
492
        kit.write(w, doc, 0, doc.getLength());
497
        kit.write(w, doc, 0, doc.getLength());
493
    }
498
    }
494
499
495
    /** Reload the document when changed externally */
500
//    /** Reload the document when changed externally */
496
    protected Task reloadDocumentTask () {
501
//    protected Task reloadDocumentTask () {
497
	StyledDocument doc = null;
502
//	StyledDocument doc = null;
498
	    // PENDING: do not openDocument() to obtain doc, as all text is removed from the
503
//	    // PENDING: do not openDocument() to obtain doc, as all text is removed from the
499
	    // document, guarded sections are (probably) erased anyway. This causes two passes
504
//	    // document, guarded sections are (probably) erased anyway. This causes two passes
500
	    // through loadFromStreamToKit!
505
//	    // through loadFromStreamToKit!
501
            try {
506
//            try {
502
                doc = openDocument();
507
//                doc = openDocument();
503
            }
508
//            }
504
            catch (IOException e) {
509
//            catch (IOException e) {
505
                // no reload performed in this case
510
//                // no reload performed in this case
506
            }
511
//            }
507
512
//
508
            if (doc != null) {
513
//            if (doc != null) {
509
                clearSections();
514
//                clearSections();
510
                NbDocument.unmarkGuarded(doc, 0, doc.getLength());
515
//                NbDocument.unmarkGuarded(doc, 0, doc.getLength());
511
		reloading = true;
516
//		reloading = true;
512
                return super.reloadDocumentTask ();
517
//                return super.reloadDocumentTask ();
513
            }
518
//            }
514
            else
519
//            else
515
                return null;
520
//                return null;
516
    }
521
//    }
517
522
518
    /** Save the document in this thread and start reparsing it.
523
    /** Save the document in this thread and start reparsing it.
519
    * @exception IOException on I/O error
524
    * @exception IOException on I/O error
Lines 523-536 Link Here
523
    }
528
    }
524
529
525
    /** Save the document in this thread.
530
    /** Save the document in this thread.
526
    * @param parse true if the parser should be started, otherwise false
527
    * @exception IOException on I/O error
528
    */
529
    protected void saveDocumentIfNecessary(boolean parse) throws IOException {
530
        saveDocument(false);
531
    }
532
533
    /** Save the document in this thread.
534
    * @param forceSave if true save always, otherwise only when is modified
531
    * @param forceSave if true save always, otherwise only when is modified
535
    * @exception IOException on I/O error
532
    * @exception IOException on I/O error
536
    */
533
    */
Lines 539-545 Link Here
539
            if (!checkCharsetConversion(Util.getFileEncoding(getDataObject().getPrimaryFile()))){
536
            if (!checkCharsetConversion(Util.getFileEncoding(getDataObject().getPrimaryFile()))){
540
                return;
537
                return;
541
            }
538
            }
542
            RepositoryUpdater.getDefault().addFileObjectToSave(findDataObject().getPrimaryFile());
539
            RepositoryUpdater.getDefault().addFileObjectToSave(getDataObject().getPrimaryFile());
543
            super.saveDocument();
540
            super.saveDocument();
544
        }
541
        }
545
    }
542
    }
Lines 587-593 Link Here
587
            StyledDocument doc = getDocument();
584
            StyledDocument doc = getDocument();
588
            Runnable docRenderer = new Runnable() {
585
            Runnable docRenderer = new Runnable() {
589
                public void run() {
586
                public void run() {
590
                    LineCookie cookie = (LineCookie)findDataObject().getCookie(LineCookie.class);
587
                    LineCookie cookie = (LineCookie)getDataObject().getCookie(LineCookie.class);
591
                    Line.Set lines = cookie.getLineSet();
588
                    Line.Set lines = cookie.getLineSet();
592
589
593
                    for (Iterator i=finalAdded.iterator();i.hasNext();) {
590
                    for (Iterator i=finalAdded.iterator();i.hasNext();) {
Lines 654-674 Link Here
654
651
655
    private ClassPath getBootClassPath () {
652
    private ClassPath getBootClassPath () {
656
        if (this.bootClasspath == null) {
653
        if (this.bootClasspath == null) {
657
            this.bootClasspath = ClassPath.getClassPath (this.entry.getFile(), ClassPath.BOOT);
654
            this.bootClasspath = ClassPath.getClassPath (getDataObject().getPrimaryFile(), ClassPath.BOOT);
658
        }
655
        }
659
        return this.bootClasspath;
656
        return this.bootClasspath;
660
    }
657
    }
661
658
662
    private ClassPath getLibrariesPath () {
659
    private ClassPath getLibrariesPath () {
663
        if (this.librariesClasspath == null) {
660
        if (this.librariesClasspath == null) {
664
            this.librariesClasspath = ClassPath.getClassPath (this.entry.getFile(), ClassPath.COMPILE);
661
            this.librariesClasspath = ClassPath.getClassPath (getDataObject().getPrimaryFile(), ClassPath.COMPILE);
665
        }
662
        }
666
        return this.librariesClasspath;
663
        return this.librariesClasspath;
667
    }
664
    }
668
665
669
    private ClassPath getSourcePath () {
666
    private ClassPath getSourcePath () {
670
        if (this.sourceClasspath == null) {
667
        if (this.sourceClasspath == null) {
671
            this.sourceClasspath = ClassPath.getClassPath (this.entry.getFile(), ClassPath.SOURCE);
668
            this.sourceClasspath = ClassPath.getClassPath (getDataObject().getPrimaryFile(), ClassPath.SOURCE);
672
        }
669
        }
673
        return this.sourceClasspath;
670
        return this.sourceClasspath;
674
    }
671
    }
Lines 680-686 Link Here
680
    * @deprecated Please use DataObject services to obtain java hierarchy.
677
    * @deprecated Please use DataObject services to obtain java hierarchy.
681
    */
678
    */
682
    public SourceElement getSource() {
679
    public SourceElement getSource() {
683
        return ((JavaDataObject)findDataObject()).getSource();
680
        return ((JavaDataObject)getDataObject()).getSource();
684
    }
681
    }
685
682
686
    /** Translate a source element to text.
683
    /** Translate a source element to text.
Lines 1126-1156 Link Here
1126
        return beginPos;
1123
        return beginPos;
1127
    }
1124
    }
1128
1125
1129
    // ==================== Misc not-public methods ========================
1126
    protected CloneableEditor createCloneableEditor() {
1130
1127
        return new JavaEditorComponent(this);
1131
    /* A method to create a new component. Overridden in subclasses.
1132
    * @return the {@link Editor} for this support
1133
    */
1134
    protected CloneableTopComponent createCloneableTopComponent () {
1135
        prepareDocument();
1136
        return createJavaEditorComponent();
1137
    }
1128
    }
1138
1129
1139
    /** Method for creation of the java editor component
1130
//        // ==================== Misc not-public methods ========================
1140
    * - accessible from the innerclass.
1131
//
1141
    */
1132
//    /** Method for creation of the java editor component
1142
    JavaEditorComponent createJavaEditorComponent() {
1133
//    * - accessible from the innerclass.
1143
        DataObject obj = findDataObject ();
1134
//    */
1144
        JavaEditorComponent editor = new JavaEditorComponent(obj);
1135
//    JavaEditorComponent createJavaEditorComponent() {
1145
        editor.setIcon(obj.getNodeDelegate().getIcon(java.beans.BeanInfo.ICON_COLOR_16x16));
1136
//        DataObject obj = getDataObject ();
1146
1137
//        JavaEditorComponent editor = new JavaEditorComponent(this);
1147
        // dock into editor mode if possible
1138
//        //editor.setIcon(obj.getNodeDelegate().getIcon(java.beans.BeanInfo.ICON_COLOR_16x16));
1148
        Mode editorMode = WindowManager.getDefault().findMode(EDITOR_MODE);
1139
//
1149
        if (editorMode != null)
1140
//        // dock into editor mode if possible
1150
            editorMode.dockInto(editor);
1141
//        Mode editorMode = WindowManager.getDefault().findMode(EDITOR_MODE);
1151
1142
//        //if (editorMode != null)
1152
        return editor;
1143
//        //    editorMode.dockInto(editor);
1153
    }
1144
//
1145
//        return editor;
1146
//    }
1154
1147
1155
    /** Set all sections as invalid. It is called from closeLast method
1148
    /** Set all sections as invalid. It is called from closeLast method
1156
    * of the JavaEditorComponent.
1149
    * of the JavaEditorComponent.
Lines 1181-1193 Link Here
1181
	}
1174
	}
1182
	return fromWhere;
1175
	return fromWhere;
1183
    }
1176
    }
1177
    
1178
    public static class JavaEditorEnv extends DataEditorSupport.Env {
1184
1179
1180
        static final long serialVersionUID = -6792511207355520950L;
1181
        
1182
        public JavaEditorEnv(DataObject obj) {
1183
            super(obj);
1184
        }
1185
        
1186
        protected FileObject getFile() {
1187
            return getDataObject().getPrimaryFile();
1188
        }
1189
        protected FileLock takeLock() throws IOException {
1190
            return ((JavaDataObject) getDataObject()).getPrimaryEntry().takeLock();
1191
        }
1192
        public CloneableOpenSupport findCloneableOpenSupport() {
1193
            // must be sync with cookies.add(EditorCookie.class, factory);
1194
            // #12938 XML files do not persist in Source editor
1195
            return (CloneableOpenSupport) getDataObject().getCookie(EditorCookie.class);
1196
        }
1197
    }
1198
    
1185
    /** The real component of the Java editor.
1199
    /** The real component of the Java editor.
1186
    * Subclasses should not attempt to work with this;
1200
    * Subclasses should not attempt to work with this;
1187
    * if they require special editing support, separate windows
1201
    * if they require special editing support, separate windows
1188
    * should be created by overriding (e.g.) {@link EditorSupport#open}.
1202
    * should be created by overriding (e.g.) {@link EditorSupport#open}.
1189
    */
1203
    */
1190
    public static class JavaEditorComponent extends EditorSupport.Editor {
1204
    public static class JavaEditorComponent extends CloneableEditor {
1191
        /** Default delay between cursor movement and updating selected element nodes. */
1205
        /** Default delay between cursor movement and updating selected element nodes. */
1192
        static final int SELECTED_NODES_DELAY = 1000;
1206
        static final int SELECTED_NODES_DELAY = 1000;
1193
1207
Lines 1217-1224 Link Here
1217
        }
1231
        }
1218
1232
1219
        /** Creates new editor */
1233
        /** Creates new editor */
1220
        public JavaEditorComponent (DataObject obj) {
1234
        public JavaEditorComponent (CloneableEditorSupport sup) {
1221
            super(obj);
1235
            super(sup);
1222
            initialize();
1236
            initialize();
1223
        }
1237
        }
1224
1238
Lines 1230-1236 Link Here
1230
        void selectElementsAtOffset(final int offset) {
1244
        void selectElementsAtOffset(final int offset) {
1231
            elementSelectionPoster.post(new Runnable() {
1245
            elementSelectionPoster.post(new Runnable() {
1232
                public void run() {
1246
                public void run() {
1233
                    final DataObject d = support.findDataObject();
1247
                    final DataObject d = support.getDataObject();
1234
                    if (!isActiveTC() || d == null || !d.isValid() || d.isTemplate()) {
1248
                    if (!isActiveTC() || d == null || !d.isValid() || d.isTemplate()) {
1235
                      return;
1249
                      return;
1236
                    }
1250
                    }
Lines 1361-1368 Link Here
1361
1375
1362
        /** Obtain a support for this component */
1376
        /** Obtain a support for this component */
1363
        private void initialize () {
1377
        private void initialize () {
1364
            support = (JavaEditor)obj.getCookie(JavaEditor.class);
1378
            support = (JavaEditor) cloneableEditorSupport();
1365
            assert support != null : "jdo.getCookie(JavaEditor.class) returned null for JDO " + obj.getPrimaryFile().getPath(); // NOI18N
1379
            //assert support != null : "jdo.getCookie(JavaEditor.class) returned null for JDO " + obj.getPrimaryFile().getPath(); // NOI18N
1366
1380
1367
            timerSelNodes = new Timer(200, new java.awt.event.ActionListener() {
1381
            timerSelNodes = new Timer(200, new java.awt.event.ActionListener() {
1368
                                          public void actionPerformed(java.awt.event.ActionEvent e) {
1382
                                          public void actionPerformed(java.awt.event.ActionEvent e) {
Lines 1404-1418 Link Here
1404
            timerSelNodes.setInitialDelay(SELECTED_NODES_DELAY);
1418
            timerSelNodes.setInitialDelay(SELECTED_NODES_DELAY);
1405
            timerSelNodes.restart();
1419
            timerSelNodes.restart();
1406
            lastCaretOffset = pos;
1420
            lastCaretOffset = pos;
1407
        }
1408
1409
1410
        /* Is called from the clone method to create new component from this one.
1411
        * This implementation only clones the object by calling super.clone method.
1412
        * @return the copy of this object
1413
        */
1414
        protected CloneableTopComponent createClonedObject () {
1415
            return support.createJavaEditorComponent();
1416
        }
1421
        }
1417
1422
1418
        /* This method is called when parent window of this component has focus,
1423
        /* This method is called when parent window of this component has focus,
(-)java/src/org/netbeans/modules/java/bridge/ElementImpl.java (-2 / +2 lines)
Lines 46-52 Link Here
46
import org.netbeans.modules.javacore.jmiimpl.javamodel.TypeClassImpl;
46
import org.netbeans.modules.javacore.jmiimpl.javamodel.TypeClassImpl;
47
import org.openide.ErrorManager;
47
import org.openide.ErrorManager;
48
import org.openide.filesystems.FileObject;
48
import org.openide.filesystems.FileObject;
49
import org.openide.text.EditorSupport;
49
import org.openide.text.CloneableEditorSupport;
50
import org.openide.util.Utilities;
50
import org.openide.util.Utilities;
51
51
52
/**
52
/**
Lines 868-874 Link Here
868
868
869
    public void checkDocument() {
869
    public void checkDocument() {
870
        JavaDataObject jdo = model.getJavaDataObject();
870
        JavaDataObject jdo = model.getJavaDataObject();
871
        EditorSupport edSupport = (EditorSupport) jdo.getCookie (EditorSupport.class);
871
        CloneableEditorSupport edSupport = (CloneableEditorSupport) jdo.getCookie (CloneableEditorSupport.class);
872
        if (!edSupport.isDocumentLoaded()) {
872
        if (!edSupport.isDocumentLoaded()) {
873
            try {
873
            try {
874
                edSupport.openDocument();
874
                edSupport.openDocument();
(-)java/src/org/netbeans/modules/java/bridge/LangEnvImpl.java (-1 / +1 lines)
Lines 188-194 Link Here
188
                PositionBounds bounds = JavaMetamodel.getManager().getElementPosition((org.netbeans.jmi.javamodel.Element) refObject);
188
                PositionBounds bounds = JavaMetamodel.getManager().getElementPosition((org.netbeans.jmi.javamodel.Element) refObject);
189
                if (bounds == null)
189
                if (bounds == null)
190
                    return;
190
                    return;
191
                ((JavaEditor) jdo.getCookie(JavaEditor.class)).openAtPosition(bounds.getBegin());
191
                ((JavaEditor) jdo.getCookie(JavaEditor.class)).openAt(bounds.getBegin());
192
            } catch (javax.jmi.reflect.InvalidObjectException e) {
192
            } catch (javax.jmi.reflect.InvalidObjectException e) {
193
            }
193
            }
194
        }
194
        }
(-)java/src/org/netbeans/modules/java/ui/nodes/elements/ElementNode.java (-1 / +1 lines)
Lines 935-941 Link Here
935
                PositionBounds bounds = JavaMetamodel.getManager().getElementPosition(node.element);
935
                PositionBounds bounds = JavaMetamodel.getManager().getElementPosition(node.element);
936
                if (bounds == null)
936
                if (bounds == null)
937
                    return;
937
                    return;
938
                ((JavaEditor) d.getCookie(JavaEditor.class)).openAtPosition(bounds.getBegin());
938
                ((JavaEditor) d.getCookie(JavaEditor.class)).openAt(bounds.getBegin());
939
            } catch (javax.jmi.reflect.InvalidObjectException e) {
939
            } catch (javax.jmi.reflect.InvalidObjectException e) {
940
            }
940
            }
941
        }
941
        }
(-)java/javacore/src/org/netbeans/modules/javacore/jmiimpl/javamodel/ResourceImpl.java (-5 / +5 lines)
Lines 38-44 Link Here
38
import org.openide.loaders.DataObject;
38
import org.openide.loaders.DataObject;
39
import org.openide.loaders.DataObjectNotFoundException;
39
import org.openide.loaders.DataObjectNotFoundException;
40
import org.openide.loaders.MultiDataObject;
40
import org.openide.loaders.MultiDataObject;
41
import org.openide.text.EditorSupport;
41
import org.openide.text.CloneableEditorSupport;
42
import org.openide.text.NbDocument;
42
import org.openide.text.NbDocument;
43
import org.openide.text.PositionBounds;
43
import org.openide.text.PositionBounds;
44
import org.openide.text.PositionRef;
44
import org.openide.text.PositionRef;
Lines 752-758 Link Here
752
                getDiff(diff);
752
                getDiff(diff);
753
            }
753
            }
754
            DataObject dobj = JavaMetamodel.getManager().getDataObject(this);
754
            DataObject dobj = JavaMetamodel.getManager().getDataObject(this);
755
            final EditorSupport editor = (EditorSupport) dobj.getCookie(EditorSupport.class);
755
            final CloneableEditorSupport editor = (CloneableEditorSupport) dobj.getCookie(CloneableEditorSupport.class);
756
            StyledDocument doc = null;
756
            StyledDocument doc = null;
757
            if (editor != null) {
757
            if (editor != null) {
758
                doc = editor.getDocument();
758
                doc = editor.getDocument();
Lines 838-844 Link Here
838
838
839
    public void applyDiff(List diff, boolean internalCall, boolean parseAfterApply) {
839
    public void applyDiff(List diff, boolean internalCall, boolean parseAfterApply) {
840
        DataObject dobj = JavaMetamodel.getManager().getDataObject(this);
840
        DataObject dobj = JavaMetamodel.getManager().getDataObject(this);
841
        final EditorSupport editor = (EditorSupport) dobj.getCookie(EditorSupport.class);
841
        final CloneableEditorSupport editor = (CloneableEditorSupport) dobj.getCookie(CloneableEditorSupport.class);
842
            if (editor!=null) {
842
            if (editor!=null) {
843
                StyledDocument doc = editor.getDocument();
843
                StyledDocument doc = editor.getDocument();
844
                if (doc != null) {
844
                if (doc != null) {
Lines 863-869 Link Here
863
        }
863
        }
864
    }
864
    }
865
865
866
    private void applyDiff(List diff, EditorSupport doc) {
866
    private void applyDiff(List diff, CloneableEditorSupport doc) {
867
        List tempDiffs = null;
867
        List tempDiffs = null;
868
        List list = new LinkedList();
868
        List list = new LinkedList();
869
        try {
869
        try {
Lines 959-965 Link Here
959
    private void rollbackDiff() {
959
    private void rollbackDiff() {
960
        DataObject dobj = JavaMetamodel.getManager().getDataObject(this);
960
        DataObject dobj = JavaMetamodel.getManager().getDataObject(this);
961
        if (rbList != null) {            
961
        if (rbList != null) {            
962
            final EditorSupport editor = (EditorSupport) dobj.getCookie(EditorSupport.class);
962
            final CloneableEditorSupport editor = (CloneableEditorSupport) dobj.getCookie(CloneableEditorSupport.class);
963
            StyledDocument doc = editor.getDocument();
963
            StyledDocument doc = editor.getDocument();
964
            final List list = rbList;
964
            final List list = rbList;
965
            rbList = null;
965
            rbList = null;
(-)java/javacore/src/org/netbeans/modules/javacore/parser/ASTProvider.java (-3 / +3 lines)
Lines 33-39 Link Here
33
import org.openide.filesystems.FileObject;
33
import org.openide.filesystems.FileObject;
34
import org.openide.filesystems.FileUtil;
34
import org.openide.filesystems.FileUtil;
35
import org.openide.loaders.DataObject;
35
import org.openide.loaders.DataObject;
36
import org.openide.text.EditorSupport;
36
import org.openide.text.DataEditorSupport;
37
import org.openide.text.PositionBounds;
37
import org.openide.text.PositionBounds;
38
import org.openide.text.PositionRef;
38
import org.openide.text.PositionRef;
39
39
Lines 44-50 Link Here
44
 */
44
 */
45
public class ASTProvider implements ParserTokens, ASTreeTypes, ASTContext {
45
public class ASTProvider implements ParserTokens, ASTreeTypes, ASTContext {
46
    DataObject dobj;
46
    DataObject dobj;
47
    private EditorSupport editor;
47
    private DataEditorSupport editor;
48
    private ASTree topNode;
48
    private ASTree topNode;
49
    private Token[] tokens;
49
    private Token[] tokens;
50
    private String sourceText;
50
    private String sourceText;
Lines 377-383 Link Here
377
    
377
    
378
    public PositionBounds createBounds(int[] oldOffsets) {
378
    public PositionBounds createBounds(int[] oldOffsets) {
379
        if (editor == null)
379
        if (editor == null)
380
            editor = (EditorSupport) dobj.getCookie(EditorSupport.class);
380
            editor = (DataEditorSupport) dobj.getCookie(EditorCookie.class);
381
        
381
        
382
        int[] offsets = getDocumentOffsets(oldOffsets);
382
        int[] offsets = getDocumentOffsets(oldOffsets);
383
        
383
        
(-)form/src/org/netbeans/modules/form/FormEditorSupport.java (-41 / +14 lines)
Lines 115-121 Link Here
115
115
116
    public FormEditorSupport(MultiDataObject.Entry javaEntry,
116
    public FormEditorSupport(MultiDataObject.Entry javaEntry,
117
                             FormDataObject formDataObject) {
117
                             FormDataObject formDataObject) {
118
        super(javaEntry);
118
        super(formDataObject);
119
        this.formDataObject = formDataObject;
119
        this.formDataObject = formDataObject;
120
    }
120
    }
121
121
Lines 163-176 Link Here
163
    /** Overriden from JavaEditor - opens editor at given position and ensures
163
    /** Overriden from JavaEditor - opens editor at given position and ensures
164
     * it is selected in the multiview.
164
     * it is selected in the multiview.
165
     */
165
     */
166
    protected EditorSupport.Editor openAt(PositionRef pos) {
166
    public void openAt(PositionRef pos) {
167
        elementToOpen = JAVA_ELEMENT_INDEX;
167
        elementToOpen = JAVA_ELEMENT_INDEX;
168
        openCloneableTopComponent();
168
        openCloneableTopComponent();
169
169
170
        MultiViewHandler handler = MultiViews.findMultiViewHandler(multiviewTC);
170
        MultiViewHandler handler = MultiViews.findMultiViewHandler(multiviewTC);
171
        handler.requestActive(handler.getPerspectives()[JAVA_ELEMENT_INDEX]);
171
        handler.requestActive(handler.getPerspectives()[JAVA_ELEMENT_INDEX]);
172
172
173
        return super.openAt(pos);
173
        super.openAt(pos);
174
    }
174
    }
175
175
176
    /** Public method for loading form data from file. Does not open the
176
    /** Public method for loading form data from file. Does not open the
Lines 241-271 Link Here
241
            throw ioEx;
241
            throw ioEx;
242
    }
242
    }
243
243
244
    /** Save the document in this thread.
245
     * @param parse true if the parser should be started, otherwise false
246
     * @exception IOException on I/O error
247
     */
248
    protected void saveDocumentIfNecessary(boolean parse) throws IOException {
249
        IOException ioEx = null;
250
        try {
251
            saveFormData();
252
            super.saveDocumentIfNecessary(parse);
253
        }
254
        catch (PersistenceException ex) {
255
            Throwable t = ex.getOriginalException();
256
            if (t instanceof IOException)
257
                ioEx = (IOException) t;
258
            else {
259
                ioEx = new IOException("Cannot save the form"); // NOI18N
260
                ErrorManager.getDefault().annotate(ioEx, t != null ? t : ex);
261
            }
262
        }
263
        reportErrors(SAVING);
264
265
        if (ioEx != null)
266
            throw ioEx;
267
    }
268
269
    /** Public method for saving form data to file. Does not save the
244
    /** Public method for saving form data to file. Does not save the
270
     * source code (document), does not report errors and does not throw
245
     * source code (document), does not report errors and does not throw
271
     * any exceptions.
246
     * any exceptions.
Lines 725-731 Link Here
725
            reloadDocument();
700
            reloadDocument();
726
    }
701
    }
727
702
728
    protected org.openide.util.Task reloadDocumentTask() {
703
    protected org.openide.util.Task reloadDocument() {
729
        MultiViewHandler handler = MultiViews.findMultiViewHandler(multiviewTC);
704
        MultiViewHandler handler = MultiViews.findMultiViewHandler(multiviewTC);
730
        MultiViewPerspective[] mvps = handler.getPerspectives();
705
        MultiViewPerspective[] mvps = handler.getPerspectives();
731
        int openedElement = 0;
706
        int openedElement = 0;
Lines 749-755 Link Here
749
        // TODO would be better not to close the form, but just reload
724
        // TODO would be better not to close the form, but just reload
750
        // FormModel and update form designer(s) with the new model
725
        // FormModel and update form designer(s) with the new model
751
726
752
        org.openide.util.Task docLoadTask = super.reloadDocumentTask();
727
        org.openide.util.Task docLoadTask = super.reloadDocument();
753
728
754
        // after reloading is done, open the form editor again
729
        // after reloading is done, open the form editor again
755
        java.awt.EventQueue.invokeLater(new Runnable() {
730
        java.awt.EventQueue.invokeLater(new Runnable() {
Lines 1154-1163 Link Here
1154
1129
1155
    // -------
1130
    // -------
1156
    // window system & multiview
1131
    // window system & multiview
1157
1132
    
1158
    /** Overriden from JavaEditor. Gets called if java editor is opened first
1133
    protected CloneableEditorSupport.Pane createPane() {
1159
     * via EditCookie. */
1160
    protected CloneableTopComponent createCloneableTopComponent() {
1161
        MultiViewDescription[] descs = new MultiViewDescription[] {
1134
        MultiViewDescription[] descs = new MultiViewDescription[] {
1162
            new JavaDesc(formDataObject), new FormDesc(formDataObject) };
1135
            new JavaDesc(formDataObject), new FormDesc(formDataObject) };
1163
1136
Lines 1172-1178 Link Here
1172
        if (editorMode != null) {
1145
        if (editorMode != null) {
1173
            editorMode.dockInto(mvtc);
1146
            editorMode.dockInto(mvtc);
1174
        }
1147
        }
1175
        return mvtc;
1148
        return (CloneableEditorSupport.Pane)mvtc;
1176
    }
1149
    }
1177
    
1150
    
1178
    private static String getMVTCToolTipText(FormDataObject formDataObject) {
1151
    private static String getMVTCToolTipText(FormDataObject formDataObject) {
Lines 1431-1437 Link Here
1431
            JavaEditor javaEditor = getJavaEditor();
1404
            JavaEditor javaEditor = getJavaEditor();
1432
            if (javaEditor != null) {
1405
            if (javaEditor != null) {
1433
                javaEditor.prepareDocument();
1406
                javaEditor.prepareDocument();
1434
                JavaEditorTopComponent editor = new JavaEditorTopComponent(dataObject);
1407
                JavaEditorTopComponent editor = new JavaEditorTopComponent((JavaEditor) dataObject.getCookie(JavaEditor.class));
1435
                Node[] nodes = editor.getActivatedNodes();
1408
                Node[] nodes = editor.getActivatedNodes();
1436
                if ((nodes == null) || (nodes.length == 0)) {
1409
                if ((nodes == null) || (nodes.length == 0)) {
1437
                    editor.setActivatedNodes(new Node[] {dataObject.getNodeDelegate()});
1410
                    editor.setActivatedNodes(new Node[] {dataObject.getNodeDelegate()});
Lines 1491-1498 Link Here
1491
            super();
1464
            super();
1492
        }
1465
        }
1493
1466
1494
        JavaEditorTopComponent(DataObject dobj) {
1467
        JavaEditorTopComponent(DataEditorSupport s) {
1495
            super(dobj);
1468
            super(s);
1496
        }
1469
        }
1497
1470
1498
        public JComponent getToolbarRepresentation() {
1471
        public JComponent getToolbarRepresentation() {
Lines 1528-1537 Link Here
1528
            multiViewObserver = callback;
1501
            multiViewObserver = callback;
1529
1502
1530
            // needed for deserialization...
1503
            // needed for deserialization...
1531
            if (obj instanceof FormDataObject) { // [obj is from EditorSupport.Editor]
1504
            if (((DataEditorSupport) cloneableEditorSupport ()).getDataObject() instanceof FormDataObject) { // [obj is from EditorSupport.Editor]
1532
                // this is used (or misused?) to obtain the deserialized
1505
                // this is used (or misused?) to obtain the deserialized
1533
                // multiview topcomponent and set it to FormEditorSupport
1506
                // multiview topcomponent and set it to FormEditorSupport
1534
                ((FormDataObject)obj).getFormEditor().setTopComponent(
1507
                ((FormDataObject)((DataEditorSupport) cloneableEditorSupport ()).getDataObject()).getFormEditor().setTopComponent(
1535
                                                   callback.getTopComponent());
1508
                                                   callback.getTopComponent());
1536
            }
1509
            }
1537
        }
1510
        }
Lines 1569-1575 Link Here
1569
        public void updateName() {
1542
        public void updateName() {
1570
            super.updateName();
1543
            super.updateName();
1571
            if (multiViewObserver != null) {
1544
            if (multiViewObserver != null) {
1572
                FormDataObject formDataObject = (FormDataObject)obj;
1545
                FormDataObject formDataObject = (FormDataObject)((DataEditorSupport) cloneableEditorSupport ()).getDataObject();
1573
                setDisplayName(getMVTCDisplayName(formDataObject));
1546
                setDisplayName(getMVTCDisplayName(formDataObject));
1574
            }
1547
            }
1575
        }
1548
        }

Return to bug 12331