Index: src/META-INF/services/org.openide.filesystems.Repository
===================================================================
RCS file: src/META-INF/services/org.openide.filesystems.Repository
diff -N src/META-INF/services/org.openide.filesystems.Repository
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/META-INF/services/org.openide.filesystems.Repository 12 Aug 2005 09:49:05 -0000 1.1.2.1
@@ -0,0 +1 @@
+org.netbeans.spi.palette.RepositoryImpl
\ No newline at end of file
Index: src/org/netbeans/spi/palette/Bundle.properties
===================================================================
RCS file: src/org/netbeans/spi/palette/Bundle.properties
diff -N src/org/netbeans/spi/palette/Bundle.properties
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/netbeans/spi/palette/Bundle.properties 12 Aug 2005 09:49:02 -0000 1.1.2.1
@@ -0,0 +1,16 @@
+# Sun Public License Notice
+#
+# The contents of this file are subject to the Sun Public License
+# Version 1.0 (the "License"). You may not use this file except in
+# compliance with the License. A copy of the License is available at
+# http://www.sun.com/
+#
+# The Original Code is NetBeans. The Initial Developer of the Original
+# Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
+# Microsystems, Inc. All Rights Reserved.
+
+# Palette: display names and tooltips for the components
+
+#Palette Category: FooCategory
+NAME_foo-FooItem=Foo Item
+HINT_foo-FooItem=This is the testing Foo Item
Index: src/org/netbeans/spi/palette/FooItem.java
===================================================================
RCS file: src/org/netbeans/spi/palette/FooItem.java
diff -N src/org/netbeans/spi/palette/FooItem.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/netbeans/spi/palette/FooItem.java 12 Aug 2005 09:49:03 -0000 1.1.2.1
@@ -0,0 +1,33 @@
+/*
+ * Sun Public License Notice
+ *
+ * The contents of this file are subject to the Sun Public License
+ * Version 1.0 (the "License"). You may not use this file except in
+ * compliance with the License. A copy of the License is available at
+ * http://www.sun.com/
+ *
+ * The Original Code is NetBeans. The Initial Developer of the Original
+ * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+
+package org.netbeans.spi.palette;
+import javax.swing.text.JTextComponent;
+import org.openide.text.ActiveEditorDrop;
+
+
+/**
+ *
+ * @author Libor Kotouc
+ */
+public class FooItem implements ActiveEditorDrop {
+
+ public FooItem() {
+ }
+
+ public boolean handleTransfer(JTextComponent targetComponent) {
+
+ return true;
+ }
+
+}
Index: src/org/netbeans/spi/palette/FooItem16.gif
===================================================================
RCS file: src/org/netbeans/spi/palette/FooItem16.gif
diff -N src/org/netbeans/spi/palette/FooItem16.gif
Binary files /dev/null and /tmp/cvs_2aaVx differ
Index: src/org/netbeans/spi/palette/FooItem32.gif
===================================================================
RCS file: src/org/netbeans/spi/palette/FooItem32.gif
diff -N src/org/netbeans/spi/palette/FooItem32.gif
Binary files /dev/null and /tmp/cvsa3aaVx differ
Index: src/org/netbeans/spi/palette/PaletteItemTest.java
===================================================================
RCS file: src/org/netbeans/spi/palette/PaletteItemTest.java
diff -N src/org/netbeans/spi/palette/PaletteItemTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/netbeans/spi/palette/PaletteItemTest.java 12 Aug 2005 09:49:04 -0000 1.1.2.1
@@ -0,0 +1,207 @@
+/*
+ * PaletteItemTest.java
+ * JUnit based test
+ *
+ * Created on August 10, 2005, 3:33 PM
+ */
+
+package org.netbeans.spi.palette;
+import java.beans.BeanInfo;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import org.netbeans.junit.NbTestCase;
+import org.netbeans.modules.palette.Category;
+import org.netbeans.modules.palette.Item;
+import org.openide.filesystems.FileLock;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.Repository;
+import org.openide.loaders.DataObject;
+import org.openide.nodes.Node;
+import org.openide.text.ActiveEditorDrop;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle;
+import org.openide.util.Utilities;
+
+/**
+ *
+ * @author Libor Kotouc
+ */
+public class PaletteItemTest extends NbTestCase {
+
+ private static final String PALETTE_ROOT = "FooPalette";
+ private static final String ITEMS_FOLDER = PALETTE_ROOT + "/FooCategory";
+ private static final String ITEM_FILE = "FooItem.xml";
+ private static final String CLASS_NAME = "org.netbeans.spi.palette.FooItem";
+ private static final String BODY = "";
+ private static final String ICON16 = "org/netbeans/spi/palette/FooItem16.gif";
+ private static final String ICON32 = "org/netbeans/spi/palette/FooItem32.gif";
+ private static final String BUNDLE_NAME = "org.netbeans.spi.palette.Bundle";
+ private static final String NAME_KEY = "NAME_foo-FooItem";
+ private static final String TOOLTIP_KEY = "HINT_foo-FooItem";
+
+
+ private FileObject itemsFolder;
+ private FileObject itemFile;
+
+ private Lookup selectedNode;
+
+ public PaletteItemTest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ itemsFolder = createItemsFolder();
+ assertNotNull(itemsFolder);
+ }
+
+ protected void tearDown() throws Exception {
+ FileObject[] ch = itemsFolder.getChildren();
+ for (int i = 0; i < ch.length; i++)
+ ch[i].delete();
+ FileObject paletteRoot = itemsFolder.getParent();
+ itemsFolder.delete();
+ paletteRoot.delete();
+ }
+
+ public void testReadItemWithActiveEditorDrop() throws Exception {
+ itemFile = createItemFileWithActiveEditorDrop();
+ assertNotNull(itemFile);
+
+ Node itemNode = DataObject.find(itemFile).getNodeDelegate();
+
+ assertEquals("Item loaded with a wrong display name.", NbBundle.getBundle(BUNDLE_NAME).getString(NAME_KEY), itemNode.getDisplayName());
+ assertEquals("Item loaded with a wrong description.", NbBundle.getBundle(BUNDLE_NAME).getString(TOOLTIP_KEY), itemNode.getShortDescription());
+ assertNotNull("Item loaded with no small icon.", itemNode.getIcon(BeanInfo.ICON_COLOR_16x16));
+ assertNotNull("Item loaded with no big icon.", itemNode.getIcon(BeanInfo.ICON_COLOR_32x32));
+
+ Object o = itemNode.getLookup().lookup(ActiveEditorDrop.class);
+ assertNotNull("Item does not contain ActiveEditorDrop implementation in its lookup.", o);
+ }
+
+ public void testReadItemWithBody() throws Exception {
+ itemFile = createItemFileWithBody();
+ assertNotNull(itemFile);
+
+ Node itemNode = DataObject.find(itemFile).getNodeDelegate();
+
+ assertEquals("Item loaded with a wrong display name.", NbBundle.getBundle(BUNDLE_NAME).getString(NAME_KEY), itemNode.getDisplayName());
+ assertEquals("Item loaded with a wrong description.", NbBundle.getBundle(BUNDLE_NAME).getString(TOOLTIP_KEY), itemNode.getShortDescription());
+ assertNotNull("Item loaded with no small icon.", itemNode.getIcon(BeanInfo.ICON_COLOR_16x16));
+ assertNotNull("Item loaded with no big icon.", itemNode.getIcon(BeanInfo.ICON_COLOR_32x32));
+
+ Object o = itemNode.getLookup().lookup(String.class);
+ assertNotNull("Item does not contain body string in its lookup.", o);
+ assertEquals("Item loaded with a wrong body string.", BODY, o);
+ }
+
+ public void testFindItem() throws Exception {
+ itemFile = createItemFileWithActiveEditorDrop();
+ assertNotNull(itemFile);
+
+ //create palette
+ PaletteController pc = PaletteFactory.createPalette(PALETTE_ROOT, new DummyActions());
+
+ //find node with ActiveEditorDrop impl in its lookup
+ Node root = (Node)pc.getRoot().lookup(Node.class);
+ Node[] cats = root.getChildren().getNodes(true);
+ Node foundNode = null;
+ Node foundCat = null;
+ assertEquals("Too many categories", 1, cats.length);
+ Node[] items = cats[0].getChildren().getNodes(true);
+ assertEquals("Too many items", 1, items.length);
+
+ assertTrue("Item not found.",
+ DataObject.find(itemFile).getNodeDelegate().getLookup().lookup(ActiveEditorDrop.class) ==
+ items[0].getLookup().lookup(ActiveEditorDrop.class)
+ );
+
+ }
+
+ public void testSelectItem() throws Exception {
+ itemFile = createItemFileWithActiveEditorDrop();
+ assertNotNull(itemFile);
+
+ //create palette
+ PaletteController pc = PaletteFactory.createPalette(PALETTE_ROOT, new DummyActions());
+ pc.addPropertyChangeListener(new PaletteListener(pc));
+
+ //simulate node selection
+ Category modelCat = pc.getModel().getCategories()[0];
+ Item modelItem = modelCat.getItems()[0];
+ pc.getModel().setSelectedItem(modelCat.getLookup(), modelItem.getLookup());
+
+ assertNotNull("Selected item does not contain ActiveEditorDrop implementation",
+ selectedNode.lookup(ActiveEditorDrop.class));
+ }
+
+
+ //---------------------------------- helpers ------------------------------------------------------------------
+
+ private class PaletteListener implements PropertyChangeListener {
+ PaletteController pc;
+ PaletteListener(PaletteController pc) { this.pc = pc; }
+ public void propertyChange(PropertyChangeEvent evt) {
+ assertEquals("Property " + PaletteController.PROP_SELECTED_ITEM + " was expected.",
+ PaletteController.PROP_SELECTED_ITEM, evt.getPropertyName());
+
+ selectedNode = pc.getSelectedItem();
+ }
+ };
+
+
+ private FileObject createItemsFolder() throws IOException {
+ FileObject root = Repository.getDefault().getDefaultFileSystem().getRoot();
+ FileObject fooCategory = FileUtil.createFolder(root, ITEMS_FOLDER);
+ return fooCategory;
+ }
+
+ private FileObject createItemFileWithActiveEditorDrop() throws Exception {
+ FileObject fo = itemsFolder.createData(ITEM_FILE);
+ FileLock lock = fo.lock();
+ try {
+ OutputStreamWriter writer = new OutputStreamWriter(fo.getOutputStream(lock), "UTF-8");
+ try {
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ } finally {
+ writer.close();
+ }
+ } finally {
+ lock.releaseLock();
+ }
+ return fo;
+ }
+
+ private FileObject createItemFileWithBody() throws Exception {
+ FileObject fo = itemsFolder.createData(ITEM_FILE);
+ FileLock lock = fo.lock();
+ try {
+ OutputStreamWriter writer = new OutputStreamWriter(fo.getOutputStream(lock), "UTF-8");
+ try {
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ writer.write("");
+ } finally {
+ writer.close();
+ }
+ } finally {
+ lock.releaseLock();
+ }
+ return fo;
+ }
+
+}
Index: src/org/netbeans/spi/palette/RepositoryImpl.java
===================================================================
RCS file: src/org/netbeans/spi/palette/RepositoryImpl.java
diff -N src/org/netbeans/spi/palette/RepositoryImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/netbeans/spi/palette/RepositoryImpl.java 12 Aug 2005 09:49:04 -0000 1.1.2.1
@@ -0,0 +1,48 @@
+/*
+ * Sun Public License Notice
+ *
+ * The contents of this file are subject to the Sun Public License
+ * Version 1.0 (the "License"). You may not use this file except in
+ * compliance with the License. A copy of the License is available at
+ * http://www.sun.com/
+ *
+ * The Original Code is NetBeans. The Initial Developer of the Original
+ * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+
+package org.netbeans.spi.palette;
+
+import org.openide.filesystems.FileSystem;
+import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.MultiFileSystem;
+import org.openide.filesystems.Repository;
+import org.openide.filesystems.XMLFileSystem;
+import org.xml.sax.SAXException;
+
+/**
+ * Repository whose getDefaultFileSystem() returns a writeable FS containing
+ * the layer of the Database Explorer module. It is put in the default lookup,
+ * thus it is returned by Repository.getDefault().
+ *
+ * @author Libor Kotouc
+ */
+public class RepositoryImpl extends Repository {
+
+ private XMLFileSystem system;
+
+ public RepositoryImpl() {
+ super(createDefFs());
+ }
+
+ private static FileSystem createDefFs() {
+ try
+ {
+ FileSystem writeFs = FileUtil.createMemoryFileSystem();
+ FileSystem layerFs = new XMLFileSystem(RepositoryImpl.class.getClassLoader().getResource("org/netbeans/modules/palette/resources/layer.xml"));
+ return new MultiFileSystem(new FileSystem[] { writeFs, layerFs });
+ } catch (SAXException e) {
+ return null;
+ }
+ }
+}