2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.ddloaders.common;
44
import org.openide.cookies.SaveCookie;
45
import org.openide.filesystems.FileObject;
46
import org.openide.loaders.MultiFileLoader;
47
import org.openide.util.RequestProcessor;
48
import org.netbeans.modules.j2ee.ddloaders.common.xmlutils.XMLJ2eeDataObject;
49
import org.netbeans.modules.j2ee.ddloaders.common.xmlutils.XMLJ2eeUtils;
52
import javax.swing.text.Document;
53
import java.io.IOException;
54
import java.util.logging.Level;
55
import java.util.logging.Logger;
57
/** Represents a DD2beansDataObject in the Repository.
61
public abstract class DD2beansDataObject extends XMLJ2eeDataObject implements org.openide.nodes.CookieSet.Factory{
63
private static final int DELAY_FOR_TIMER=200;
64
/** Private request processor for parsing and text generating tasks */
65
protected final static RequestProcessor RP = new RequestProcessor("XML Parsing"); //NOI18N
66
private final RequestProcessor.Task generationTask;
67
// constructor settings
68
private String prefixMark;
70
private static final long serialVersionUID = -5363900668319174348L;
72
public DD2beansDataObject(FileObject pf, MultiFileLoader loader)
73
throws org.openide.loaders.DataObjectExistsException {
74
this (pf, loader,true);
77
public DD2beansDataObject(FileObject pf, MultiFileLoader loader, final boolean saveAfterNodeChanges)
78
throws org.openide.loaders.DataObjectExistsException {
81
generationTask = RP.create(new Runnable() {
82
int numberOfStartedGens;
84
numberOfStartedGens++;
85
final String newDoc = generateDocument();
86
SwingUtilities.invokeLater(new Runnable() {
89
Document doc = getEditorSupport().openDocument();
90
XMLJ2eeUtils.replaceDocument(doc, newDoc, prefixMark);
91
setDocumentValid(true);
92
if (saveAfterNodeChanges) {
93
SaveCookie savec = (SaveCookie) getCookie(SaveCookie.class);
98
// this is necessary for correct undo behaviour
99
getEditorSupport().getUndo().discardAllEdits();
100
} catch (javax.swing.text.BadLocationException e) {
101
Logger.getLogger("global").log(Level.INFO, null, e);
102
} catch (IOException e) {
103
Logger.getLogger("global").log(Level.INFO, null, e);
105
synchronized (generationTask) {
106
numberOfStartedGens--;
107
if (numberOfStartedGens == 0) {
118
/** Create document from the Node. This method is called after Node (Node properties)is changed.
119
* The document is generated from data modul (isDocumentGenerable=true)
121
protected abstract String generateDocument();
123
/** setter for prefixMark. This is information, which prefix in xml document should be preserved
124
* after replacing by new generated document (This is mainly for preserving comments at the beginning)
125
* @param prefix prefixMark
127
protected final void setPrefixMark(String prefix) {
128
this.prefixMark=prefix;
130
/** gettert for prefixMark
133
protected final String getPrefixMark() {
137
/** Setter for property nodeDirty.
138
* @param dirty New value of property nodeDirty.
140
public void setNodeDirty(boolean dirty){
141
//System.out.println("setNodeDirty("+dirty+")");
143
synchronized (this) {
150
public RequestProcessor.Task getGenerationTask(){
151
return generationTask;
154
protected void restartGen() {
155
generationTask.schedule(DELAY_FOR_TIMER);