<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
-source.. = src/main/java/
+source.. = src/main/java/,\
+ src/main/resources
output.. = target/classes/
bin.includes = META-INF/,\
.,\
package org.argeo.eclipse.ui.jcr;
+import java.util.ResourceBundle;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
public class JcrUiPlugin extends AbstractUIPlugin {
+ private final static Log log = LogFactory.getLog(JcrUiPlugin.class);
+
public final static String ID = "org.argeo.eclipse.ui.jcr";
+ private ResourceBundle messages;
+
private static JcrUiPlugin plugin;
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ messages = ResourceBundle.getBundle("org.argeo.eclipse.ui.jcr");
}
public static JcrUiPlugin getDefault() {
return imageDescriptorFromPlugin(ID, path);
}
+ /** Returns the internationalized label for the given key */
+ public static String getMessage(String key) {
+ try {
+ return getDefault().messages.getString(key);
+ } catch (NullPointerException npe) {
+ log.warn(key + " not found.");
+ return key;
+ }
+ }
+
+ /**
+ * Gives access to the internationalization message bundle. Returns null in
+ * case the ClientUiPlugin is not started (for JUnit tests, by instance)
+ */
+ public static ResourceBundle getMessagesBundle() {
+ if (getDefault() != null)
+ // To avoid NPE
+ return getDefault().messages;
+ else
+ return null;
+ }
}
import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.dialogs.SingleValue;
+import org.argeo.eclipse.ui.jcr.JcrUiPlugin;
import org.argeo.eclipse.ui.jcr.views.AbstractJcrBrowser;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
if (selection != null && !selection.isEmpty()
&& selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
+
if (obj instanceof Node) {
String folderName = SingleValue.ask("Folder name",
"Enter folder name");
}
}
} else {
- ErrorFeedback.show("Can only add file folder to a node");
+ ErrorFeedback.show(JcrUiPlugin
+ .getMessage("errorUnvalidNtFolderNodeType"));
}
}
return null;
--- /dev/null
+## English labels for Agreo base JCR UI application
+
+## Generic labels
+
+## Errors
+errorUnvalidNtFolderNodeType= Error: folder can only be created on a Jcr Node
+
public synchronized void addChild(Object child) {
loaded = true;
children.add(child);
- if (child instanceof TreeParent)
- ((TreeParent) child).setParent(this);
+ // bsinou: was 'if (child instanceof TreeParent)'
+ if (child instanceof TreeObject)
+ ((TreeObject) child).setParent(this);
}
public synchronized void removeChild(Object child) {
children.remove(child);
if (child instanceof TreeParent)
((TreeParent) child).setParent(null);
+ // TODO: clear subtree recursively
}
public synchronized void clearChildren() {
loaded = false;
children.clear();
+ // TODO: clear also the objects
}
public synchronized Object[] getChildren() {
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con"
+ path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6" />
+ <classpathentry kind="con"
+ path="org.eclipse.pde.core.requiredPlugins" />
+ <classpathentry kind="src" path="src/main/java" />
+ <classpathentry kind="output" path="target/classes" />
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.argeo.sandbox.ui.rap</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+#Mon Jun 20 10:19:50 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
--- /dev/null
+Manifest-Version: 1.0\r
+Bundle-ManifestVersion: 2\r
+Bundle-Name: Rap sandbox\r
+Bundle-SymbolicName: org.argeo.sandbox.ui.rap;singleton:=true\r
+Bundle-Version: 0.3.3.SNAPSHOT\r
+Bundle-Activator: org.argeo.sandbox.ui.rap.Activator\r
+Bundle-Vendor: Argeo\r
+Require-Bundle: org.eclipse.rap.ui\r
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6\r
+Bundle-ActivationPolicy: lazy\r
+Import-Package: javax.servlet;version="2.4.0",\r
+ javax.servlet.http;version="2.4.0",\r
+ org.eclipse.equinox.http.servlet;version="1.1.0"\r
+\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+</beans>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+
+ <bean id="urlMapping"
+ class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
+ <property name="mappings">
+ <props>
+ <prop key="*">osgiServiceController</prop>
+ </props>
+ </property>
+ </bean>
+
+ <bean id="osgiServiceController"
+ class="org.springframework.web.servlet.mvc.ServletWrappingController">
+ <property name="servletClass">
+ <value>org.eclipse.equinox.http.servlet.HttpServiceServlet</value>
+ </property>
+ <property name="servletName">
+ <value>osgiService</value>
+ </property>
+ </bean>
+</beans>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ version="2.5">
+
+ <display-name>Argeo OSGi TEST Webapp</display-name>
+
+ <!-- General -->
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>/WEB-INF/applicationContext.xml</param-value>
+ </context-param>
+
+ <listener>
+ <display-name>Spring Context</display-name>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+ <context-param>
+ <param-name>contextClass</param-name>
+ <param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
+ </context-param>
+
+ <!-- OSGi Http Service -->
+ <servlet>
+ <servlet-name>service</servlet-name>
+ <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+ <init-param>
+ <param-name>contextClass</param-name>
+ <param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>service</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
--- /dev/null
+source.. = src/main/java/
+output.. = target/classes/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ WEB-INF/,\
+ .
--- /dev/null
+log4j.rootLogger=WARN, console
+
+## Levels
+log4j.logger.org.argeo.sandbox.ui=TRACE
+
+# Apache Tomcat
+log4j.logger.org.apache.catalina=DEBUG
+log4j.logger.org.apache.coyote=INFO
+log4j.logger.org.apache.tomcat=INFO
+
+## Appenders
+# console is set to be a ConsoleAppender.
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+
+# console uses PatternLayout.
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern= %-5p %d{ISO8601} %m - [%t] %c%n
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+
+ <!-- Enable RAP workbench and provide an entry point -->
+ <extension
+ point="org.eclipse.rap.ui.entrypoint">
+ <entrypoint
+ class="org.argeo.sandbox.ui.rap.Application"
+ parameter="hello"
+ id="org.argeo.sandbox.ui.rap.Application">
+ </entrypoint>
+ </extension>
+ <extension
+ id="basicWebapp"
+ name="Argeo basic Web App"
+ point="org.eclipse.core.runtime.applications">
+ <application cardinality="singleton-global"
+ thread="main"
+ visible="true">
+ <run
+ class="org.argeo.sandbox.ui.rap.Application">
+ </run>
+ </application>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.perspectives">
+ <perspective
+ name="RAP Perspective"
+ class="org.argeo.sandbox.ui.rap.Perspective"
+ id="org.argeo.sandbox.ui.downloadTries">
+ </perspective>
+ </extension>
+ <extension point="org.eclipse.ui.views">
+ <view
+ name="test download view"
+ class="org.argeo.sandbox.ui.rap.views.TestDownloadView"
+ id ="org.argeo.sandbox.ui.testDownloadView">
+ </view>
+ </extension>
+</plugin>
--- /dev/null
+argeo.osgi.start=\
+org.springframework.osgi.extender,\
+com.springsource.javax.servlet,\
+org.eclipse.core.runtime,\
+org.eclipse.equinox.common,\
+org.eclipse.equinox.http.registry,\
+org.eclipse.equinox.launcher,\
+org.eclipse.equinox.http.jetty,\
+org.mortbay.jetty.server,\
+org.springframework.osgi.web.extender,\
+org.argeo.sandbox.ui.rap
+
+
+##org.argeo.eclipse.ui,\
+
+org.argeo.security.ui.initialPerspective=org.argeo.sandbox.ui.downloadTries
+
+eclipse.ignoreApp=true
+osgi.noShutdown=true
+
+log4j.configuration=file:../../log4j.properties
+
+#org.eclipse.equinox.http.jetty.log.stderr.threshold=debug
+org.osgi.service.http.port=9090
+# Demo test URL used with tomcat : http://localhost:9090/org.argeo.sandbox.ui/rap?startup=hello
--- /dev/null
+argeo.osgi.start=\
+org.springframework.osgi.extender,\
+com.springsource.javax.servlet,\
+org.eclipse.core.runtime,\
+org.eclipse.equinox.common,\
+org.eclipse.equinox.http.registry,\
+org.eclipse.equinox.launcher,\
+org.argeo.dep.osgi.catalina.start,\
+org.argeo.server.tomcat,\
+org.springframework.osgi.web.extender,\
+org.argeo.sandbox.ui.rap
+
+
+##org.argeo.eclipse.ui,\
+
+org.argeo.security.ui.initialPerspective=org.argeo.sandbox.ui.downloadTries
+
+eclipse.ignoreApp=true
+osgi.noShutdown=true
+
+log4j.configuration=file:../../log4j.properties
+
+# Demo test URL used with tomcat : http://localhost:7070/org.argeo.rap.webapp/sebi
--- /dev/null
+package org.argeo.sandbox.ui.rap;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.argeo.sandbox.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given plug-in
+ * relative path
+ *
+ * @param path
+ * the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
--- /dev/null
+package org.argeo.sandbox.ui.rap;
+
+import org.eclipse.rwt.lifecycle.IEntryPoint;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.application.WorkbenchAdvisor;
+
+/**
+ * This class controls all aspects of the application's execution
+ * and is contributed through the plugin.xml.
+ */
+public class Application implements IEntryPoint {
+
+ public int createUI() {
+ Display display = PlatformUI.createDisplay();
+ WorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
+ return PlatformUI.createAndRunWorkbench( display, advisor );
+ }
+}
--- /dev/null
+package org.argeo.sandbox.ui.rap;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.application.ActionBarAdvisor;
+import org.eclipse.ui.application.IActionBarConfigurer;
+
+/**
+ * Creates, adds and disposes actions for the menus and action bars of
+ * each workbench window.
+ */
+public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
+
+ public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
+ super(configurer);
+ }
+
+ protected void makeActions(IWorkbenchWindow window) {
+ }
+
+ protected void fillMenuBar(IMenuManager menuBar) {
+ }
+
+}
--- /dev/null
+package org.argeo.sandbox.ui.rap;
+
+import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
+import org.eclipse.ui.application.WorkbenchAdvisor;
+import org.eclipse.ui.application.WorkbenchWindowAdvisor;
+
+/**
+ * This workbench advisor creates the window advisor, and specifies the
+ * perspective id for the initial window.
+ */
+public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
+
+ private static final String PERSPECTIVE_ID = Perspective.ID;
+
+ public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
+ IWorkbenchWindowConfigurer configurer) {
+ return new ApplicationWorkbenchWindowAdvisor(configurer);
+ }
+
+ public String getInitialWindowPerspectiveId() {
+ return PERSPECTIVE_ID;
+ }
+}
--- /dev/null
+package org.argeo.sandbox.ui.rap;
+
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.application.ActionBarAdvisor;
+import org.eclipse.ui.application.IActionBarConfigurer;
+import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
+import org.eclipse.ui.application.WorkbenchWindowAdvisor;
+
+/**
+ * Configures the initial size and appearance of a workbench window.
+ */
+public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
+
+ public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
+ super(configurer);
+ }
+
+ public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer) {
+ return new ApplicationActionBarAdvisor(configurer);
+ }
+
+ public void preWindowOpen() {
+ IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
+ configurer.setInitialSize(new Point(400, 300));
+ configurer.setShowCoolBar(false);
+ configurer.setShowStatusLine(false);
+ configurer.setTitle("Hello RAP");
+ }
+}
--- /dev/null
+package org.argeo.sandbox.ui.rap;
+
+import org.argeo.sandbox.ui.rap.views.TestDownloadView;
+import org.eclipse.ui.IFolderLayout;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+/**
+ * Configures the perspective layout. This class is contributed through the
+ * plugin.xml.
+ */
+public class Perspective implements IPerspectiveFactory {
+
+ public final static String ID = "org.argeo.sandbox.ui.downloadTries";
+
+ public void createInitialLayout(IPageLayout layout) {
+ String editorArea = layout.getEditorArea();
+ layout.setEditorAreaVisible(true);
+ layout.setFixed(false);
+
+ // Create the main ui layout
+ IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT,
+ 0.4f, editorArea);
+
+ // add the views to the corresponding place holder
+ left.addView(TestDownloadView.ID);
+ }
+}
--- /dev/null
+package org.argeo.sandbox.ui.rap.views;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.part.ViewPart;
+
+public class TestDownloadView extends ViewPart {
+ public final static String ID = "org.argeo.sandbox.ui.testDownloadView";
+
+ @Override
+ public void createPartControl(Composite parent) {
+ Label label = new Label(parent, SWT.None);
+ label.setText("Test dowload");
+ }
+
+ @Override
+ public void setFocus() {
+ // TODO Auto-generated method stub
+ }
+
+}
class="org.argeo.jcr.ui.explorer.commands.OpenGenericNodeEditor"
scope="prototype">
</bean>
+ <bean id="getNodeSize" class="org.argeo.jcr.ui.explorer.commands.GetNodeSize"
+ scope="prototype">
+ </bean>
+
- <bean id="addRemoteRepository"
- class="org.argeo.jcr.ui.explorer.commands.AddRemoteRepository">
- <property name="repositoryFactory" ref="repositoryFactory"/>
- <property name="bundleContext" ref="bundleContext"/>
+ <bean id="addRemoteRepository" class="org.argeo.jcr.ui.explorer.commands.AddRemoteRepository">
+ <property name="repositoryFactory" ref="repositoryFactory" />
+ <property name="bundleContext" ref="bundleContext" />
</bean>
- <bean id="addFileFolder" class="org.argeo.eclipse.ui.jcr.commands.AddFileFolder"
+ <bean id="addFolderNode" class="org.argeo.jcr.ui.explorer.commands.AddFolderNode"
scope="prototype" />
<bean id="refresh" class="org.argeo.eclipse.ui.jcr.commands.Refresh"
scope="prototype" />
- <bean id="deleteNode" class="org.argeo.eclipse.ui.jcr.commands.DeleteNode"
+ <bean id="deleteNodes" class="org.argeo.jcr.ui.explorer.commands.DeleteNodes"
scope="prototype" />
<bean id="importFileSystem" class="org.argeo.jcr.ui.explorer.commands.ImportFileSystem"
name="Node path">
</commandParameter>
</command>
+ <command
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ id="org.argeo.jcr.ui.explorer.getNodeSize"
+ name="Get node size">
+ <commandParameter
+ id="org.argeo.jcr.ui.explorer.nodePath"
+ name="Node path">
+ </commandParameter>
+ </command>
+
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
id="org.argeo.jcr.ui.explorer.addRemoteRepository"
</command>
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
- id="org.argeo.jcr.ui.explorer.addFileFolder"
- name="Add file folder...">
+ id="org.argeo.jcr.ui.explorer.addFolderNode"
+ name="Create folder">
</command>
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
</command>
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
- id="org.argeo.jcr.ui.explorer.deleteNode"
- name="Delete node">
+ id="org.argeo.jcr.ui.explorer.deleteNodes"
+ name="Delete nodes">
</command>
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
locationURI="menu:org.argeo.jcr.ui.explorer.browserView">
<command
commandId="org.argeo.jcr.ui.explorer.addRemoteRepository"
- icon="icons/add.gif"
+ icon="icons/addRepo.gif"
style="push">
</command>
</menuContribution>
style="push">
</command>
<command
- commandId="org.argeo.jcr.ui.explorer.addFileFolder"
- icon="icons/add.gif"
+ commandId="org.argeo.jcr.ui.explorer.addFolderNode"
+ icon="icons/addFolder.gif"
style="push">
</command>
<command
- commandId="org.argeo.jcr.ui.explorer.deleteNode"
+ commandId="org.argeo.jcr.ui.explorer.deleteNodes"
icon="icons/remove.gif"
style="push">
</command>
style="push"
tooltip="Import files from the files sytem to the repository">
</command>
+ <command
+ commandId="org.argeo.jcr.ui.explorer.addRemoteRepository"
+ icon="icons/addRepo.gif"
+ style="push">
+ </command>
+ <command
+ commandId="org.argeo.jcr.ui.explorer.getNodeSize"
+ icon="icons/getSize.gif"
+ style="push">
+ </command>
</menuContribution>
</extension>
<extension
package org.argeo.jcr.ui.explorer.browser;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
-import java.util.Map;
import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import org.argeo.ArgeoException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.ArgeoJcrConstants;
import org.argeo.jcr.JcrUtils;
import org.argeo.jcr.RepositoryRegister;
+import org.argeo.jcr.ui.explorer.model.RepositoriesNode;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
*
*/
public class NodeContentProvider implements ITreeContentProvider {
- private ItemComparator itemComparator = new ItemComparator();
+ private final static Log log = LogFactory.getLog(NodeContentProvider.class);
+ // Business Objects
private RepositoryRegister repositoryRegister;
private Session userSession;
+ // Utils
+ // private ItemComparator itemComparator = new ItemComparator();
+
public NodeContentProvider(Session userSession,
RepositoryRegister repositoryRegister) {
this.userSession = userSession;
if (userSession != null) {
Node userHome = JcrUtils.getUserHome(userSession);
if (userHome != null)
- objs.add(userHome);
+ // TODO : find a way to dynamically get alias for the node
+ objs.add(new SingleJcrNode(null, userHome, userSession
+ .getUserID(), ArgeoJcrConstants.ALIAS_NODE));
}
if (repositoryRegister != null)
- objs.add(repositoryRegister);
+ objs.add(new RepositoriesNode("Repositories", repositoryRegister,
+ null));
return objs.toArray();
}
public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof Node) {
- return childrenNodes((Node) parentElement);
- } else if (parentElement instanceof RepositoryNode) {
- return ((RepositoryNode) parentElement).getChildren();
- } else if (parentElement instanceof WorkspaceNode) {
- Session session = ((WorkspaceNode) parentElement).getSession();
- if (session == null)
- return new Object[0];
-
- try {
- return childrenNodes(session.getRootNode());
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot retrieve root node of "
- + session, e);
- }
- } else if (parentElement instanceof RepositoryRegister) {
- RepositoryRegister repositoryRegister = (RepositoryRegister) parentElement;
- List<RepositoryNode> nodes = new ArrayList<RepositoryNode>();
- Map<String, Repository> repositories = repositoryRegister
- .getRepositories();
- for (String name : repositories.keySet()) {
- nodes.add(new RepositoryNode(name, repositories.get(name)));
- }
- return nodes.toArray();
- } else {
+ // if (parentElement instanceof Node) {
+ // return childrenNodes((Node) parentElement);
+ // } else if (parentElement instanceof RepositoryNode) {
+ // return ((RepositoryNode) parentElement).getChildren();
+ // } else if (parentElement instanceof WorkspaceNode) {
+ // Session session = ((WorkspaceNode) parentElement).getSession();
+ // if (session == null)
+ // return new Object[0];
+ //
+ // try {
+ // return childrenNodes(session.getRootNode());
+ // } catch (RepositoryException e) {
+ // throw new ArgeoException("Cannot retrieve root node of "
+ // + session, e);
+ // }
+ // } else if (parentElement instanceof RepositoryRegister) {
+ // RepositoryRegister repositoryRegister = (RepositoryRegister)
+ // parentElement;
+ // List<RepositoryNode> nodes = new ArrayList<RepositoryNode>();
+ // Map<String, Repository> repositories = repositoryRegister
+ // .getRepositories();
+ // for (String name : repositories.keySet()) {
+ // nodes.add(new RepositoryNode(name, repositories.get(name)));
+ // }
+ // return nodes.toArray();
+
+ if (parentElement instanceof TreeParent)
+ return ((TreeParent) parentElement).getChildren();
+ else {
return new Object[0];
}
}
public Object getParent(Object element) {
- try {
- if (element instanceof Node) {
- Node node = (Node) element;
- if (!node.getPath().equals("/"))
- return node.getParent();
- else
- return null;
- }
- return null;
- } catch (RepositoryException e) {
+ if (element instanceof TreeParent) {
+ return ((TreeParent) element).getParent();
+ } else
return null;
- }
}
public boolean hasChildren(Object element) {
- try {
- if (element instanceof Node) {
- return ((Node) element).hasNodes();
- } else if (element instanceof RepositoryNode) {
- return ((RepositoryNode) element).hasChildren();
- } else if (element instanceof WorkspaceNode) {
- return ((WorkspaceNode) element).getSession() != null;
- } else if (element instanceof RepositoryRegister) {
- return ((RepositoryRegister) element).getRepositories().size() > 0;
- }
- return false;
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot check children of " + element, e);
+ if (element instanceof RepositoriesNode) {
+ RepositoryRegister rr = ((RepositoriesNode) element)
+ .getRepositoryRegister();
+ return rr.getRepositories().size() > 0;
+ } else if (element instanceof TreeParent) {
+ TreeParent tp = (TreeParent) element;
+ return tp.hasChildren();
+ // } else if (element instanceof RepositoryNode) {
+ // return ((RepositoryNode) element).hasChildren();
+ // } else if (element instanceof WorkspaceNode) {
+ // return ((WorkspaceNode) element).getSession() != null;
}
+ return false;
+ // } catch (RepositoryException e) {
+ // throw new ArgeoException("Cannot check children of " + element, e);
+ // }
}
public void dispose() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
- protected Object[] childrenNodes(Node parentNode) {
- try {
- List<Node> children = new ArrayList<Node>();
- NodeIterator nit = parentNode.getNodes();
- while (nit.hasNext()) {
- Node node = nit.nextNode();
- children.add(node);
- }
- Node[] arr = children.toArray(new Node[children.size()]);
- Arrays.sort(arr, itemComparator);
- return arr;
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot list children of " + parentNode, e);
- }
- }
+ // protected Object[] childrenNodes(Node parentNode) {
+ // try {
+ // List<Node> children = new ArrayList<Node>();
+ // NodeIterator nit = parentNode.getNodes();
+ // while (nit.hasNext()) {
+ // Node node = nit.nextNode();
+ // children.add(node);
+ // }
+ // Node[] arr = children.toArray(new Node[children.size()]);
+ // Arrays.sort(arr, itemComparator);
+ // return arr;
+ // } catch (RepositoryException e) {
+ // throw new ArgeoException("Cannot list children of " + parentNode, e);
+ // }
+ // }
}
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
+import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.jcr.DefaultNodeLabelProvider;
import org.argeo.eclipse.ui.jcr.JcrUiPlugin;
-import org.argeo.jcr.RepositoryRegister;
+import org.argeo.jcr.ui.explorer.model.RepositoriesNode;
+import org.argeo.jcr.ui.explorer.model.RepositoryNode;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
+import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
import org.eclipse.swt.graphics.Image;
public class NodeLabelProvider extends DefaultNodeLabelProvider {
"icons/repositories.gif").createImage();
public String getText(Object element) {
- if (element instanceof RepositoryRegister) {
- return "Repositories";
+ try {
+ if (element instanceof SingleJcrNode) {
+ SingleJcrNode sjn = (SingleJcrNode) element;
+ return getText(sjn.getNode());
+ } else
+ return super.getText(element);
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected JCR error while getting node name.");
}
- return super.getText(element);
}
protected String getText(Node node) throws RepositoryException {
return WorkspaceNode.WORKSPACE_DISCONNECTED;
else
return WorkspaceNode.WORKSPACE_CONNECTED;
- } else if (element instanceof RepositoryRegister) {
+ } else if (element instanceof RepositoriesNode) {
return REPOSITORIES;
- }
+ } else if (element instanceof SingleJcrNode)
+ try {
+ return super.getImage(((SingleJcrNode) element).getNode());
+ } catch (RepositoryException e) {
+ return null;
+ }
return super.getImage(element);
}
+++ /dev/null
-package org.argeo.jcr.ui.explorer.browser;
-
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.eclipse.ui.jcr.JcrUiPlugin;
-import org.eclipse.swt.graphics.Image;
-
-public class RepositoryNode extends TreeParent {
- private final String name;
- private final Repository repository;
- private Session defaultSession = null;
- public final static Image REPOSITORY_DISCONNECTED = JcrUiPlugin
- .getImageDescriptor("icons/repository_disconnected.gif")
- .createImage();
- public final static Image REPOSITORY_CONNECTED = JcrUiPlugin
- .getImageDescriptor("icons/repository_connected.gif").createImage();
-
- public RepositoryNode(String name, Repository repository) {
- super(name);
- this.name = name;
- this.repository = repository;
- }
-
- public void login() {
- try {
-// SimpleCredentials sc = new SimpleCredentials("root",
-// "demo".toCharArray());
-// defaultSession = repository.login(sc);
- defaultSession = repository.login();
- String[] wkpNames = defaultSession.getWorkspace()
- .getAccessibleWorkspaceNames();
- for (String wkpName : wkpNames) {
- if (wkpName.equals(defaultSession.getWorkspace().getName()))
- addChild(new WorkspaceNode(repository, wkpName,
- defaultSession));
- else
- addChild(new WorkspaceNode(repository, wkpName));
- }
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot connect to repository " + name, e);
- }
- }
-
- public Session getDefaultSession() {
- return defaultSession;
- }
-
-}
+++ /dev/null
-package org.argeo.jcr.ui.explorer.browser;
-
-import javax.jcr.Node;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Workspace;
-import javax.jcr.observation.EventIterator;
-import javax.jcr.observation.EventListener;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.eclipse.ui.jcr.JcrUiPlugin;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Wraps a JCR {@link Workspace}, or more precisely a {@link Session} to it.
- * Implicitly also the root node of this session.
- */
-public class WorkspaceNode extends TreeParent implements EventListener {
- private final String name;
- private final Repository repository;
- private Session session = null;
- public final static Image WORKSPACE_DISCONNECTED = JcrUiPlugin
- .getImageDescriptor("icons/workspace_disconnected.png")
- .createImage();
- public final static Image WORKSPACE_CONNECTED = JcrUiPlugin
- .getImageDescriptor("icons/workspace_connected.png").createImage();
-
- public WorkspaceNode(Repository repository, String name) {
- this(repository, name, null);
- }
-
- public WorkspaceNode(Repository repository, String name, Session session) {
- super(name);
- this.name = name;
- this.repository = repository;
- this.session = session;
- if (session != null)
- processNewSession(session);
- }
-
- public Session getSession() {
- return session;
- }
-
- public Node getRootNode() {
- try {
- if (session != null)
- return session.getRootNode();
- else
- return null;
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot get root node of workspace "
- + name, e);
- }
- }
-
- public void login() {
- try {
- logout();
- session = repository.login(name);
- processNewSession(session);
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot connect to repository " + name, e);
- }
- }
-
- public void logout() {
- try {
- if (session != null && session.isLive()) {
- session.getWorkspace().getObservationManager()
- .removeEventListener(this);
- session.logout();
- }
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot connect to repository " + name, e);
- }
- }
-
- public void onEvent(final EventIterator events) {
- // if (session == null)
- // return;
- // Display.getDefault().syncExec(new Runnable() {
- // public void run() {
- // while (events.hasNext()) {
- // Event event = events.nextEvent();
- // try {
- // String path = event.getPath();
- // String parentPath = path.substring(0,
- // path.lastIndexOf('/'));
- // final Object parent;
- // if (parentPath.equals("/") || parentPath.equals(""))
- // parent = this;
- // else if (session.itemExists(parentPath)){
- // parent = session.getItem(parentPath);
- // ((Item)parent).refresh(false);
- // }
- // else
- // parent = null;
- // if (parent != null) {
- // nodesViewer.refresh(parent);
- // }
- //
- // } catch (RepositoryException e) {
- // log.warn("Error processing event " + event, e);
- // }
- // }
- // }
- // });
- }
-
- protected void processNewSession(Session session) {
- // try {
- // ObservationManager observationManager = session.getWorkspace()
- // .getObservationManager();
- // observationManager.addEventListener(this, Event.NODE_ADDED
- // | Event.NODE_REMOVED, "/", true, null, null, false);
- // } catch (RepositoryException e) {
- // throw new ArgeoException("Cannot process new session "
- // + session, e);
- // }
- }
-
-}
--- /dev/null
+package org.argeo.jcr.ui.explorer.commands;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+
+import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.eclipse.ui.dialogs.SingleValue;
+import org.argeo.eclipse.ui.jcr.JcrUiPlugin;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
+import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/** Adds a node of type nt:folder */
+public class AddFolderNode extends AbstractHandler {
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
+ .getActivePage().getSelection();
+ GenericJcrBrowser view = (GenericJcrBrowser) HandlerUtil
+ .getActiveWorkbenchWindow(event).getActivePage()
+ .findView(HandlerUtil.getActivePartId(event));
+ if (selection != null && !selection.isEmpty()
+ && selection instanceof IStructuredSelection) {
+ Object obj = ((IStructuredSelection) selection).getFirstElement();
+
+ if (obj instanceof SingleJcrNode) {
+ String folderName = SingleValue.ask("Folder name",
+ "Enter folder name");
+ if (folderName != null) {
+ SingleJcrNode sjn = (SingleJcrNode) obj;
+ Node parentNode = sjn.getNode();
+ try {
+ Node newNode = parentNode.addNode(folderName,
+ NodeType.NT_FOLDER);
+ parentNode.getSession().save();
+ view.nodeAdded(sjn);
+ } catch (RepositoryException e) {
+ ErrorFeedback.show("Cannot create folder " + folderName
+ + " under " + parentNode, e);
+ }
+ }
+ } else {
+ ErrorFeedback.show(JcrUiPlugin
+ .getMessage("errorUnvalidNtFolderNodeType"));
+ }
+ }
+ return null;
+ }
+
+}
--- /dev/null
+package org.argeo.jcr.ui.explorer.commands;
+
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
+import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Deletes the selected nodes: both in the JCR repository and in the UI view.
+ * Warning no check is done, except implementation dependent native checks,
+ * handle with care.
+ */
+public class DeleteNodes extends AbstractHandler {
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
+ .getActivePage().getSelection();
+ GenericJcrBrowser view = (GenericJcrBrowser) HandlerUtil
+ .getActiveWorkbenchWindow(event).getActivePage()
+ .findView(HandlerUtil.getActivePartId(event));
+
+ if (selection != null && selection instanceof IStructuredSelection) {
+ Iterator<?> it = ((IStructuredSelection) selection).iterator();
+ Object obj = null;
+ SingleJcrNode ancestor = null;
+ WorkspaceNode rootAncestor = null;
+ try {
+ while (it.hasNext()) {
+ obj = it.next();
+ if (obj instanceof SingleJcrNode) {
+ // Cache objects
+ SingleJcrNode sjn = (SingleJcrNode) obj;
+ TreeParent tp = (TreeParent) sjn.getParent();
+ Node node = sjn.getNode();
+
+ // Jcr Remove
+ node.remove();
+ node.getSession().save();
+ // UI remove
+ tp.removeChild(sjn);
+
+ // Check if the parent is the root node
+ if (tp instanceof WorkspaceNode)
+ rootAncestor = (WorkspaceNode) tp;
+ else
+ ancestor = getOlder(ancestor, (SingleJcrNode) tp);
+ }
+ }
+ if (rootAncestor != null)
+ view.nodeRemoved(rootAncestor);
+ else if (ancestor != null)
+ view.nodeRemoved(ancestor);
+ } catch (Exception e) {
+ ErrorFeedback.show("Cannot delete selected node ", e);
+ }
+ }
+ return null;
+ }
+
+ private SingleJcrNode getOlder(SingleJcrNode A, SingleJcrNode B) {
+ try {
+ if (A == null)
+ return B == null ? null : B;
+ // Todo enhanced this method
+ else
+ return A.getNode().getDepth() <= B.getNode().getDepth() ? A : B;
+ } catch (RepositoryException re) {
+ throw new ArgeoException("Cannot find ancestor", re);
+ }
+ }
+}
--- /dev/null
+package org.argeo.jcr.ui.explorer.commands;
+
+import javax.jcr.Node;
+
+import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
+import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/** Opens the generic node editor. */
+public class GetNodeSize extends AbstractHandler {
+ // private final static Log log = LogFactory.getLog(GetNodeSize.class);
+
+ public final static String ID = "org.argeo.jcr.ui.explorer.getNodeSize";
+ public final static String DEFAULT_ICON_REL_PATH = "icons/getSize.gif";
+ public final static String DEFAULT_LABEL = JcrExplorerPlugin
+ .getMessage("getNodeSizeCmdLbl");
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ // JcrUtils.getRepositoryByAlias(repositoryRegister,
+ // ArgeoJcrConstants.ALIAS_NODE);
+
+ ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
+ .getActivePage().getSelection();
+ GenericJcrBrowser view = (GenericJcrBrowser) HandlerUtil
+ .getActiveWorkbenchWindow(event).getActivePage()
+ .findView(HandlerUtil.getActivePartId(event));
+
+ if (selection != null && !selection.isEmpty()
+ && selection instanceof IStructuredSelection) {
+
+ // We only get
+ IStructuredSelection iss = (IStructuredSelection) selection;
+ if (iss.size() > 1)
+ ErrorFeedback.show(JcrExplorerPlugin
+ .getMessage("warningInvalidMultipleSelection"), null);
+
+ long size = 0;
+ Node node;
+ if (iss.getFirstElement() instanceof SingleJcrNode)
+ node = ((SingleJcrNode) iss.getFirstElement()).getNode();
+ else if (iss.getFirstElement() instanceof WorkspaceNode)
+ node = ((WorkspaceNode) iss.getFirstElement()).getRootNode();
+ else
+ // unvalid object type
+ return null;
+
+ size = JcrUtils.getNodeApproxSize(node);
+
+ String[] labels = { "OK" };
+ Shell shell = HandlerUtil.getActiveWorkbenchWindow(event)
+ .getShell();
+ MessageDialog md = new MessageDialog(shell, "Node size", null,
+ "Node size is: " + size / 1024 + " KB",
+ MessageDialog.INFORMATION, labels, 0);
+ md.open();
+ }
+ return null;
+ }
+}
import javax.jcr.Node;
import org.argeo.eclipse.ui.ErrorFeedback;
-import org.argeo.eclipse.ui.jcr.views.AbstractJcrBrowser;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
+import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
import org.argeo.jcr.ui.explorer.wizards.ImportFileSystemWizard;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event)
.getActivePage().getSelection();
- AbstractJcrBrowser view = (AbstractJcrBrowser) HandlerUtil
+ GenericJcrBrowser view = (GenericJcrBrowser) HandlerUtil
.getActiveWorkbenchWindow(event).getActivePage()
.findView(HandlerUtil.getActivePartId(event));
if (selection != null && !selection.isEmpty()
&& selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
try {
- if (obj instanceof Node) {
- Node folder = (Node) obj;
+ Node folder = null;
+ if (obj instanceof SingleJcrNode) {
+ folder = ((SingleJcrNode) obj).getNode();
+ } else if (obj instanceof WorkspaceNode) {
+ folder = ((WorkspaceNode) obj).getRootNode();
+ } else {
+ ErrorFeedback.show(JcrExplorerPlugin
+ .getMessage("warningInvalidNodeToImport"));
+ }
+ if (folder != null) {
ImportFileSystemWizard wizard = new ImportFileSystemWizard(
folder);
WizardDialog dialog = new WizardDialog(
HandlerUtil.getActiveShell(event), wizard);
dialog.open();
- view.refresh(folder);
- } else {
- ErrorFeedback.show("Can only import to a node");
+ view.nodeAdded((TreeParent) obj);
}
} catch (Exception e) {
ErrorFeedback.show("Cannot import files to " + obj, e);
}
return null;
}
-
}
--- /dev/null
+package org.argeo.jcr.ui.explorer.model;
+
+import java.util.Map;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryFactory;
+
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.RepositoryRegister;
+
+/**
+ * UI Tree component. Implements the Argeo abstraction of a
+ * {@link RepositoryFactory} that enable a user to "mount" various repositories
+ * in a single Tree like View. It is usually meant to be at the root of the UI
+ * Tree and thus {@link getParent()} method will return null.
+ *
+ * The {@link RepositoryFactory} is injected at instantiation time and must be
+ * use get or register new {@link Repository} objects upon which a reference is
+ * kept here.
+ */
+
+public class RepositoriesNode extends TreeParent {
+ private final String name;
+ private final RepositoryRegister repositoryRegister;
+
+ public RepositoriesNode(String name, RepositoryRegister repositoryRegister,
+ TreeParent parent) {
+ super(name);
+ this.name = name;
+ this.repositoryRegister = repositoryRegister;
+ }
+
+ /**
+ * Override normal behaviour to initialize the various repositories only at
+ * request time
+ */
+ @Override
+ public synchronized Object[] getChildren() {
+ if (isLoaded()) {
+ return super.getChildren();
+ } else {
+ // initialize current object
+ Map<String, Repository> refRepos = repositoryRegister
+ .getRepositories();
+ for (String name : refRepos.keySet()) {
+ super.addChild(new RepositoryNode(name, refRepos.get(name),
+ this));
+ }
+ return super.getChildren();
+ }
+ }
+
+ public void registerNewRepository(String alias, Repository repository) {
+ // TODO: implement this
+ // Create a new RepositoryNode Object
+ // add it
+ // super.addChild(new RepositoriesNode(...));
+ }
+
+ /** Returns the {@link RepositoryRegister} wrapped by thgis object. */
+ public RepositoryRegister getRepositoryRegister() {
+ return repositoryRegister;
+ }
+
+}
--- /dev/null
+package org.argeo.jcr.ui.explorer.model;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.jcr.JcrUiPlugin;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * UI Tree component. Wraps a JCR {@link Repository}. It also keeps a reference
+ * to its parent Tree Ui component; typically the unique {@link Repositories}
+ * object of the current view to enable bi-directionnal browsing in the tree.
+ */
+
+public class RepositoryNode extends TreeParent implements UiNode {
+ private String alias;
+ private final Repository repository;
+ private Session defaultSession = null;
+ public final static Image REPOSITORY_DISCONNECTED = JcrUiPlugin
+ .getImageDescriptor("icons/repository_disconnected.gif")
+ .createImage();
+ public final static Image REPOSITORY_CONNECTED = JcrUiPlugin
+ .getImageDescriptor("icons/repository_connected.gif").createImage();
+
+ /** Create a new repository with alias = name */
+ public RepositoryNode(String alias, Repository repository, TreeParent parent) {
+ this(alias, alias, repository, parent);
+ }
+
+ /** Create a new repository with distinct name & alias */
+ public RepositoryNode(String alias, String name, Repository repository,
+ TreeParent parent) {
+ super(name);
+ this.repository = repository;
+ setParent(parent);
+ this.alias = alias;
+ }
+
+ public void login() {
+ try {
+ // SimpleCredentials sc = new SimpleCredentials("root",
+ // "demo".toCharArray());
+ // defaultSession = repository.login(sc);
+ defaultSession = repository.login();
+ String[] wkpNames = defaultSession.getWorkspace()
+ .getAccessibleWorkspaceNames();
+ for (String wkpName : wkpNames) {
+ if (wkpName.equals(defaultSession.getWorkspace().getName()))
+ addChild(new WorkspaceNode(this, wkpName, defaultSession));
+ else
+ addChild(new WorkspaceNode(this, wkpName));
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot connect to repository " + alias, e);
+ }
+ }
+
+ public Session getDefaultSession() {
+ return defaultSession;
+ }
+
+ /** returns the {@link Repository} referenced by the current UI Node */
+ public Repository getRepository() {
+ return repository;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
+}
--- /dev/null
+package org.argeo.jcr.ui.explorer.model;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Workspace;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+
+/**
+ * UI Tree component. Wraps a node of a JCR {@link Workspace}. It also keeps a
+ * reference to its parent node that can either be a {@link WorkspaceNode}, a
+ * {@link SingleJcrNode} or null if the node is "mounted" as the root of the UI
+ * tree.
+ */
+
+public class SingleJcrNode extends TreeParent implements UiNode {
+
+ private final Node node;
+ private String alias = null;
+
+ // keeps a local reference to the node's name to avoid exception when the
+ // session is lost
+ // private final String name;
+
+ /** Creates a new UiNode in the UI Tree */
+ public SingleJcrNode(TreeParent parent, Node node, String name) {
+ super(name);
+ setParent(parent);
+ this.node = node;
+ }
+
+ /**
+ * Creates a new UiNode in the UI Tree, keeping a reference to the alias of
+ * the corresponding repository in the current UI environment. It is useful
+ * to be able to mount nodes as roots of the UI tree.
+ */
+ public SingleJcrNode(TreeParent parent, Node node, String name, String alias) {
+ super(name);
+ setParent(parent);
+ this.node = node;
+ this.alias = alias;
+ }
+
+ /** returns the node wrapped by the current Ui object */
+ public Node getNode() {
+ return node;
+ }
+
+ /**
+ * Returns the alias corresponding to the repository abstraction that
+ * contains current node. If the current object is mounted as root of the UI
+ * tree, the alias is stored in the object. Otherwise, we must browse the
+ * tree backward to the RepositoryNode.
+ *
+ * Alias is then cached in the current object so that next time it will be
+ * here.
+ */
+ public String getAlias() {
+ if (alias == null) {
+ alias = ((UiNode) getParent()).getAlias();
+ }
+ return alias;
+ }
+
+ /**
+ * Override normal behaviour to initialize children only when first
+ * requested
+ */
+ @Override
+ public synchronized Object[] getChildren() {
+ if (isLoaded()) {
+ return super.getChildren();
+ } else {
+ // initialize current object
+ try {
+ NodeIterator ni = node.getNodes();
+ while (ni.hasNext()) {
+ Node curNode = ni.nextNode();
+ addChild(new SingleJcrNode(this, curNode, curNode.getName()));
+ }
+ return super.getChildren();
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexcpected error while initializing children SingleJcrNode",
+ re);
+ }
+ }
+ }
+
+ @Override
+ public boolean hasChildren() {
+ try {
+ return node.hasNodes();
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while checking children node existence",
+ re);
+ }
+ }
+
+}
--- /dev/null
+package org.argeo.jcr.ui.explorer.model;
+
+/**
+ * insure presence of the useful specific methods used in the building a UI Tree
+ * based on JCR repositories
+ */
+public interface UiNode {
+
+ public String getAlias();
+}
--- /dev/null
+package org.argeo.jcr.ui.explorer.model;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.jcr.JcrUiPlugin;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * UI Tree component. Wraps the root node of a JCR {@link Workspace}. It also
+ * keeps a reference to its parent {@link RepositoryNode}, to be able to
+ * retrieve alias of the current used repository
+ */
+
+public class WorkspaceNode extends TreeParent implements EventListener, UiNode {
+ private Session session = null;
+
+ public final static Image WORKSPACE_DISCONNECTED = JcrUiPlugin
+ .getImageDescriptor("icons/workspace_disconnected.png")
+ .createImage();
+ public final static Image WORKSPACE_CONNECTED = JcrUiPlugin
+ .getImageDescriptor("icons/workspace_connected.png").createImage();
+
+ public WorkspaceNode(RepositoryNode parent, String name) {
+ this(parent, name, null);
+ }
+
+ public WorkspaceNode(RepositoryNode parent, String name, Session session) {
+ super(name);
+ this.session = session;
+ if (session != null)
+ processNewSession(session);
+ setParent(parent);
+ }
+
+ public Session getSession() {
+ return session;
+ }
+
+ public Node getRootNode() {
+ try {
+ if (session != null)
+ return session.getRootNode();
+ else
+ return null;
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot get root node of workspace "
+ + getName(), e);
+ }
+ }
+
+ public void login() {
+ try {
+ logout();
+ session = ((RepositoryNode) getParent()).getRepository().login(
+ getName());
+ processNewSession(session);
+
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot connect to repository "
+ + getName(), e);
+ }
+ }
+
+ public void logout() {
+ try {
+ if (session != null && session.isLive()) {
+ session.getWorkspace().getObservationManager()
+ .removeEventListener(this);
+ session.logout();
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot connect to repository "
+ + getName(), e);
+ }
+ }
+
+ /** Returns the alias of the parent Repository */
+ public String getAlias() {
+ return ((UiNode) getParent()).getAlias();
+ }
+
+ @Override
+ public boolean hasChildren() {
+ try {
+ if (session == null)
+ return false;
+ else
+ return session.getRootNode().hasNodes();
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while checking children node existence",
+ re);
+ }
+ }
+
+ /** Override normal behaviour to initialize display of the workspace */
+ @Override
+ public synchronized Object[] getChildren() {
+ if (isLoaded()) {
+ return super.getChildren();
+ } else {
+ // initialize current object
+ try {
+ Node rootNode;
+ if (session == null)
+ return null;
+ else
+ rootNode = session.getRootNode();
+ NodeIterator ni = rootNode.getNodes();
+ while (ni.hasNext()) {
+ Node node = ni.nextNode();
+ addChild(new SingleJcrNode(this, node, node.getName()));
+ }
+ return super.getChildren();
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Cannot initialize WorkspaceNode UI object."
+ + getName(), e);
+ }
+ }
+ }
+
+ public void onEvent(final EventIterator events) {
+ // if (session == null)
+ // return;
+ // Display.getDefault().syncExec(new Runnable() {
+ // public void run() {
+ // while (events.hasNext()) {
+ // Event event = events.nextEvent();
+ // try {
+ // String path = event.getPath();
+ // String parentPath = path.substring(0,
+ // path.lastIndexOf('/'));
+ // final Object parent;
+ // if (parentPath.equals("/") || parentPath.equals(""))
+ // parent = this;
+ // else if (session.itemExists(parentPath)){
+ // parent = session.getItem(parentPath);
+ // ((Item)parent).refresh(false);
+ // }
+ // else
+ // parent = null;
+ // if (parent != null) {
+ // nodesViewer.refresh(parent);
+ // }
+ //
+ // } catch (RepositoryException e) {
+ // log.warn("Error processing event " + event, e);
+ // }
+ // }
+ // }
+ // });
+ }
+
+ protected void processNewSession(Session session) {
+ // try {
+ // ObservationManager observationManager = session.getWorkspace()
+ // .getObservationManager();
+ // observationManager.addEventListener(this, Event.NODE_ADDED
+ // | Event.NODE_REMOVED, "/", true, null, null, false);
+ // } catch (RepositoryException e) {
+ // throw new ArgeoException("Cannot process new session "
+ // + session, e);
+ // }
+ }
+
+}
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.specific.FileHandler;
import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
-import org.argeo.jcr.ui.explorer.browser.NodeContentProvider;
-import org.argeo.jcr.ui.explorer.browser.RepositoryNode;
-import org.argeo.jcr.ui.explorer.browser.WorkspaceNode;
import org.argeo.jcr.ui.explorer.editors.GenericNodeEditor;
import org.argeo.jcr.ui.explorer.editors.GenericNodeEditorInput;
+import org.argeo.jcr.ui.explorer.model.RepositoryNode;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
+import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
.getFirstElement();
if (obj instanceof RepositoryNode) {
RepositoryNode rpNode = (RepositoryNode) obj;
- rpNode.login();
- nodeViewer.refresh(obj);
+ if (rpNode.getChildren().length == 0) {
+ rpNode.login();
+ nodeViewer.refresh(obj);
+ }
+ // else do nothing
} else if (obj instanceof WorkspaceNode) {
((WorkspaceNode) obj).login();
nodeViewer.refresh(obj);
- } else if (obj instanceof Node) {
- Node node = (Node) obj;
+ } else if (obj instanceof SingleJcrNode) {
+ SingleJcrNode sjn = (SingleJcrNode) obj;
+ Node node = sjn.getNode();
try {
if (node.isNodeType(NodeType.NT_FILE)) {
// double click on a file node triggers its opening
// TODO : enhanced that.
ITreeContentProvider itcp = (ITreeContentProvider) nodeViewer
.getContentProvider();
- jfp.setRootNodes((Object[]) itcp.getElements(null));
+ // jfp.setRootNodes((Object[]) itcp.getElements(null));
fileHandler.openFile(name, id);
}
GenericNodeEditorInput gnei = new GenericNodeEditorInput(node);
}
}
}
-
- // Enhance this method
- private String getRepositoryAlias(Object element) {
- NodeContentProvider ncp = (NodeContentProvider) nodeViewer
- .getContentProvider();
- Object parent = element;
- while (!(ncp.getParent(parent) instanceof RepositoryNode)
- && parent != null)
- parent = ncp.getParent(parent);
- return parent == null ? null : ((RepositoryNode) parent).getName();
- }
}
package org.argeo.jcr.ui.explorer.utils;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
import javax.jcr.Node;
import javax.jcr.Property;
-import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
import org.apache.commons.io.IOUtils;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.specific.FileProvider;
-import org.argeo.jcr.RepositoryRegister;
-import org.argeo.jcr.ui.explorer.browser.RepositoryNode;
+import org.argeo.jcr.ui.explorer.model.RepositoryNode;
/**
* Implements a FileProvider for UI purposes. Note that it might not be very
*
* @param repositoryNode
*/
- public void setRootNodes(Object[] rootNodes) {
- List<Object> tmpNodes = new ArrayList<Object>();
- for (int i = 0; i < rootNodes.length; i++) {
- Object obj = rootNodes[i];
- if (obj instanceof Node) {
- tmpNodes.add(obj);
- } else if (obj instanceof RepositoryRegister) {
- RepositoryRegister repositoryRegister = (RepositoryRegister) obj;
- Map<String, Repository> repositories = repositoryRegister
- .getRepositories();
- for (String name : repositories.keySet()) {
- tmpNodes.add(new RepositoryNode(name, repositories
- .get(name)));
- }
-
- }
- }
- this.rootNodes = tmpNodes.toArray();
- }
+ // public void setRootNodes(Object[] rootNodes) {
+ // List<Object> tmpNodes = new ArrayList<Object>();
+ // for (int i = 0; i < rootNodes.length; i++) {
+ // Object obj = rootNodes[i];
+ // if (obj instanceof Node) {
+ // tmpNodes.add(obj);
+ // } else if (obj instanceof RepositoryRegister) {
+ // RepositoryRegister repositoryRegister = (RepositoryRegister) obj;
+ // Map<String, Repository> repositories = repositoryRegister
+ // .getRepositories();
+ // for (String name : repositories.keySet()) {
+ // tmpNodes.add(new RepositoryNode(name, repositories
+ // .get(name)));
+ // }
+ //
+ // }
+ // }
+ // this.rootNodes = tmpNodes.toArray();
+ // }
public byte[] getByteArrayFileFromId(String fileId) {
InputStream fis = null;
package org.argeo.jcr.ui.explorer.utils;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
+import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+
/** Centralizes some useful methods to build Uis with JCR */
public class JcrUiUtils {
+ /** Insure that the UI componant is not stale, refresh if needed */
+ public static void forceRefreshIfNeeded(TreeParent element) {
+ Node curNode;
+
+ if (element instanceof SingleJcrNode)
+ curNode = ((SingleJcrNode) element).getNode();
+ else if (element instanceof WorkspaceNode)
+ curNode = ((WorkspaceNode) element).getRootNode();
+ else
+ return;
+ // TODO implement specific methods for other cases
+
+ try {
+ // we mainly rely on nb of children
+ if (element.getChildren().length == curNode.getNodes().getSize())
+ return;
+ else {
+ // get rid of children of UI object
+ element.clearChildren();
+ element.getChildren();
+ }
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while synchronising the UI with the JCR repository",
+ re);
+ }
+ }
+ /**
+ * Workaround to get the alias of the repository that contains the given
+ * element. As we cannot browse the UI tree upward we recursively browse it
+ * downward until we find the given element
+ * */
+ // public static String getRepositoryAliasFromITreeElement(
+ // NodeContentProvider ncp, Object element) {
+ // RepositoryNode repositoryNode = null;
+ // if (element instanceof RepositoryNode)
+ // return ((RepositoryNode) element).getName();
+ // else if (element instanceof RepositoryRegister)
+ // throw new ArgeoException(
+ // "Cannot get alias for a repository register");
+ //
+ // // Get root elements
+ // Object[] elements = ncp.getElements(null);
+ //
+ // try {
+ // for (int i = 0; i < elements.length; i++) {
+ // if (elements[i] instanceof Node) {
+ // Node curNode = (Node) elements[i];
+ // if (curNode.isNodeType(ArgeoTypes.ARGEO_USER_HOME)) {
+ // // Do nothing, we'll find the node in the "normal" tree
+ // // and
+ // // get corresponding alias this way round
+ // } else
+ // throw new ArgeoException(
+ // "Normal nodes should not be at the root of NodeTreeViewer");
+ // } else if (elements[i] instanceof RepositoryRegister) {
+ // RepositoryRegister repositoryRegister = (RepositoryRegister) elements[i];
+ // Map<String, Repository> repositories = repositoryRegister
+ // .getRepositories();
+ //
+ // for (String name : repositories.keySet()) {
+ // boolean found = isElementInCurrentTreePart(
+ // ncp,
+ // new RepositoryNode(name, repositories.get(name)),
+ // (Node) element);
+ // if (found)
+ // return name;
+ // }
+ // } else
+ // throw new ArgeoException(
+ // "Unexpected object class at the root of NodeTreeViewer");
+ // }
+ // } catch (RepositoryException re) {
+ // throw new ArgeoException(
+ // "Unexpected error while retrieving Alias name", re);
+ // }
+ // return null;
+ // }
+ //
+ // /** implements the recursivity */
+ // private static boolean isElementInCurrentTreePart(NodeContentProvider
+ // ncp,
+ // Object parentElement, NodParente searchedElement) {
+ // boolean found = false;
+ // if (parentElement instanceof WorkspaceNode) {
+ // WorkspaceNode wn = (WorkspaceNode) parentElement;
+ // Object[] children = wn.getChildren();
+ // int i = children.length - 1;
+ // while (!found && i >= 0) {
+ // found = isElementInCurrentTreePart(ncp, children[i],
+ // searchedElement);
+ // }
+ // return found;
+ // } else if (parentElement instanceof RepositoryNode) {
+ // RepositoryNode rn = (RepositoryNode) parentElement;
+ // Object[] children = rn.getChildren();
+ // int i = children.length - 1;
+ // while (!found && i >= 0) {
+ // found = isElementInCurrentTreePart(ncp, children[i],
+ // searchedElement);
+ // }
+ // return found;
+ // } else {
+ // Node node = (Node) parentElement;
+ // if (node.equals(searchedElement))
+ // return true;
+ // NodeIterator ni;
+ // try {
+ // ni = node.getNodes();
+ // while (!found && ni.hasNext()) {
+ // found = isElementInCurrentTreePart(ncp, ni.nextNode(),
+ // searchedElement);
+ // }
+ // } catch (RepositoryException e) {
+ // throw new ArgeoException("unexpected erreur while recursively"
+ // + " recovering RepositoryNode for selected object", e);
+ // }
+ //
+ // return found;
+ // }
+ // }
}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
import org.argeo.eclipse.ui.jcr.AsyncUiEventListener;
import org.argeo.eclipse.ui.jcr.utils.NodeViewerComparer;
import org.argeo.eclipse.ui.jcr.views.AbstractJcrBrowser;
import org.argeo.jcr.ui.explorer.browser.NodeContentProvider;
import org.argeo.jcr.ui.explorer.browser.NodeLabelProvider;
import org.argeo.jcr.ui.explorer.browser.PropertiesContentProvider;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
import org.argeo.jcr.ui.explorer.utils.GenericNodeDoubleClickListener;
import org.argeo.jcr.ui.explorer.utils.JcrFileProvider;
+import org.argeo.jcr.ui.explorer.utils.JcrUiUtils;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.TreeViewer;
// nodesViewer.refresh(tmpSel.getFirstElement());
// }
- private JcrFileProvider getJcrFileProvider() {
- return jcrFileProvider;
- }
-
- private FileHandler getFileHandler() {
- return fileHandler;
- }
+ // private JcrFileProvider getJcrFileProvider() {
+ // return jcrFileProvider;
+ // }
+ //
+ // private FileHandler getFileHandler() {
+ // return fileHandler;
+ // }
protected TreeViewer createNodeViewer(Composite parent,
final ITreeContentProvider nodeContentProvider) {
if (!event.getSelection().isEmpty()) {
IStructuredSelection sel = (IStructuredSelection) event
.getSelection();
- propertiesViewer.setInput(sel.getFirstElement());
+ Object firstItem = sel.getFirstElement();
+ if (firstItem instanceof SingleJcrNode)
+ propertiesViewer
+ .setInput(((SingleJcrNode) firstItem)
+ .getNode());
} else {
propertiesViewer.setInput(getViewSite());
}
return nodesViewer;
}
+ /** Notifies the current view that a node has been added */
+ public void nodeAdded(TreeParent parentNode) {
+ // insure that Ui objects have been correctly created:
+ JcrUiUtils.forceRefreshIfNeeded(parentNode);
+ getNodeViewer().refresh(parentNode);
+ getNodeViewer().expandToLevel(parentNode, 1);
+ }
+
+ /** Notifies the current view that a node has been added */
+ public void nodeRemoved(TreeParent parentNode) {
+ IStructuredSelection newSel = new StructuredSelection(parentNode);
+ getNodeViewer().setSelection(newSel, true);
+ // Force refresh
+ IStructuredSelection tmpSel = (IStructuredSelection) getNodeViewer()
+ .getSelection();
+ getNodeViewer().refresh(tmpSel.getFirstElement());
+ }
+
class TreeObserver extends AsyncUiEventListener {
public TreeObserver(Display display) {
## English labels for Agreo JCR UI application
## Generic labels
+
+## Errors & warnings
+errorUnvalidNtFolderNodeType= Error: folder can only be created on a Jcr Node
+warningInvalidNodeToImport=Can only import to a node
+warningInvalidMultipleSelection=This functionality is implemented only on a single node for the time being.
warningUnversionableNode= Warning: Current node is not versionable.
warningNoChildNode= Warning: current node has no children.
+## Commands
+getNodeSizeCmdLbl= Get approx. size
+
## GenericNodeEditor
nodeEditorLbl=Generic node editor
genericNodePageTitle=Properties
}
return sbuf.toString();
}
+
+ /**
+ * Estimate the sub tree size from current node. Computation is based on the
+ * Jcr {@link Property.getLength()} method. Note : it is not the exact size
+ * used on the disk by the current part of the JCR Tree.
+ */
+
+ public static long getNodeApproxSize(Node node) {
+ long curNodeSize = 0;
+ try {
+ PropertyIterator pi = node.getProperties();
+ while (pi.hasNext()) {
+ Property prop = pi.nextProperty();
+ if (prop.isMultiple()) {
+ int nb = prop.getLengths().length;
+ for (int i = 0; i < nb; i++) {
+ curNodeSize += (prop.getLengths()[i] > 0 ? prop
+ .getLengths()[i] : 0);
+ }
+ } else
+ curNodeSize += (prop.getLength() > 0 ? prop.getLength() : 0);
+ }
+
+ NodeIterator ni = node.getNodes();
+ while (ni.hasNext())
+ curNodeSize += getNodeApproxSize(ni.nextNode());
+ return curNodeSize;
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while recursively determining node size.",
+ re);
+ }
+ }
}