Skip to content
This repository was archived by the owner on Dec 18, 2019. It is now read-only.

Commit f05441a

Browse files
author
daimor
committed
added editing for classes
1 parent 99811ee commit f05441a

26 files changed

+2441
-416
lines changed

NBStudioCore/src/org/nbstudio/core/Connection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public final class Connection implements Serializable {
2626
public final String address;
2727
public final int port;
2828
public final String namespace;
29-
private static Database connection;
29+
private Database connection;
3030
public final String username;
3131
public final String password;
3232

NBStudioCore/src/org/nbstudio/core/cls/CLSFile.java

Lines changed: 620 additions & 0 deletions
Large diffs are not rendered by default.

NBStudioCore/src/org/nbstudio/core/cls/CLSParserListerer4Save.java

Lines changed: 1125 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package org.nbstudio.core.cls;
6+
7+
import com.intersys.cache.CacheObject;
8+
import com.intersys.classes.CacheRootObject;
9+
import com.intersys.classes.Dictionary.ClassDefinition;
10+
import com.intersys.classes.Dictionary.PropertyDefinition;
11+
import com.intersys.objects.CacheException;
12+
import com.intersys.objects.Database;
13+
import com.intersys.objects.Id;
14+
import java.lang.reflect.Field;
15+
import java.util.ArrayList;
16+
import java.util.HashMap;
17+
import java.util.Iterator;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.regex.Pattern;
21+
import org.nbstudio.syntax.cls.clsParser;
22+
23+
/**
24+
*
25+
* @author daimor
26+
*/
27+
public class CLSUtils {
28+
29+
private static ArrayList<String> propertiesExcludeList = new ArrayList<String>() {
30+
{
31+
add("Name");
32+
add("Description");
33+
add("SequenceNumber");
34+
add("Parameters");
35+
36+
addList("%Dictionary.PropertyDefinition", new String[]{"Aliases", "Identity", "OnDelete", "Relationship", "Collection"});
37+
addList("%Dictionary.ParameterDefinition", new String[]{"Default", "Expression"});
38+
addList("%Dictionary.MethodDefinition", new String[]{"ClassMethod", "ClientMethod", "ReturnType", "FormalSpec", "Implementation", "Hash"});
39+
addList("%Dictionary.XDataDefinition", new String[]{"Data"});
40+
addList("%Dictionary.QueryDefinition", new String[]{"SqlQuery", "FormalSpec"});
41+
addList("%Dictionary.TriggerDefinition", new String[]{"Code"});
42+
addList("%Dictionary.IndexDefinition", new String[]{"Properties"});
43+
addList("%Dictionary.ForeignKeyDefinition", new String[]{"Properties", "ReferencedClass", "ReferencedKey"});
44+
addList("%Dictionary.ProjectionDefinition", new String[]{"Type"});
45+
}
46+
47+
public void addList(String clsName, String[] excludeList) {
48+
for (String string : excludeList) {
49+
add(clsName + "||" + string);
50+
}
51+
}
52+
};
53+
54+
private static CacheObject getmInternal(CacheRootObject obj) {
55+
CacheObject mInternal = null;
56+
try {
57+
Field privateStringField = CacheRootObject.class.getDeclaredField("mInternal");
58+
privateStringField.setAccessible(true);
59+
mInternal = (CacheObject) privateStringField.get(obj);
60+
} catch (Exception ignoredException) {
61+
}
62+
return mInternal;
63+
}
64+
65+
public static void setParameters(CacheRootObject obj, List<clsParser.ParameterContext> parametersList) {
66+
try {
67+
Map params = CLSUtils.getParameters(obj);
68+
params.clear();
69+
if (parametersList == null) {
70+
return;
71+
}
72+
for (Iterator<clsParser.ParameterContext> it = parametersList.iterator(); it.hasNext();) {
73+
clsParser.ParameterContext parameterContext = it.next();
74+
String paramName = parameterContext.paramName.getText();
75+
String paramVal = parameterContext.paramVal.getText();
76+
paramVal = paramVal.replaceAll("\"\"", "\"");
77+
paramVal = Pattern.compile("^\"(.*)\"$").matcher(paramVal).replaceAll("$1");
78+
params.put(paramName, paramVal);
79+
}
80+
} catch (Exception ignoredException) {
81+
}
82+
}
83+
84+
public static java.util.Map getParameters(CacheRootObject obj) throws com.intersys.objects.CacheException {
85+
CacheObject mInternal = getmInternal(obj);
86+
com.intersys.cache.Dataholder dh = mInternal.getProperty("Parameters", true);
87+
com.intersys.cache.CacheObject cobj = dh.getCacheObject();
88+
if (cobj == null) {
89+
return null;
90+
}
91+
return (java.util.Map) (cobj.newJavaInstance());
92+
}
93+
94+
public static void setProperty(CacheRootObject obj, String propName, boolean value) {
95+
try {
96+
CacheObject mInternal = getmInternal(obj);
97+
com.intersys.cache.Dataholder dh = new com.intersys.cache.Dataholder(value);
98+
mInternal.setProperty(propName, dh);
99+
} catch (Exception ignoredException) {
100+
}
101+
}
102+
103+
public static void setProperty(CacheRootObject obj, String propName, String value) {
104+
try {
105+
CacheObject mInternal = getmInternal(obj);
106+
value = value.replaceAll("^\"(.*)\"$", "$1");
107+
value = ((value == null) || (value.isEmpty())) ? null : value;
108+
com.intersys.cache.Dataholder dh = new com.intersys.cache.Dataholder(value);
109+
mInternal.setProperty(propName, dh);
110+
} catch (Exception ignoredException) {
111+
}
112+
}
113+
114+
public static String getProperty(CacheRootObject obj, String propName, String defaultValue) {
115+
try {
116+
CacheObject mInternal = getmInternal(obj);
117+
com.intersys.cache.Dataholder dh = mInternal.getProperty(propName, false);
118+
return dh.getString();
119+
} catch (Exception ignoredException) {
120+
return defaultValue;
121+
}
122+
}
123+
124+
public static Boolean getProperty(CacheRootObject obj, String propName, Boolean defaultValue) {
125+
try {
126+
CacheObject mInternal = getmInternal(obj);
127+
com.intersys.cache.Dataholder dh = mInternal.getProperty(propName, false);
128+
return dh.getBoolean();
129+
} catch (Exception ignoredException) {
130+
return defaultValue;
131+
}
132+
}
133+
134+
public static java.util.Map<String, Object> getProperties(CacheRootObject obj) {
135+
HashMap<String, Object> result = new java.util.HashMap<String, Object>();
136+
try {
137+
Database db = obj.getDatabase();
138+
String className = obj._className(true);
139+
ClassDefinition objDef = (ClassDefinition) ClassDefinition.open(db, new Id(className), 0);
140+
141+
List objProps = objDef.getProperties().asList();
142+
for (Iterator it = objProps.iterator(); it.hasNext();) {
143+
PropertyDefinition prop = (PropertyDefinition) it.next();
144+
String propName = prop.getName();
145+
String propType = prop.getType();
146+
String defaultValue = prop.getInitialExpression();
147+
148+
if ((propName.startsWith("%"))
149+
|| propertiesExcludeList.contains(propName)
150+
|| propertiesExcludeList.contains(className + "||" + propName)
151+
|| (("InitialExpression".equals(propName)) && (obj instanceof PropertyDefinition) && (((PropertyDefinition) obj).getInitialExpression().equals("\"\"")))
152+
|| (!propType.matches("(%(Library.)?CacheString)|(%(Library.)?Boolean)"))) {
153+
continue;
154+
}
155+
156+
defaultValue = defaultValue.replaceAll("^\"(.*)\"$", "$1");
157+
defaultValue = defaultValue.replaceAll("\"\"", "\"");
158+
if (propType.matches("%(Library.)?CacheString")) {
159+
result.put(propName, defaultValue);
160+
} else if (propType.matches("%(Library.)?Boolean")) {
161+
result.put(propName, ("1".equals(defaultValue)));
162+
}
163+
}
164+
} catch (CacheException ex) {
165+
}
166+
return result;
167+
168+
}
169+
}

NBStudioCore/src/org/nbstudio/core/cls/clsDataObject.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
*/
55
package org.nbstudio.core.cls;
66

7+
import java.beans.PropertyChangeEvent;
8+
import java.beans.PropertyChangeListener;
79
import java.io.IOException;
10+
import javax.swing.text.Document;
811
import org.openide.awt.ActionID;
912
import org.openide.awt.ActionReference;
1013
import org.openide.awt.ActionReferences;
@@ -14,6 +17,10 @@
1417
import org.openide.loaders.DataObjectExistsException;
1518
import org.openide.loaders.MultiDataObject;
1619
import org.openide.loaders.MultiFileLoader;
20+
import org.openide.nodes.CookieSet;
21+
import org.openide.nodes.Node;
22+
import org.openide.text.CloneableEditorSupport;
23+
import org.openide.text.DataEditorSupport;
1724
import org.openide.util.NbBundle.Messages;
1825

1926
@Messages({
@@ -84,14 +91,44 @@ public class clsDataObject extends MultiDataObject {
8491

8592
public clsDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
8693
super(pf, loader);
87-
registerEditor("text/isc-cls", false);
94+
// registerEditor("text/isc-cls", false);
95+
CookieSet cookies = getCookieSet();
96+
// observer = new GlslShaderFileObserver(this);
97+
98+
final CloneableEditorSupport support = DataEditorSupport.create(this, getPrimaryEntry(), cookies);
99+
support.addPropertyChangeListener(
100+
new PropertyChangeListenerImpl(support));
101+
cookies.add((Node.Cookie) support);
102+
}
103+
104+
// @Override
105+
// protected Node createNodeDelegate() {
106+
// }
107+
108+
private class PropertyChangeListenerImpl implements PropertyChangeListener {
109+
110+
private final CloneableEditorSupport support;
111+
112+
public PropertyChangeListenerImpl(CloneableEditorSupport support) {
113+
this.support = support;
114+
}
115+
116+
public void propertyChange(PropertyChangeEvent event) {
117+
if ("document".equals(event.getPropertyName())) {
118+
if (event.getNewValue() != null) {
119+
// support.getDocument().addDocumentListener(observer);
120+
// observer.runCompileTask();
121+
} else if (event.getOldValue() != null) {
122+
// ((Document) event.getOldValue()).removeDocumentListener(observer);
123+
}
124+
}
125+
}
88126
}
89127

90128
@Override
91129
protected int associateLookup() {
92130
return 1;
93131
}
94-
95132
// @MultiViewElement.Registration(
96133
// displayName = "#LBL_cls_EDITOR",
97134
// iconBase = "org/nbstudio/core/cls/class.png",

0 commit comments

Comments
 (0)