Lines 42-53
package org.openide.loaders;
Link Here
|
42 |
package org.openide.loaders; |
42 |
package org.openide.loaders; |
43 |
|
43 |
|
44 |
|
44 |
|
|
|
45 |
import java.awt.Image; |
46 |
import java.awt.Toolkit; |
45 |
import org.openide.filesystems.*; |
47 |
import org.openide.filesystems.*; |
46 |
import java.io.IOException; |
48 |
import java.io.IOException; |
47 |
import java.util.*; |
49 |
import java.util.*; |
48 |
import org.netbeans.junit.*; |
50 |
import org.netbeans.junit.*; |
49 |
import java.beans.PropertyChangeListener; |
51 |
import java.beans.PropertyChangeListener; |
|
|
52 |
import java.net.URL; |
53 |
import javax.swing.Action; |
50 |
import junit.framework.Test; |
54 |
import junit.framework.Test; |
|
|
55 |
import org.openide.actions.EditAction; |
56 |
import org.openide.nodes.Node; |
51 |
|
57 |
|
52 |
/** Check what can be done when registering loaders in layer. |
58 |
/** Check what can be done when registering loaders in layer. |
53 |
* @author Jaroslav Tulach |
59 |
* @author Jaroslav Tulach |
Lines 93-98
public class DataLoaderInLayerTest exten
Link Here
|
93 |
} |
99 |
} |
94 |
} |
100 |
} |
95 |
} |
101 |
} |
|
|
102 |
private static <F extends DataObject.Factory> void addRemove(String mime, F factory, boolean add) throws IOException { |
103 |
String res = "Loaders/" + mime + "/Factories/" + factory.getClass().getSimpleName().replace('.', '-') + ".instance"; |
104 |
FileObject root = Repository.getDefault().getDefaultFileSystem().getRoot(); |
105 |
if (add) { |
106 |
FileObject fo = FileUtil.createData(root, res); |
107 |
fo.setAttribute("instanceCreate", factory); |
108 |
assertSame("No serialization, just memory fs is used", factory, fo.getAttribute("instanceCreate")); |
109 |
} else { |
110 |
FileObject fo = root.getFileObject(res); |
111 |
if (fo != null) { |
112 |
fo.delete(); |
113 |
} |
114 |
} |
115 |
} |
96 |
|
116 |
|
97 |
public void testSimpleGetChildren() throws Exception { |
117 |
public void testSimpleGetChildren() throws Exception { |
98 |
DataLoader l = DataLoader.getLoader(SimpleUniFileLoader.class); |
118 |
DataLoader l = DataLoader.getLoader(SimpleUniFileLoader.class); |
Lines 122-127
public class DataLoaderInLayerTest exten
Link Here
|
122 |
assertEquals(SimpleDataObject.class, dob.getClass()); |
142 |
assertEquals(SimpleDataObject.class, dob.getClass()); |
123 |
} finally { |
143 |
} finally { |
124 |
addRemove("text/plain", SimpleFactory.class, false); |
144 |
addRemove("text/plain", SimpleFactory.class, false); |
|
|
145 |
} |
146 |
} |
147 |
|
148 |
public void testFactoryInstanceRegistrationWorksAsWell() throws Exception { |
149 |
URL u = DataLoaderInLayerTest.class.getResource("/org/openide/loaders/saveAll.gif"); |
150 |
Image img = Toolkit.getDefaultToolkit().createImage(u); |
151 |
|
152 |
DataObject.Factory f = DataLoaderPool.factory(SimpleDataObject.class, "text/simplefactory", img); |
153 |
|
154 |
addRemove("text/plain", f, true); |
155 |
try { |
156 |
FileSystem lfs = createFS("folderF/file.simple"); |
157 |
FileObject fo = lfs.findResource("folderF"); |
158 |
DataFolder df = DataFolder.findFolder(fo); |
159 |
DataObject[] arr = df.getChildren(); |
160 |
assertEquals("One object", 1, arr.length); |
161 |
DataObject dob = arr[0]; |
162 |
assertEquals(SimpleDataObject.class, dob.getClass()); |
163 |
|
164 |
FileObject root = Repository.getDefault().getDefaultFileSystem().getRoot(); |
165 |
FileObject edit = FileUtil.createData(root, "/Loaders/text/simplefactory/Actions/org-openide-actions-EditAction.instance"); |
166 |
|
167 |
Node node = dob.getNodeDelegate(); |
168 |
Action[] actions = node.getActions(true); |
169 |
assertEquals("One action is present: " + Arrays.asList(actions), 1, actions.length); |
170 |
assertEquals("It is the edit one", EditAction.class, actions[0].getClass()); |
171 |
|
172 |
assertSame("Icon is propagated for open", img, node.getOpenedIcon(0)); |
173 |
assertSame("Icon is propagated", img, node.getIcon(0)); |
174 |
} finally { |
175 |
addRemove("text/plain", f, false); |
125 |
} |
176 |
} |
126 |
} |
177 |
} |
127 |
|
178 |
|