<and>
<or>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem">
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem">
</instanceof>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem">
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem">
</instanceof>
</or>
<with variable="activeMenuSelection"><count value="1"/></with>
<and>
<or>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem">
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem">
</instanceof>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem">
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem">
</instanceof>
</or>
<with variable="activeMenuSelection"><count value="1"/></with>
<and>
<or>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoryElem">
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem">
</instanceof>
</or>
<with variable="activeMenuSelection"><count value="1"/></with>
<iterate>
<or>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem" />
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem" />
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem" />
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem" />
</or>
</iterate>
</visibleWhen>
<and>
<or>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem" />
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem" />
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem" />
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem" />
</or>
<with variable="activeMenuSelection"><count value="1"/></with>
</and>
<iterate>
<or>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoriesElem" />
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoriesElem" />
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoryElem" />
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem" />
</or>
</iterate>
</visibleWhen>
<iterate>
<or>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.RemoteRepositoryElem" />
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.RemoteRepositoryElem" />
</or>
</iterate>
</visibleWhen>
<iterate>
<or>
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem" />
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem" />
<instanceof
- value="org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem" />
+ value="org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem" />
</or>
</iterate>
</visibleWhen>
style="push">
<visibleWhen>
<iterate> <and>
- <instanceof value="org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem"></instanceof>
+ <instanceof value="org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem"></instanceof>
<with variable="activeMenuSelection"><count value="1"/></with>
</and> </iterate>
</visibleWhen>
style="push">
<visibleWhen>
<iterate> <and>
- <instanceof value="org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem"></instanceof>
+ <instanceof value="org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem"></instanceof>
<with variable="activeMenuSelection"><count value="1"/></with>
</and> </iterate>
</visibleWhen>
<visibleWhen>
<iterate>
<and>
- <instanceof value="org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem"></instanceof>
+ <instanceof value="org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem"></instanceof>
<with variable="activeMenuSelection"><count value="1"/></with>
</and>
</iterate>
import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
import org.argeo.eclipse.ui.dialogs.SingleValue;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.AddPrivilegeWizard;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.AddPrivilegeWizard;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
import org.argeo.eclipse.ui.dialogs.SingleValue;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoryElem;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.workbench.CommandUtils;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
import org.argeo.jcr.JcrUtils;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import javax.jcr.nodetype.NodeType;
import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.NodeEditorInput;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.NodeEditorInput;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem;
import org.argeo.jcr.JcrUtils;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.ImportFileSystemWizard;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.ImportFileSystemWizard;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
import org.argeo.jcr.JcrUtils;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.JcrQueryEditorInput;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.NodeEditorInput;
import org.argeo.eclipse.ui.workbench.jcr.DefaultNodeEditor;
import org.argeo.eclipse.ui.workbench.jcr.GenericJcrQueryEditor;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.JcrQueryEditorInput;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.NodeEditorInput;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.internal.jcr.JcrBrowserUtils;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
-import org.argeo.eclipse.ui.workbench.jcr.internal.JcrBrowserUtils;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
*/
package org.argeo.eclipse.ui.workbench.commands;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.RemoteRepositoryElem;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.RemoteRepositoryElem;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.dialogs.SingleValue;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
import org.argeo.jcr.JcrUtils;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionIterator;
+import javax.jcr.version.VersionManager;
+
+import org.argeo.ArgeoException;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Display some version information of a JCR full versionable node in a tree
+ * like structure
+ */
+public class FullVersioningTreeContentProvider implements ITreeContentProvider {
+ private static final long serialVersionUID = 8691772509491211112L;
+
+ /**
+ * Sends back the first level of the Tree. input element must be a single
+ * node object
+ */
+ public Object[] getElements(Object inputElement) {
+ try {
+ Node rootNode = (Node) inputElement;
+ String curPath = rootNode.getPath();
+ VersionManager vm = rootNode.getSession().getWorkspace()
+ .getVersionManager();
+
+ VersionHistory vh = vm.getVersionHistory(curPath);
+ List<Version> result = new ArrayList<Version>();
+ VersionIterator vi = vh.getAllLinearVersions();
+
+ while (vi.hasNext()) {
+ result.add(vi.nextVersion());
+ }
+ return result.toArray();
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while getting version elements", re);
+ }
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ try {
+ if (parentElement instanceof Version) {
+ List<Node> tmp = new ArrayList<Node>();
+ tmp.add(((Version) parentElement).getFrozenNode());
+ return tmp.toArray();
+ }
+ } catch (RepositoryException re) {
+ throw new ArgeoException("Unexpected error while getting child "
+ + "node for version element", re);
+ }
+ return null;
+ }
+
+ public Object getParent(Object element) {
+ try {
+ // this will not work in a simpleVersionning environment, parent is
+ // not a node.
+ if (element instanceof Node
+ && ((Node) element).isNodeType(NodeType.NT_FROZEN_NODE)) {
+ Node node = (Node) element;
+ return node.getParent();
+ } else
+ return null;
+ } catch (RepositoryException e) {
+ return null;
+ }
+ }
+
+ public boolean hasChildren(Object element) {
+ try {
+ if (element instanceof Version)
+ return true;
+ else if (element instanceof Node)
+ return ((Node) element).hasNodes();
+ else
+ 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) {
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.GenericNodeEditorInput;
+import org.argeo.eclipse.ui.workbench.jcr.DefaultNodeEditor;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.ui.PartInitException;
+
+/** Centralizes the management of double click on a NodeTreeViewer */
+public class GenericNodeDoubleClickListener implements IDoubleClickListener {
+ // private final static Log log = LogFactory
+ // .getLog(GenericNodeDoubleClickListener.class);
+
+ private TreeViewer nodeViewer;
+
+ // private JcrFileProvider jfp;
+ // private FileHandler fileHandler;
+
+ public GenericNodeDoubleClickListener(TreeViewer nodeViewer) {
+ this.nodeViewer = nodeViewer;
+ // jfp = new JcrFileProvider();
+ // Commented out. see https://www.argeo.org/bugzilla/show_bug.cgi?id=188
+ // fileHandler = null;
+ // fileHandler = new FileHandler(jfp);
+ }
+
+ public void doubleClick(DoubleClickEvent event) {
+ if (event.getSelection() == null || event.getSelection().isEmpty())
+ return;
+ Object obj = ((IStructuredSelection) event.getSelection())
+ .getFirstElement();
+ if (obj instanceof RepositoryElem) {
+ RepositoryElem rpNode = (RepositoryElem) obj;
+ if (!rpNode.isConnected()) {
+ rpNode.login();
+ nodeViewer.refresh(obj);
+ }
+ } else if (obj instanceof WorkspaceElem) {
+ WorkspaceElem wn = (WorkspaceElem) obj;
+ if (wn.isConnected())
+ wn.logout();
+ else
+ wn.login();
+ nodeViewer.refresh(obj);
+ } else if (obj instanceof SingleJcrNodeElem) {
+ SingleJcrNodeElem sjn = (SingleJcrNodeElem) obj;
+ Node node = sjn.getNode();
+ try {
+ if (node.isNodeType(NodeType.NT_FILE)) {
+ // double click on a file node triggers its opening
+ // String name = node.getName();
+ // String id = node.getIdentifier();
+
+ // TODO add integration of direct retrieval of the binary in
+ // a JCR repo.
+ // Map<String, String> params = new HashMap<String,
+ // String>();
+ // params.put(OpenFile.PARAM_FILE_NAME, name);
+ // params.put(OpenFile.PARAM_FILE_URI, "jcr://" + id);
+ // CommandUtils
+ // .callCommand("org.argeo.security.ui.specific.openFile",
+ // params);
+
+ // For the file provider to be able to browse the
+ // various
+ // repository.
+ // TODO : enhanced that.
+ // ITreeContentProvider itcp = (ITreeContentProvider)
+ // nodeViewer
+ // .getContentProvider();
+ // jfp.setReferenceNode(node);
+ // if (fileHandler != null)
+ // fileHandler.openFile(name, id);
+ }
+ GenericNodeEditorInput gnei = new GenericNodeEditorInput(node);
+ WorkbenchUiPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage()
+ .openEditor(gnei, DefaultNodeEditor.ID);
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Repository error while getting node info", re);
+ } catch (PartInitException pie) {
+ throw new ArgeoException(
+ "Unexepected exception while opening node editor", pie);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoriesElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem;
+
+/** Centralizes useful methods to manage the JCR Browser */
+public class JcrBrowserUtils {
+
+ /** Insure that the UI component is not stale, refresh if needed */
+ public static void forceRefreshIfNeeded(TreeParent element) {
+ Node curNode = null;
+
+ boolean doRefresh = false;
+
+ try {
+ if (element instanceof SingleJcrNodeElem) {
+ curNode = ((SingleJcrNodeElem) element).getNode();
+ } else if (element instanceof WorkspaceElem) {
+ curNode = ((WorkspaceElem) element).getRootNode();
+ }
+
+ if (curNode != null
+ && element.getChildren().length != curNode.getNodes()
+ .getSize())
+ doRefresh = true;
+ else if (element instanceof RepositoryElem) {
+ RepositoryElem rn = (RepositoryElem) element;
+ if (rn.isConnected()) {
+ String[] wkpNames = rn.getAccessibleWorkspaceNames();
+ if (element.getChildren().length != wkpNames.length)
+ doRefresh = true;
+ }
+ } else if (element instanceof RepositoriesElem) {
+ doRefresh = true;
+ // Always force refresh for RepositoriesElem : the condition
+ // below does not take remote repository into account and it is
+ // not trivial to do so.
+
+ // RepositoriesElem rn = (RepositoriesElem) element;
+ // if (element.getChildren().length !=
+ // rn.getRepositoryRegister()
+ // .getRepositories().size())
+ // doRefresh = true;
+ }
+ if (doRefresh) {
+ element.clearChildren();
+ element.getChildren();
+ }
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while synchronising the UI with the JCR repository",
+ re);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.ArgeoJcrConstants;
+import org.argeo.jcr.RepositoryRegister;
+import org.argeo.jcr.UserJcrUtils;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoriesElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.util.security.Keyring;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Implementation of the {@code ITreeContentProvider} to display multiple
+ * repository environment in a tree like structure
+ */
+public class NodeContentProvider implements ITreeContentProvider {
+ private static final long serialVersionUID = -4083809398848374403L;
+ final private RepositoryRegister repositoryRegister;
+ final private RepositoryFactory repositoryFactory;
+
+ // Current user session on the default workspace of the argeo Node
+ final private Session userSession;
+ final private Keyring keyring;
+ private boolean sortChildren;
+
+ // Reference for cleaning
+ private SingleJcrNodeElem homeNode = null;
+ private RepositoriesElem repositoriesNode = null;
+
+ // Utils
+ private TreeBrowserComparator itemComparator = new TreeBrowserComparator();
+
+ public NodeContentProvider(Session userSession, Keyring keyring,
+ RepositoryRegister repositoryRegister,
+ RepositoryFactory repositoryFactory, Boolean sortChildren) {
+ this.userSession = userSession;
+ this.keyring = keyring;
+ this.repositoryRegister = repositoryRegister;
+ this.repositoryFactory = repositoryFactory;
+ this.sortChildren = sortChildren;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput == null)// dispose
+ return;
+
+ if (userSession != null) {
+ Node userHome = UserJcrUtils.getUserHome(userSession);
+ if (userHome != null) {
+ // TODO : find a way to dynamically get alias for the node
+ if (homeNode != null)
+ homeNode.dispose();
+ homeNode = new SingleJcrNodeElem(null, userHome,
+ userSession.getUserID(), ArgeoJcrConstants.ALIAS_NODE);
+ }
+ }
+ if (repositoryRegister != null) {
+ if (repositoriesNode != null)
+ repositoriesNode.dispose();
+ repositoriesNode = new RepositoriesElem("Repositories",
+ repositoryRegister, repositoryFactory, null, userSession,
+ keyring);
+ }
+ }
+
+ /**
+ * Sends back the first level of the Tree. Independent from inputElement
+ * that can be null
+ */
+ public Object[] getElements(Object inputElement) {
+ List<Object> objs = new ArrayList<Object>();
+ if (homeNode != null)
+ objs.add(homeNode);
+ if (repositoriesNode != null)
+ objs.add(repositoriesNode);
+ return objs.toArray();
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof TreeParent) {
+ if (sortChildren) {
+ Object[] tmpArr = ((TreeParent) parentElement).getChildren();
+ if (tmpArr == null)
+ return new Object[0];
+ TreeParent[] arr = new TreeParent[tmpArr.length];
+ for (int i = 0; i < tmpArr.length; i++)
+ arr[i] = (TreeParent) tmpArr[i];
+ Arrays.sort(arr, itemComparator);
+ return arr;
+ } else
+ return ((TreeParent) parentElement).getChildren();
+ } else
+ return new Object[0];
+ }
+
+ /**
+ * Sets whether the content provider should order the children nodes or not.
+ * It is user duty to call a full refresh of the tree after changing this
+ * parameter.
+ */
+ public void setSortChildren(boolean sortChildren) {
+ this.sortChildren = sortChildren;
+ }
+
+ public Object getParent(Object element) {
+ if (element instanceof TreeParent) {
+ return ((TreeParent) element).getParent();
+ } else
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element instanceof RepositoriesElem) {
+ RepositoryRegister rr = ((RepositoriesElem) element)
+ .getRepositoryRegister();
+ return rr.getRepositories().size() > 0;
+ } else if (element instanceof TreeParent) {
+ TreeParent tp = (TreeParent) element;
+ return tp.hasChildren();
+ }
+ return false;
+ }
+
+ public void dispose() {
+ if (homeNode != null)
+ homeNode.dispose();
+ if (repositoriesNode != null) {
+ // logs out open sessions
+ // see https://bugzilla.argeo.org/show_bug.cgi?id=23
+ repositoriesNode.dispose();
+ }
+ }
+
+ /**
+ * Specific comparator for this view. See specification here:
+ * https://www.argeo.org/bugzilla/show_bug.cgi?id=139
+ */
+ private class TreeBrowserComparator implements Comparator<TreeParent> {
+
+ public int category(TreeParent element) {
+ if (element instanceof SingleJcrNodeElem) {
+ Node node = ((SingleJcrNodeElem) element).getNode();
+ try {
+ if (node.isNodeType(NodeType.NT_FOLDER))
+ return 5;
+ } catch (RepositoryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return 10;
+ }
+
+ public int compare(TreeParent o1, TreeParent o2) {
+ int cat1 = category(o1);
+ int cat2 = category(o2);
+
+ if (cat1 != cat2) {
+ return cat1 - cat2;
+ }
+ return o1.getName().compareTo(o2.getName());
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.RemoteRepositoryElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoriesElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.WorkspaceElem;
+import org.argeo.eclipse.ui.workbench.jcr.JcrImages;
+import org.argeo.jcr.ArgeoTypes;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/** Provides reasonable defaults for know JCR types. */
+public class NodeLabelProvider extends ColumnLabelProvider {
+ private static final long serialVersionUID = -3662051696443321843L;
+
+ private final static Log log = LogFactory.getLog(NodeLabelProvider.class);
+
+ public String getText(Object element) {
+ try {
+ if (element instanceof SingleJcrNodeElem) {
+ SingleJcrNodeElem sjn = (SingleJcrNodeElem) element;
+ return getText(sjn.getNode());
+ } else if (element instanceof Node) {
+ return getText((Node) element);
+ } else
+ return super.getText(element);
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected JCR error while getting node name.");
+ }
+ }
+
+ protected String getText(Node node) throws RepositoryException {
+ String label = node.getName();
+ StringBuffer mixins = new StringBuffer("");
+ for (NodeType type : node.getMixinNodeTypes())
+ mixins.append(' ').append(type.getName());
+
+ return label + " [" + node.getPrimaryNodeType().getName() + mixins
+ + "]";
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof RemoteRepositoryElem) {
+ if (((RemoteRepositoryElem) element).isConnected())
+ return JcrImages.REMOTE_CONNECTED;
+ else
+ return JcrImages.REMOTE_DISCONNECTED;
+ } else if (element instanceof RepositoryElem) {
+ if (((RepositoryElem) element).isConnected())
+ return JcrImages.REPOSITORY_CONNECTED;
+ else
+ return JcrImages.REPOSITORY_DISCONNECTED;
+ } else if (element instanceof WorkspaceElem) {
+ if (((WorkspaceElem) element).isConnected())
+ return JcrImages.WORKSPACE_CONNECTED;
+ else
+ return JcrImages.WORKSPACE_DISCONNECTED;
+ } else if (element instanceof RepositoriesElem) {
+ return JcrImages.REPOSITORIES;
+ } else if (element instanceof SingleJcrNodeElem) {
+ Node nodeElem = ((SingleJcrNodeElem) element).getNode();
+ return getImage(nodeElem);
+
+ // if (element instanceof Node) {
+ // return getImage((Node) element);
+ // } else if (element instanceof WrappedNode) {
+ // return getImage(((WrappedNode) element).getNode());
+ // } else if (element instanceof NodesWrapper) {
+ // return getImage(((NodesWrapper) element).getNode());
+ // }
+ }
+ // try {
+ // return super.getImage();
+ // } catch (RepositoryException e) {
+ // return null;
+ // }
+ return super.getImage(element);
+ }
+
+ protected Image getImage(Node node) {
+ try {
+ if (node.getPrimaryNodeType().isNodeType(NodeType.NT_FILE))
+ return JcrImages.FILE;
+ else if (node.getPrimaryNodeType().isNodeType(NodeType.NT_FOLDER))
+ return JcrImages.FOLDER;
+ else if (node.getPrimaryNodeType().isNodeType(NodeType.NT_RESOURCE))
+ return JcrImages.BINARY;
+ else if (node.isNodeType(ArgeoTypes.ARGEO_USER_HOME))
+ return JcrImages.HOME;
+ else
+ return JcrImages.NODE;
+ } catch (RepositoryException e) {
+ log.warn("Error while retrieving type for " + node
+ + " in order to display corresponding image");
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.jcr.utils.JcrItemsComparator;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+public class PropertiesContentProvider implements IStructuredContentProvider {
+ private static final long serialVersionUID = 5227554668841613078L;
+ private JcrItemsComparator itemComparator = new JcrItemsComparator();
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Object[] getElements(Object inputElement) {
+ try {
+ if (inputElement instanceof Node) {
+ Set<Property> props = new TreeSet<Property>(itemComparator);
+ PropertyIterator pit = ((Node) inputElement).getProperties();
+ while (pit.hasNext())
+ props.add(pit.nextProperty());
+ return props.toArray();
+ }
+ return new Object[] {};
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot get element for " + inputElement,
+ e);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
+import org.argeo.jcr.JcrUtils;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ViewerCell;
+
+/** Default basic label provider for a given JCR Node's properties */
+public class PropertyLabelProvider extends ColumnLabelProvider implements
+ WorkbenchConstants {
+ private static final long serialVersionUID = -5405794508731390147L;
+
+ // To be able to change column order easily
+ public static final int COLUMN_PROPERTY = 0;
+ public static final int COLUMN_VALUE = 1;
+ public static final int COLUMN_ATTRIBUTES = 2;
+
+ // Utils
+ protected DateFormat timeFormatter = new SimpleDateFormat(DATE_TIME_FORMAT);
+
+ public void update(ViewerCell cell) {
+ Object element = cell.getElement();
+ cell.setText(getColumnText(element, cell.getColumnIndex()));
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ try {
+ if (element instanceof Property) {
+ Property prop = (Property) element;
+ if (prop.isMultiple()) {
+ switch (columnIndex) {
+ case COLUMN_PROPERTY:
+ return prop.getName();
+ case COLUMN_VALUE:
+ // Corresponding values are listed on children
+ return "";
+ case COLUMN_ATTRIBUTES:
+ return JcrUtils.getPropertyDefinitionAsString(prop);
+ }
+ } else {
+ switch (columnIndex) {
+ case COLUMN_PROPERTY:
+ return prop.getName();
+ case COLUMN_VALUE:
+ return formatValueAsString(prop.getValue());
+ case COLUMN_ATTRIBUTES:
+ return JcrUtils.getPropertyDefinitionAsString(prop);
+ }
+ }
+ } else if (element instanceof Value) {
+ Value val = (Value) element;
+
+ switch (columnIndex) {
+ case COLUMN_PROPERTY:
+ // Nothing to show
+ return "";
+ case COLUMN_VALUE:
+ return formatValueAsString(val);
+ case COLUMN_ATTRIBUTES:
+ // Corresponding attributes are listed on the parent
+ return "";
+ }
+ }
+
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexepected error while getting property values", re);
+ }
+ return null;
+ }
+
+ private String formatValueAsString(Value value) {
+ // TODO enhance this method
+ try {
+ String strValue;
+
+ if (value.getType() == PropertyType.BINARY)
+ strValue = "<binary>";
+ else if (value.getType() == PropertyType.DATE)
+ strValue = timeFormatter.format(value.getDate().getTime());
+ else
+ strValue = value.getString();
+ return strValue;
+ } catch (RepositoryException e) {
+ throw new ArgeoException("unexpected error while formatting value",
+ e);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.jcr.utils.JcrItemsComparator;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Implementation of the {@code ITreeContentProvider} in order to display a
+ * single JCR node and its children in a tree like structure
+ */
+public class SingleNodeAsTreeContentProvider implements ITreeContentProvider {
+ private static final long serialVersionUID = -2128326504754297297L;
+ // private Node rootNode;
+ private JcrItemsComparator itemComparator = new JcrItemsComparator();
+
+ /**
+ * Sends back the first level of the Tree. input element must be a single
+ * node object
+ */
+ public Object[] getElements(Object inputElement) {
+ try {
+ Node rootNode = (Node) inputElement;
+ List<Node> result = new ArrayList<Node>();
+ NodeIterator ni = rootNode.getNodes();
+ while (ni.hasNext()) {
+ result.add(ni.nextNode());
+ }
+
+ return result.toArray();
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while getting child nodes for children editor page ",
+ re);
+ }
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return childrenNodes((Node) parentElement);
+ }
+
+ public Object getParent(Object element) {
+ try {
+ Node node = (Node) element;
+ if (!node.getPath().equals("/"))
+ return node.getParent();
+ else
+ return null;
+ } catch (RepositoryException e) {
+ return null;
+ }
+ }
+
+ public boolean hasChildren(Object element) {
+ try {
+ return ((Node) element).hasNodes();
+ } 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);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.version.Version;
+
+import org.argeo.ArgeoException;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+
+/**
+ * Simple wrapping of the ColumnLabelProvider class to provide text display in
+ * order to build a tree for version. The getText() method does not assume that
+ * {@link Version} extends {@link Node} class to respect JCR 2.0 specification
+ *
+ */
+public class VersionLabelProvider extends ColumnLabelProvider {
+ private static final long serialVersionUID = 5270739851193688238L;
+
+ public String getText(Object element) {
+ try {
+ if (element instanceof Version) {
+ Version version = (Version) element;
+ return version.getName();
+ } else if (element instanceof Node) {
+ return ((Node) element).getName();
+ }
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while getting element name", re);
+ }
+ return super.getText(element);
+ }
+}
--- /dev/null
+package org.argeo.eclipse.ui.workbench.internal.jcr.model;
+
+import javax.jcr.Repository;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.MaintainedRepository;
+
+/** Wrap a {@link MaintainedRepository} */
+public class MaintainedRepositoryElem extends RepositoryElem {
+
+ public MaintainedRepositoryElem(String alias, Repository repository,
+ TreeParent parent) {
+ super(alias, repository, parent);
+ if (!(repository instanceof MaintainedRepository)) {
+ throw new ArgeoException("Repository " + alias
+ + " is not amiantained repository");
+ }
+ }
+
+ protected MaintainedRepository getMaintainedRepository() {
+ return (MaintainedRepository) getRepository();
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.model;
+
+import java.util.Arrays;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.ArgeoJcrUtils;
+import org.argeo.jcr.ArgeoNames;
+import org.argeo.util.security.Keyring;
+
+/** Root of a remote repository */
+public class RemoteRepositoryElem extends RepositoryElem {
+ private final Keyring keyring;
+ /**
+ * A session of the logged in user on the default workspace of the node
+ * repository.
+ */
+ private final Session userSession;
+ private final String remoteNodePath;
+
+ private final RepositoryFactory repositoryFactory;
+ private final String uri;
+
+ public RemoteRepositoryElem(String alias,
+ RepositoryFactory repositoryFactory, String uri, TreeParent parent,
+ Session userSession, Keyring keyring, String remoteNodePath) {
+ super(alias, null, parent);
+ this.repositoryFactory = repositoryFactory;
+ this.uri = uri;
+ this.keyring = keyring;
+ this.userSession = userSession;
+ this.remoteNodePath = remoteNodePath;
+ }
+
+ @Override
+ protected Session repositoryLogin(String workspaceName)
+ throws RepositoryException {
+ Node remoteRepository = userSession.getNode(remoteNodePath);
+ String userID = remoteRepository.getProperty(ArgeoNames.ARGEO_USER_ID)
+ .getString();
+ String pwdPath = remoteRepository.getPath() + '/'
+ + ArgeoNames.ARGEO_PASSWORD;
+ char[] password = keyring.getAsChars(pwdPath);
+
+ try {
+ SimpleCredentials credentials = new SimpleCredentials(userID,
+ password);
+ return getRepository().login(credentials, workspaceName);
+ } finally {
+ Arrays.fill(password, 0, password.length, ' ');
+ }
+ }
+
+ @Override
+ public Repository getRepository() {
+ if (repository == null)
+ repository = ArgeoJcrUtils.getRepositoryByUri(repositoryFactory,
+ uri);
+ return super.getRepository();
+ }
+
+ public void remove() {
+ try {
+ Node remoteNode = userSession.getNode(remoteNodePath);
+ remoteNode.remove();
+ remoteNode.getSession().save();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot remove " + remoteNodePath, e);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.model;
+
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
+import org.argeo.jcr.ArgeoNames;
+import org.argeo.jcr.MaintainedRepository;
+import org.argeo.jcr.RepositoryRegister;
+import org.argeo.jcr.UserJcrUtils;
+import org.argeo.util.security.Keyring;
+
+/**
+ * UI Tree component that 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 RepositoriesElem extends TreeParent implements ArgeoNames {
+ private final RepositoryRegister repositoryRegister;
+ private final RepositoryFactory repositoryFactory;
+
+ /**
+ * A session of the logged in user on the default workspace of the node
+ * repository.
+ */
+ private final Session userSession;
+ private final Keyring keyring;
+
+ public RepositoriesElem(String name, RepositoryRegister repositoryRegister,
+ RepositoryFactory repositoryFactory, TreeParent parent,
+ Session userSession, Keyring keyring) {
+ super(name);
+ this.repositoryRegister = repositoryRegister;
+ this.repositoryFactory = repositoryFactory;
+ this.userSession = userSession;
+ this.keyring = keyring;
+ }
+
+ /**
+ * Override normal behavior 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()) {
+ Repository repository = refRepos.get(name);
+ if (repository instanceof MaintainedRepository)
+ super.addChild(new MaintainedRepositoryElem(name,
+ repository, this));
+ else
+ super.addChild(new RepositoryElem(name, repository, this));
+ }
+
+ // remote
+ if (keyring != null) {
+ try {
+ addRemoteRepositories(keyring);
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Cannot browse remote repositories", e);
+ }
+ }
+ return super.getChildren();
+ }
+ }
+
+ protected void addRemoteRepositories(Keyring jcrKeyring)
+ throws RepositoryException {
+ Node userHome = UserJcrUtils.getUserHome(userSession);
+ if (userHome != null && userHome.hasNode(ARGEO_REMOTE)) {
+ NodeIterator it = userHome.getNode(ARGEO_REMOTE).getNodes();
+ while (it.hasNext()) {
+ Node remoteNode = it.nextNode();
+ String uri = remoteNode.getProperty(ARGEO_URI).getString();
+ try {
+ RemoteRepositoryElem remoteRepositoryNode = new RemoteRepositoryElem(
+ remoteNode.getName(), repositoryFactory, uri, this,
+ userSession, jcrKeyring, remoteNode.getPath());
+ super.addChild(remoteRepositoryNode);
+ } catch (Exception e) {
+ ErrorFeedback.show("Cannot add remote repository "
+ + remoteNode, e);
+ }
+ }
+ }
+ }
+
+ 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 this object. */
+ public RepositoryRegister getRepositoryRegister() {
+ return repositoryRegister;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.model;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+
+/**
+ * UI Tree component that 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 RepositoryElem extends TreeParent {
+ private String alias;
+ protected Repository repository;
+ private Session defaultSession = null;
+
+ /** Create a new repository with distinct name & alias */
+ public RepositoryElem(String alias, Repository repository, TreeParent parent) {
+ super(alias);
+ this.repository = repository;
+ setParent(parent);
+ this.alias = alias;
+ }
+
+ public void login() {
+ try {
+ defaultSession = repositoryLogin("main");
+ String[] wkpNames = defaultSession.getWorkspace()
+ .getAccessibleWorkspaceNames();
+ for (String wkpName : wkpNames) {
+ if (wkpName.equals(defaultSession.getWorkspace().getName()))
+ addChild(new WorkspaceElem(this, wkpName, defaultSession));
+ else
+ addChild(new WorkspaceElem(this, wkpName));
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot connect to repository " + alias, e);
+ }
+ }
+
+ /**
+ * Actual call to the
+ * {@link Repository#login(javax.jcr.Credentials, String)} method. To be
+ * overridden.
+ */
+ protected Session repositoryLogin(String workspaceName)
+ throws RepositoryException {
+ return repository.login(workspaceName);
+ }
+
+ public String[] getAccessibleWorkspaceNames() {
+ try {
+ return defaultSession.getWorkspace().getAccessibleWorkspaceNames();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot retrieve workspace names", e);
+ }
+ }
+
+ public void createWorkspace(String workspaceName) {
+ if (!isConnected())
+ login();
+ try {
+ defaultSession.getWorkspace().createWorkspace(workspaceName);
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot create workspace", e);
+ }
+ }
+
+ /** returns the {@link Repository} referenced by the current UI Node */
+ public Repository getRepository() {
+ return repository;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
+ public Boolean isConnected() {
+ if (defaultSession != null && defaultSession.isLive())
+ return true;
+ else
+ return false;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.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 WorkspaceElem}, a
+ * {@link SingleJcrNodeElem} or null if the node is "mounted" as the root of the UI
+ * tree.
+ */
+
+public class SingleJcrNodeElem extends TreeParent {
+
+ 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 SingleJcrNodeElem(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 SingleJcrNodeElem(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;
+ }
+
+ protected String getRepositoryAlias() {
+ return alias;
+ }
+
+ /**
+ * Override normal behavior 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 SingleJcrNodeElem(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 {
+ if (node.getSession().isLive())
+ return node.hasNodes();
+ else
+ return false;
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while checking children node existence",
+ re);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.model;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+// import javax.jcr.Workspace;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.JcrUtils;
+
+/**
+ * UI Tree component. Wraps the root node of a JCR {@link Workspace}. It also
+ * keeps a reference to its parent {@link RepositoryElem}, to be able to
+ * retrieve alias of the current used repository
+ */
+public class WorkspaceElem extends TreeParent {
+ private Session session = null;
+
+ public WorkspaceElem(RepositoryElem parent, String name) {
+ this(parent, name, null);
+ }
+
+ public WorkspaceElem(RepositoryElem parent, String name, Session session) {
+ super(name);
+ this.session = session;
+ setParent(parent);
+ }
+
+ public synchronized Session getSession() {
+ return session;
+ }
+
+ public synchronized 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 synchronized void login() {
+ try {
+ session = ((RepositoryElem) getParent()).repositoryLogin(getName());
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot connect to repository "
+ + getName(), e);
+ }
+ }
+
+ public Boolean isConnected() {
+ if (session != null && session.isLive())
+ return true;
+ else
+ return false;
+ }
+
+ @Override
+ public synchronized void dispose() {
+ logout();
+ super.dispose();
+ }
+
+ /** Logouts the session, does not nothing if there is no live session. */
+ public synchronized void logout() {
+ clearChildren();
+ JcrUtils.logoutQuietly(session);
+ session = null;
+ }
+
+ @Override
+ public synchronized boolean hasChildren() {
+ try {
+ if (isConnected())
+ return session.getRootNode().hasNodes();
+ else
+ return false;
+ } 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 SingleJcrNodeElem(this, node, node.getName()));
+ }
+ return super.getChildren();
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Cannot initialize WorkspaceNode UI object."
+ + getName(), e);
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.GenericTableComparator;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.EditorPart;
+
+/** Executes any JCR query. */
+public abstract class AbstractJcrQueryEditor extends EditorPart {
+ private final static Log log = LogFactory
+ .getLog(AbstractJcrQueryEditor.class);
+
+ protected String initialQuery;
+ protected String initialQueryType;
+
+ /* DEPENDENCY INJECTION */
+ private Session session;
+
+ // Widgets
+ private TableViewer viewer;
+ private List<TableViewerColumn> tableViewerColumns = new ArrayList<TableViewerColumn>();
+ private GenericTableComparator comparator;
+
+ /** Override to layout a form enabling the end user to build his query */
+ protected abstract void createQueryForm(Composite parent);
+
+ @Override
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ JcrQueryEditorInput editorInput = (JcrQueryEditorInput) input;
+ initialQuery = editorInput.getQuery();
+ initialQueryType = editorInput.getQueryType();
+ setSite(site);
+ setInput(editorInput);
+ }
+
+ @Override
+ public final void createPartControl(final Composite parent) {
+ parent.setLayout(new FillLayout());
+
+ SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
+ sashForm.setSashWidth(4);
+ sashForm.setLayout(new FillLayout());
+
+ Composite top = new Composite(sashForm, SWT.NONE);
+ GridLayout gl = new GridLayout(1, false);
+ top.setLayout(gl);
+
+ createQueryForm(top);
+
+ Composite bottom = new Composite(sashForm, SWT.NONE);
+ bottom.setLayout(new GridLayout(1, false));
+ sashForm.setWeights(getWeights());
+
+ viewer = new TableViewer(bottom);
+ viewer.getTable().setLayoutData(
+ new GridData(SWT.FILL, SWT.FILL, true, true));
+ viewer.getTable().setHeaderVisible(true);
+ viewer.setContentProvider(getQueryResultContentProvider());
+ viewer.setInput(getEditorSite());
+
+ if (getComparator() != null) {
+ comparator = getComparator();
+ viewer.setComparator(comparator);
+ }
+ if (getTableDoubleClickListener() != null)
+ viewer.addDoubleClickListener(getTableDoubleClickListener());
+
+ }
+
+ protected void executeQuery(String statement) {
+ try {
+ if (log.isDebugEnabled())
+ log.debug("Query : " + statement);
+
+ QueryResult qr = session.getWorkspace().getQueryManager()
+ .createQuery(statement, initialQueryType).execute();
+
+ // remove previous columns
+ for (TableViewerColumn tvc : tableViewerColumns)
+ tvc.getColumn().dispose();
+
+ int i = 0;
+ for (final String columnName : qr.getColumnNames()) {
+ TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE);
+ configureColumn(columnName, tvc, i);
+ tvc.setLabelProvider(getLabelProvider(columnName));
+ tableViewerColumns.add(tvc);
+ i++;
+ }
+
+ // Must create a local list: QueryResults can only be read once.
+ try {
+ List<Row> rows = new ArrayList<Row>();
+ RowIterator rit = qr.getRows();
+ while (rit.hasNext()) {
+ rows.add(rit.nextRow());
+ }
+ viewer.setInput(rows);
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot read query result", e);
+ }
+
+ } catch (RepositoryException e) {
+ ErrorDialog.openError(null, "Error", "Cannot execute JCR query: "
+ + statement, new Status(IStatus.ERROR,
+ "org.argeo.eclipse.ui.jcr", e.getMessage()));
+ }
+ }
+
+ /**
+ * To be overidden to adapt size of form and result frames.
+ *
+ * @return
+ */
+ protected int[] getWeights() {
+ return new int[] { 30, 70 };
+ }
+
+ /**
+ * To be overidden to implement a doubleclick Listener on one of the rows of
+ * the table.
+ *
+ * @return
+ */
+ protected IDoubleClickListener getTableDoubleClickListener() {
+ return null;
+ }
+
+ /**
+ * To be overiden in order to implement a specific
+ * QueryResultContentProvider
+ */
+ protected IStructuredContentProvider getQueryResultContentProvider() {
+ return new QueryResultContentProvider();
+ }
+
+ /**
+ * Enable specific implementation for columns
+ */
+ protected List<TableViewerColumn> getTableViewerColumns() {
+ return tableViewerColumns;
+ }
+
+ /**
+ * Enable specific implementation for columns
+ */
+ protected TableViewer getTableViewer() {
+ return viewer;
+ }
+
+ /**
+ * To be overridden in order to configure column label providers .
+ */
+ protected ColumnLabelProvider getLabelProvider(final String columnName) {
+ return new ColumnLabelProvider() {
+ private static final long serialVersionUID = -3539689333250152606L;
+
+ public String getText(Object element) {
+ Row row = (Row) element;
+ try {
+ return row.getValue(columnName).getString();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot display row " + row, e);
+ }
+ }
+
+ public Image getImage(Object element) {
+ return null;
+ }
+ };
+ }
+
+ /**
+ * To be overridden in order to configure the columns.
+ *
+ * @deprecated use {@link
+ * org.argeo.eclipse.ui.jcr.editors.AbstractJcrQueryEditor.
+ * configureColumn(String jcrColumnName, TableViewerColumn
+ * column, int columnIndex)} instead
+ */
+ protected void configureColumn(String jcrColumnName,
+ TableViewerColumn column) {
+ column.getColumn().setWidth(50);
+ column.getColumn().setText(jcrColumnName);
+ }
+
+ /** To be overridden in order to configure the columns. */
+ protected void configureColumn(String jcrColumnName,
+ TableViewerColumn column, int columnIndex) {
+ column.getColumn().setWidth(50);
+ column.getColumn().setText(jcrColumnName);
+ }
+
+ private class QueryResultContentProvider implements
+ IStructuredContentProvider {
+ private static final long serialVersionUID = -5421095459600554741L;
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Object[] getElements(Object inputElement) {
+
+ if (inputElement instanceof List)
+ return ((List<?>) inputElement).toArray();
+
+ // Never reached might be deleted in future release
+ if (!(inputElement instanceof QueryResult))
+ return new String[] {};
+
+ try {
+ QueryResult queryResult = (QueryResult) inputElement;
+ List<Row> rows = new ArrayList<Row>();
+ RowIterator rit = queryResult.getRows();
+ while (rit.hasNext()) {
+ rows.add(rit.nextRow());
+ }
+
+ // List<Node> elems = new ArrayList<Node>();
+ // NodeIterator nit = queryResult.getNodes();
+ // while (nit.hasNext()) {
+ // elems.add(nit.nextNode());
+ // }
+ return rows.toArray();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot read query result", e);
+ }
+ }
+
+ }
+
+ /**
+ * Might be used by children classes to sort columns.
+ *
+ * @param column
+ * @param index
+ * @return
+ */
+ protected SelectionAdapter getSelectionAdapter(final TableColumn column,
+ final int index) {
+
+ // A comparator must be define
+ if (comparator == null)
+ return null;
+
+ SelectionAdapter selectionAdapter = new SelectionAdapter() {
+ private static final long serialVersionUID = 239829307927778349L;
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
+ try {
+
+ comparator.setColumn(index);
+ int dir = viewer.getTable().getSortDirection();
+ if (viewer.getTable().getSortColumn() == column) {
+ dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
+ } else {
+
+ dir = SWT.DOWN;
+ }
+ viewer.getTable().setSortDirection(dir);
+ viewer.getTable().setSortColumn(column);
+ viewer.refresh();
+ } catch (Exception exc) {
+ exc.printStackTrace();
+ }
+ }
+ };
+ return selectionAdapter;
+ }
+
+ /**
+ * To be overridden to enable sorting.
+ */
+ protected GenericTableComparator getComparator() {
+ return null;
+ }
+
+ @Override
+ public boolean isDirty() {
+ return false;
+ }
+
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ // TODO save the query in JCR?
+ }
+
+ @Override
+ public void doSaveAs() {
+ }
+
+ @Override
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ /** Returns the injected current session */
+ protected Session getSession() {
+ return session;
+ }
+
+ /* DEPENDENCY INJECTION */
+ public void setSession(Session session) {
+ this.session = session;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.security.Privilege;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.EclipseUiUtils;
+import org.argeo.eclipse.ui.workbench.internal.users.UsersUtils;
+import org.argeo.eclipse.ui.workbench.users.PickUpUserDialog;
+import org.argeo.jcr.JcrUtils;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Text;
+import org.osgi.service.useradmin.User;
+import org.osgi.service.useradmin.UserAdmin;
+
+/** Add Jcr privileges to the chosen user group on a given node */
+public class AddPrivilegeWizard extends Wizard {
+
+ // Context
+ private UserAdmin userAdmin;
+ private Session currentSession;
+ private String targetPath;
+ // Chosen parameters
+ private User chosenUser;
+ private String jcrPrivilege;
+
+ // UI Object
+ private DefinePrivilegePage page;
+
+ // TODO enable external definition of possible values and corresponding
+ // description
+ protected static final Map<String, String> AUTH_TYPE_LABELS;
+ static {
+ Map<String, String> tmpMap = new HashMap<String, String>();
+ tmpMap.put(Privilege.JCR_READ, "jcr:read");
+ tmpMap.put(Privilege.JCR_WRITE, "jcr:write");
+ tmpMap.put(Privilege.JCR_ALL, "jcr:all");
+ AUTH_TYPE_LABELS = Collections.unmodifiableMap(tmpMap);
+ }
+
+ protected static final Map<String, String> AUTH_TYPE_DESC;
+ static {
+ Map<String, String> tmpMap = new HashMap<String, String>();
+ tmpMap.put(Privilege.JCR_READ,
+ "The privilege to retrieve a node and get its properties and their values.");
+ tmpMap.put(Privilege.JCR_WRITE, "An aggregate privilege that "
+ + "contains: jcr:modifyProperties, jcr:addChildNodes, "
+ + "jcr:removeNode, jcr:removeChildNodes");
+ tmpMap.put(Privilege.JCR_ALL, "An aggregate privilege that "
+ + "contains all JCR predefined privileges, "
+ + "plus all implementation-defined privileges. ");
+ AUTH_TYPE_DESC = Collections.unmodifiableMap(tmpMap);
+ }
+
+ public AddPrivilegeWizard(Session currentSession, String path,
+ UserAdmin userAdmin) {
+ super();
+ this.userAdmin = userAdmin;
+ this.currentSession = currentSession;
+ this.targetPath = path;
+ }
+
+ @Override
+ public void addPages() {
+ try {
+ setWindowTitle("Add privilege on " + targetPath);
+ page = new DefinePrivilegePage(userAdmin, targetPath);
+ addPage(page);
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot add page to wizard ", e);
+ }
+ }
+
+ @Override
+ public boolean performFinish() {
+ if (!canFinish())
+ return false;
+ try {
+ JcrUtils.addPrivilege(currentSession, targetPath,
+ chosenUser.getName(), jcrPrivilege);
+ } catch (RepositoryException re) {
+ throw new ArgeoException("Cannot set " + jcrPrivilege + " for "
+ + chosenUser.getName() + " on " + targetPath, re);
+ }
+ return true;
+ }
+
+ private class DefinePrivilegePage extends WizardPage implements
+ ModifyListener {
+ private static final long serialVersionUID = 8084431378762283920L;
+
+ // Context
+ final private UserAdmin userAdmin;
+
+ public DefinePrivilegePage(UserAdmin userAdmin, String path) {
+ super("Main");
+ this.userAdmin = userAdmin;
+ setTitle("Define the privilege to apply to " + path);
+ setMessage("Please choose a user or a group and relevant JCR Privilege.");
+ }
+
+ public void createControl(Composite parent) {
+ final Composite composite = new Composite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout(3, false));
+
+ // specify subject
+ createBoldLabel(composite, "User or group name");
+ final Label groupNameLbl = new Label(composite, SWT.LEAD);
+ groupNameLbl.setLayoutData(EclipseUiUtils.fillWidth());
+
+ Link pickUpLk = new Link(composite, SWT.LEFT);
+ pickUpLk.setText(" <a>Change</a> ");
+
+ createBoldLabel(composite, "User or group DN");
+ final Text groupNameTxt = new Text(composite, SWT.LEAD | SWT.BORDER);
+ groupNameTxt.setLayoutData(EclipseUiUtils.fillWidth(2));
+
+ pickUpLk.addSelectionListener(new SelectionAdapter() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ PickUpUserDialog dialog = new PickUpUserDialog(
+ getShell(), "Choose a group or a user", userAdmin);
+ if (dialog.open() == Window.OK) {
+ chosenUser = dialog.getSelected();
+ groupNameLbl.setText(UsersUtils
+ .getCommonName(chosenUser));
+ groupNameTxt.setText(chosenUser.getName());
+ }
+ }
+ });
+
+ groupNameTxt.addFocusListener(new FocusListener() {
+ private static final long serialVersionUID = 1965498600105667738L;
+
+ @Override
+ public void focusLost(FocusEvent event) {
+ String dn = groupNameTxt.getText();
+ User newChosen = null;
+ try {
+ newChosen = (User) userAdmin.getRole(dn);
+ } catch (Exception e) {
+ boolean tryAgain = MessageDialog.openQuestion(
+ getShell(), "Unvalid DN",
+ "DN " + dn + " is not valid.\nError message: "
+ + e.getMessage()
+ + "\n\t\tDo you want to try again?");
+ if (tryAgain)
+ groupNameTxt.setFocus();
+ else
+ resetOnFail();
+ }
+
+ if (userAdmin.getRole(dn) == null) {
+ boolean tryAgain = MessageDialog.openQuestion(
+ getShell(), "Unexisting role", "User/group "
+ + dn + " does not exist. "
+ + "Do you want to try again?");
+ if (tryAgain)
+ groupNameTxt.setFocus();
+ else
+ resetOnFail();
+ } else {
+ chosenUser = newChosen;
+ groupNameLbl.setText(UsersUtils
+ .getCommonName(chosenUser));
+ }
+ }
+
+ private void resetOnFail() {
+ String oldDn = chosenUser == null ? "" : chosenUser
+ .getName();
+ groupNameTxt.setText(oldDn);
+ }
+
+ @Override
+ public void focusGained(FocusEvent event) {
+ }
+ });
+
+ // JCR Privileges
+ createBoldLabel(composite, "Privilege type");
+ Combo authorizationCmb = new Combo(composite, SWT.BORDER
+ | SWT.READ_ONLY | SWT.V_SCROLL);
+ authorizationCmb.setItems(AUTH_TYPE_LABELS.values().toArray(
+ new String[0]));
+ authorizationCmb.setLayoutData(EclipseUiUtils.fillWidth(2));
+ createBoldLabel(composite, ""); // empty cell
+ final Label descLbl = new Label(composite, SWT.WRAP);
+ descLbl.setLayoutData(EclipseUiUtils.fillWidth(2));
+
+ authorizationCmb.addSelectionListener(new SelectionAdapter() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String chosenPrivStr = ((Combo) e.getSource()).getText();
+ if (AUTH_TYPE_LABELS.containsValue(chosenPrivStr)) {
+ loop: for (String key : AUTH_TYPE_LABELS.keySet()) {
+ if (AUTH_TYPE_LABELS.get(key).equals(chosenPrivStr)) {
+ jcrPrivilege = key;
+ break loop;
+ }
+ }
+ }
+
+ if (jcrPrivilege != null) {
+ descLbl.setText(AUTH_TYPE_DESC.get(jcrPrivilege));
+ composite.layout(true, true);
+ }
+ }
+ });
+
+ // Compulsory
+ setControl(composite);
+ }
+
+ public void modifyText(ModifyEvent event) {
+ String message = checkComplete();
+ if (message != null)
+ setMessage(message, WizardPage.ERROR);
+ else {
+ setMessage("Complete", WizardPage.INFORMATION);
+ setPageComplete(true);
+ }
+ }
+
+ /** @return error message or null if complete */
+ protected String checkComplete() {
+ if (chosenUser == null)
+ return "Please choose a relevant group or user";
+ else if (userAdmin.getRole(chosenUser.getName()) == null)
+ return "Please choose a relevant group or user";
+ else if (jcrPrivilege == null)
+ return "Please choose a relevant JCR privilege";
+ return null;
+ }
+ }
+
+ private Label createBoldLabel(Composite parent, String value) {
+ Label label = new Label(parent, SWT.RIGHT);
+ label.setText(" " + value);
+ label.setFont(EclipseUiUtils.getBoldFont(parent));
+ label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+ return label;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import javax.jcr.Node;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.EclipseUiUtils;
+import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.internal.jcr.NodeLabelProvider;
+import org.argeo.eclipse.ui.workbench.internal.jcr.SingleNodeAsTreeContentProvider;
+import org.argeo.eclipse.ui.workbench.jcr.DefaultNodeEditor;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ * List all childs of the current node and brings some browsing capabilities
+ * accross the repository
+ */
+public class ChildNodesPage extends FormPage {
+ // private final static Log log = LogFactory.getLog(ChildNodesPage.class);
+
+ // business objects
+ private Node currentNode;
+
+ // this page UI components
+ private SingleNodeAsTreeContentProvider nodeContentProvider;
+ private TreeViewer nodesViewer;
+
+ public ChildNodesPage(FormEditor editor, String title, Node currentNode) {
+ super(editor, "ChildNodesPage", title);
+ this.currentNode = currentNode;
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ try {
+ ScrolledForm form = managedForm.getForm();
+ form.setText(WorkbenchUiPlugin.getMessage("childNodesPageTitle"));
+ Composite body = form.getBody();
+ GridLayout twt = new GridLayout(1, false);
+ twt.marginWidth = twt.marginHeight = 5;
+ body.setLayout(twt);
+ if (!currentNode.hasNodes()) {
+ managedForm.getToolkit().createLabel(body,
+ WorkbenchUiPlugin.getMessage("warningNoChildNode"));
+ } else {
+ nodeContentProvider = new SingleNodeAsTreeContentProvider();
+ nodesViewer = createNodeViewer(body, nodeContentProvider);
+ nodesViewer.setInput(currentNode);
+ }
+ } catch (Exception e) {
+ throw new ArgeoException(
+ "Unexpected error while creating child node page", e);
+ }
+ }
+
+ protected TreeViewer createNodeViewer(Composite parent,
+ final ITreeContentProvider nodeContentProvider) {
+
+ final TreeViewer tmpNodeViewer = new TreeViewer(parent, SWT.BORDER);
+ Tree tree = tmpNodeViewer.getTree();
+ tree.setLinesVisible(true);
+ tmpNodeViewer.getTree().setLayoutData(EclipseUiUtils.fillAll());
+ tmpNodeViewer.setContentProvider(nodeContentProvider);
+ tmpNodeViewer.setLabelProvider(new NodeLabelProvider());
+ tmpNodeViewer.addDoubleClickListener(new DClickListener());
+ return tmpNodeViewer;
+ }
+
+ public class DClickListener implements IDoubleClickListener {
+
+ public void doubleClick(DoubleClickEvent event) {
+ if (event.getSelection() == null || event.getSelection().isEmpty())
+ return;
+ Object obj = ((IStructuredSelection) event.getSelection())
+ .getFirstElement();
+ if (obj instanceof Node) {
+ Node node = (Node) obj;
+ try {
+ GenericNodeEditorInput gnei = new GenericNodeEditorInput(
+ node);
+ WorkbenchUiPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage()
+ .openEditor(gnei, DefaultNodeEditor.ID);
+ } catch (PartInitException pie) {
+ throw new ArgeoException(
+ "Unexepected exception while opening node editor",
+ pie);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/** Dialog to change the current user password */
+public class ChooseNameDialog extends TitleAreaDialog {
+ private static final long serialVersionUID = 280139710002698692L;
+ private Text nameTxt;
+
+ public ChooseNameDialog(Shell parentShell) {
+ super(parentShell);
+ setTitle("Choose name");
+ }
+
+ protected Point getInitialSize() {
+ return new Point(300, 250);
+ }
+
+ protected Control createDialogArea(Composite parent) {
+ Composite dialogarea = (Composite) super.createDialogArea(parent);
+ dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ Composite composite = new Composite(dialogarea, SWT.NONE);
+ composite.setLayout(new GridLayout(2, false));
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ nameTxt = createLT(composite, "Name");
+
+ setMessage("Choose name", IMessageProvider.INFORMATION);
+ parent.pack();
+ return composite;
+ }
+
+ /** Creates label and text. */
+ protected Text createLT(Composite parent, String label) {
+ new Label(parent, SWT.NONE).setText(label);
+ Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
+ text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ return text;
+ }
+
+ public String getName() {
+ return nameTxt.getText();
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ * This page is only used at editor's creation time when current node has not
+ * yet been set
+ */
+public class EmptyNodePage extends FormPage {
+ // private final static Log log = LogFactory.getLog(EmptyNodePage.class);
+
+ public EmptyNodePage(FormEditor editor, String title) {
+ super(editor, "Empty Page", title);
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ try {
+ ScrolledForm form = managedForm.getForm();
+ GridLayout twt = new GridLayout(1, false);
+ twt.marginWidth = twt.marginHeight = 0;
+ form.getBody().setLayout(twt);
+ Label lbl = new Label(form.getBody(), SWT.NONE);
+ lbl.setText("Empty page");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * An editor input based the JCR node object.
+ * */
+
+public class GenericNodeEditorInput implements IEditorInput {
+ private final Node currentNode;
+
+ // cache key properties at creation time to avoid Exception at recoring time
+ // when the session has been closed
+ private String path;
+ private String uid;
+ private String name;
+
+ public GenericNodeEditorInput(Node currentNode) {
+ this.currentNode = currentNode;
+ try {
+ name = currentNode.getName();
+ uid = currentNode.getIdentifier();
+ path = currentNode.getPath();
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "unexpected error while getting node key values at creation time",
+ re);
+ }
+ }
+
+ public Node getCurrentNode() {
+ return currentNode;
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getUid() {
+ return uid;
+ }
+
+ public String getToolTipText() {
+ return path;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ /**
+ * equals method based on UID that is unique within a workspace and path of
+ * the node, thus 2 shared node that have same UID as defined in the spec
+ * but 2 different pathes will open two distinct editors.
+ *
+ * TODO enhance this method to support multirepository and multiworkspace
+ * environments
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+
+ GenericNodeEditorInput other = (GenericNodeEditorInput) obj;
+ if (!getUid().equals(other.getUid()))
+ return false;
+ if (!getPath().equals(other.getPath()))
+ return false;
+ return true;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.ListIterator;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
+import org.argeo.jcr.JcrUtils;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.AbstractFormPart;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ * Main node editor page. Lists all properties of the current node and enable
+ * access and editing for some of them.
+ */
+
+public class GenericNodePage extends FormPage implements WorkbenchConstants {
+ // private final static Log log = LogFactory.getLog(GenericNodePage.class);
+
+ // local constants
+ private final static String JCR_PROPERTY_NAME = "jcr:name";
+
+ // Utils
+ protected DateFormat timeFormatter = new SimpleDateFormat(DATE_TIME_FORMAT);
+
+ // Main business Objects
+ private Node currentNode;
+
+ // This page widgets
+ private FormToolkit tk;
+ private List<Control> modifyableProperties = new ArrayList<Control>();
+
+ public GenericNodePage(FormEditor editor, String title, Node currentNode) {
+ super(editor, "id", title);
+ this.currentNode = currentNode;
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ tk = managedForm.getToolkit();
+ ScrolledForm form = managedForm.getForm();
+ GridLayout twt = new GridLayout(3, false);
+ twt.marginWidth = twt.marginHeight = 5;
+
+ form.getBody().setLayout(twt);
+ createPropertiesPart(form.getBody());
+ }
+
+ private void createPropertiesPart(Composite parent) {
+ try {
+
+ PropertyIterator pi = currentNode.getProperties();
+
+ // Initializes form part
+ AbstractFormPart part = new AbstractFormPart() {
+ public void commit(boolean onSave) {
+ try {
+ if (onSave) {
+ ListIterator<Control> it = modifyableProperties
+ .listIterator();
+ while (it.hasNext()) {
+ // we only support Text controls for the time
+ // being
+ Text curControl = (Text) it.next();
+ String value = curControl.getText();
+ currentNode.setProperty((String) curControl
+ .getData(JCR_PROPERTY_NAME), value);
+ }
+
+ // We only commit when onSave = true,
+ // thus it is still possible to save after a tab
+ // change.
+ super.commit(onSave);
+ }
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while saving properties", re);
+ }
+ }
+ };
+
+ while (pi.hasNext()) {
+ Property prop = pi.nextProperty();
+ addPropertyLine(parent, part, prop);
+ }
+
+ getManagedForm().addPart(part);
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Error during creation of network details section", re);
+ }
+
+ }
+
+ private void addPropertyLine(Composite parent, AbstractFormPart part,
+ Property prop) {
+ try {
+ tk.createLabel(parent, prop.getName());
+ tk.createLabel(parent,
+ "[" + JcrUtils.getPropertyDefinitionAsString(prop) + "]");
+
+ if (prop.getDefinition().isProtected()) {
+ tk.createLabel(parent, formatReadOnlyPropertyValue(prop));
+ } else
+ addModifyableValueWidget(parent, part, prop);
+ } catch (RepositoryException re) {
+ throw new ArgeoException("Cannot get property " + prop, re);
+ }
+ }
+
+ private String formatReadOnlyPropertyValue(Property prop) {
+ try {
+ String strValue;
+
+ if (prop.getType() == PropertyType.BINARY)
+ strValue = "<binary>";
+ else if (prop.isMultiple())
+ strValue = Arrays.asList(prop.getValues()).toString();
+ else if (prop.getType() == PropertyType.DATE)
+ strValue = timeFormatter.format(prop.getValue().getDate()
+ .getTime());
+ else
+ strValue = prop.getValue().getString();
+
+ return strValue;
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while formatting read only property value",
+ re);
+ }
+ }
+
+ private Control addModifyableValueWidget(Composite parent,
+ AbstractFormPart part, Property prop) {
+ GridData gd;
+ try {
+ if (prop.getType() == PropertyType.STRING) {
+ Text txt = tk.createText(parent, prop.getString());
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ txt.setLayoutData(gd);
+ txt.addModifyListener(new ModifiedFieldListener(part));
+ txt.setData(JCR_PROPERTY_NAME, prop.getName());
+ modifyableProperties.add(txt);
+ } else {
+ // unsupported property type for editing, we create a read only
+ // label.
+ return tk
+ .createLabel(parent, formatReadOnlyPropertyValue(prop));
+ }
+ return null;
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while formatting read only property value",
+ re);
+ }
+
+ }
+
+ private class ModifiedFieldListener implements ModifyListener {
+ private static final long serialVersionUID = 2117484480773434646L;
+ private AbstractFormPart formPart;
+
+ public ModifiedFieldListener(AbstractFormPart generalPart) {
+ this.formPart = generalPart;
+ }
+
+ public void modifyText(ModifyEvent e) {
+ formPart.markDirty();
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
+import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.eclipse.ui.workbench.internal.jcr.PropertyLabelProvider;
+import org.eclipse.jface.layout.TreeColumnLayout;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ * Generic editor property page. Lists all properties of current node as a
+ * complex tree. TODO: enable editing
+ */
+public class GenericPropertyPage extends FormPage implements WorkbenchConstants {
+ // private final static Log log =
+ // LogFactory.getLog(GenericPropertyPage.class);
+
+ // Main business Objects
+ private Node currentNode;
+
+ public GenericPropertyPage(FormEditor editor, String title, Node currentNode) {
+ super(editor, "id", title);
+ this.currentNode = currentNode;
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ ScrolledForm form = managedForm.getForm();
+ form.setText(WorkbenchUiPlugin.getMessage("genericNodePageTitle"));
+
+ Composite body = form.getBody();
+ FillLayout layout = new FillLayout();
+ layout.marginHeight = 5;
+ layout.marginWidth = 5;
+ body.setLayout(layout);
+ createComplexTree(body);
+ // TODO TreeColumnLayout triggers a scroll issue with the form:
+ // The inside body is always to big and a scroll bar is shown
+ // Composite tableCmp = new Composite(body, SWT.NO_FOCUS);
+ // createComplexTree(tableCmp);
+ }
+
+ private TreeViewer createComplexTree(Composite parent) {
+ int style = SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION;
+ Tree tree = new Tree(parent, style);
+ TreeColumnLayout tableColumnLayout = new TreeColumnLayout();
+
+ createColumn(tree, tableColumnLayout, "Property", SWT.LEFT, 200, 30);
+ createColumn(tree, tableColumnLayout, "Value(s)", SWT.LEFT, 300, 60);
+ createColumn(tree, tableColumnLayout, "Attributes", SWT.LEFT, 75, 0);
+ // Do not apply the treeColumnLayout it does not work yet
+ // parent.setLayout(tableColumnLayout);
+
+ tree.setLinesVisible(true);
+ tree.setHeaderVisible(true);
+
+ TreeViewer treeViewer = new TreeViewer(tree);
+ treeViewer.setContentProvider(new TreeContentProvider());
+ treeViewer.setLabelProvider(new PropertyLabelProvider());
+ treeViewer.setInput(currentNode);
+ treeViewer.expandAll();
+ return treeViewer;
+ }
+
+ private static TreeColumn createColumn(Tree parent,
+ TreeColumnLayout tableColumnLayout, String name, int style,
+ int width, int weight) {
+ TreeColumn column = new TreeColumn(parent, style);
+ column.setText(name);
+ column.setWidth(width);
+ column.setMoveable(true);
+ column.setResizable(true);
+ tableColumnLayout.setColumnData(column, new ColumnWeightData(weight,
+ width, true));
+ return column;
+ }
+
+ //
+ // private void createPropertiesPart(Composite parent) {
+ // try {
+ //
+ // PropertyIterator pi = currentNode.getProperties();
+ //
+ // // Initializes form part
+ // AbstractFormPart part = new AbstractFormPart() {
+ // public void commit(boolean onSave) {
+ // try {
+ // if (onSave) {
+ // ListIterator<Control> it = modifyableProperties
+ // .listIterator();
+ // while (it.hasNext()) {
+ // // we only support Text controls for the time
+ // // being
+ // Text curControl = (Text) it.next();
+ // String value = curControl.getText();
+ // currentNode.setProperty((String) curControl
+ // .getData(JCR_PROPERTY_NAME), value);
+ // }
+ //
+ // // We only commit when onSave = true,
+ // // thus it is still possible to save after a tab
+ // // change.
+ // super.commit(onSave);
+ // }
+ // } catch (RepositoryException re) {
+ // throw new ArgeoException(
+ // "Unexpected error while saving properties", re);
+ // }
+ // }
+ // };
+ //
+ // while (pi.hasNext()) {
+ // Property prop = pi.nextProperty();
+ // addPropertyLine(parent, part, prop);
+ // }
+ //
+ // getManagedForm().addPart(part);
+ // } catch (RepositoryException re) {
+ // throw new ArgeoException(
+ // "Error during creation of network details section", re);
+ // }
+ //
+ // }
+ //
+ // private void addPropertyLine(Composite parent, AbstractFormPart part,
+ // Property prop) {
+ // try {
+ // tk.createLabel(parent, prop.getName());
+ // tk.createLabel(parent,
+ // "[" + JcrUtils.getPropertyDefinitionAsString(prop) + "]");
+ //
+ // if (prop.getDefinition().isProtected()) {
+ // tk.createLabel(parent, formatReadOnlyPropertyValue(prop));
+ // } else
+ // addModifyableValueWidget(parent, part, prop);
+ // } catch (RepositoryException re) {
+ // throw new ArgeoException("Cannot get property " + prop, re);
+ // }
+ // }
+ //
+ // private String formatReadOnlyPropertyValue(Property prop) {
+ // try {
+ // String strValue;
+ //
+ // if (prop.getType() == PropertyType.BINARY)
+ // strValue = "<binary>";
+ // else if (prop.isMultiple())
+ // strValue = Arrays.asList(prop.getValues()).toString();
+ // else if (prop.getType() == PropertyType.DATE)
+ // strValue = timeFormatter.format(prop.getValue().getDate()
+ // .getTime());
+ // else
+ // strValue = prop.getValue().getString();
+ //
+ // return strValue;
+ // } catch (RepositoryException re) {
+ // throw new ArgeoException(
+ // "Unexpected error while formatting read only property value",
+ // re);
+ // }
+ // }
+ //
+ // private Control addModifyableValueWidget(Composite parent,
+ // AbstractFormPart part, Property prop) {
+ // GridData gd;
+ // try {
+ // if (prop.getType() == PropertyType.STRING) {
+ // Text txt = tk.createText(parent, prop.getString());
+ // gd = new GridData(GridData.FILL_HORIZONTAL);
+ // txt.setLayoutData(gd);
+ // txt.addModifyListener(new ModifiedFieldListener(part));
+ // txt.setData(JCR_PROPERTY_NAME, prop.getName());
+ // modifyableProperties.add(txt);
+ // } else {
+ // // unsupported property type for editing, we create a read only
+ // // label.
+ // return tk
+ // .createLabel(parent, formatReadOnlyPropertyValue(prop));
+ // }
+ // return null;
+ // } catch (RepositoryException re) {
+ // throw new ArgeoException(
+ // "Unexpected error while formatting read only property value",
+ // re);
+ // }
+ //
+ // }
+
+ // Multiple Value Model
+ // protected class MultipleValueItem {
+ // private int index;
+ // private Value value;
+ //
+ // public MultipleValueItem(int index, Value value) {
+ // this.index = index;
+ // this.value = value;
+ // }
+ //
+ // public int getIndex() {
+ // return index;
+ // }
+ //
+ // public Object getValue() {
+ // return value;
+ // }
+ // }
+
+ private class TreeContentProvider implements ITreeContentProvider {
+ private static final long serialVersionUID = -6162736530019406214L;
+
+ public Object[] getElements(Object parent) {
+ Object[] props = null;
+ try {
+
+ if (parent instanceof Node) {
+ Node node = (Node) parent;
+ PropertyIterator pi;
+ pi = node.getProperties();
+ List<Property> propList = new ArrayList<Property>();
+ while (pi.hasNext()) {
+ propList.add(pi.nextProperty());
+ }
+ props = propList.toArray();
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception while listing node properties", e);
+ }
+ return props;
+ }
+
+ public Object getParent(Object child) {
+ return null;
+ }
+
+ public Object[] getChildren(Object parent) {
+ Object[] result = null;
+ if (parent instanceof Property) {
+ Property prop = (Property) parent;
+ try {
+
+ if (prop.isMultiple()) {
+ Value[] values = prop.getValues();
+ // List<MultipleValueItem> list = new
+ // ArrayList<MultipleValueItem>();
+ // for (int i = 0; i < values.length; i++) {
+ // MultipleValueItem mvi = new MultipleValueItem(i,
+ // values[i]);
+ // list.add(mvi);
+ // }
+
+ return values;
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected error getting multiple values property.",
+ e);
+ }
+ }
+ return result;
+ }
+
+ public boolean hasChildren(Object parent) {
+ try {
+ if (parent instanceof Property
+ && ((Property) parent).isMultiple()) {
+ return true;
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception while checking if property is multiple",
+ e);
+ }
+ return false;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+import javax.jcr.Binary;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.nodetype.NodeType;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
+import org.argeo.eclipse.ui.specific.UploadFileWizardPage;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.wizard.Wizard;
+
+public class ImportFileSystemWizard extends Wizard {
+ private final static Log log = LogFactory
+ .getLog(ImportFileSystemWizard.class);
+
+ private UploadFileWizardPage importPage;
+ private final Node folder;
+
+ public ImportFileSystemWizard(Node folder) {
+ this.folder = folder;
+ setWindowTitle("Import from file system");
+ }
+
+ @Override
+ public void addPages() {
+ importPage = new UploadFileWizardPage();
+ addPage(importPage);
+ setNeedsProgressMonitor(importPage.getNeedsProgressMonitor());
+ }
+
+ /**
+ * Called when the user click on 'Finish' in the wizard. The real upload to
+ * the JCR repository is done here.
+ */
+ @Override
+ public boolean performFinish() {
+
+ // Initialization
+ final String objectType = importPage.getObjectType();
+ final String objectPath = importPage.getObjectPath();
+
+ // We do not display a progress bar for one file only
+ if (UploadFileWizardPage.FILE_ITEM_TYPE.equals(objectType)) {
+ // In Rap we must force the "real" upload of the file
+ // importPage.performFinish();
+ try {
+ Node fileNode = folder.addNode(importPage.getObjectName(),
+ NodeType.NT_FILE);
+ Node resNode = fileNode.addNode(Property.JCR_CONTENT,
+ NodeType.NT_RESOURCE);
+ Binary binary = null;
+ InputStream is = null;
+ try {
+ is = importPage.getFileInputStream();
+ binary = folder.getSession().getValueFactory()
+ .createBinary(is);
+ resNode.setProperty(Property.JCR_DATA, binary);
+ } finally {
+ if (binary != null)
+ binary.dispose();
+ IOUtils.closeQuietly(is);
+ }
+ folder.getSession().save();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ } else if (UploadFileWizardPage.FOLDER_ITEM_TYPE.equals(objectType)) {
+ if (objectPath == null || !new File(objectPath).exists()) {
+ ErrorFeedback.show("Directory " + objectPath
+ + " does not exist");
+ return false;
+ }
+
+ Boolean failed = false;
+ final File dir = new File(objectPath).getAbsoluteFile();
+ final Long sizeB = directorySize(dir, 0l);
+ final Stats stats = new Stats();
+ Long begin = System.currentTimeMillis();
+ try {
+ getContainer().run(true, true, new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) {
+ try {
+ Integer sizeKB = (int) (sizeB / FileUtils.ONE_KB);
+ monitor.beginTask("", sizeKB);
+ importDirectory(folder, dir, monitor, stats);
+ monitor.done();
+ } catch (Exception e) {
+ if (e instanceof RuntimeException)
+ throw (RuntimeException) e;
+ else
+ throw new ArgeoException("Cannot import "
+ + objectPath, e);
+ }
+ }
+ });
+ } catch (Exception e) {
+ ErrorFeedback.show("Cannot import " + objectPath, e);
+ failed = true;
+ }
+
+ Long duration = System.currentTimeMillis() - begin;
+ Long durationS = duration / 1000l;
+ String durationStr = (durationS / 60) + " min " + (durationS % 60)
+ + " s";
+ StringBuffer message = new StringBuffer("Imported\n");
+ message.append(stats.fileCount).append(" files\n");
+ message.append(stats.dirCount).append(" directories\n");
+ message.append(FileUtils.byteCountToDisplaySize(stats.sizeB));
+ if (failed)
+ message.append(" of planned ").append(
+ FileUtils.byteCountToDisplaySize(sizeB));
+ message.append("\n");
+ message.append("in ").append(durationStr).append("\n");
+ if (failed)
+ MessageDialog.openError(getShell(), "Import failed",
+ message.toString());
+ else
+ MessageDialog.openInformation(getShell(), "Import successful",
+ message.toString());
+
+ return true;
+ }
+ return false;
+
+ }
+
+ /** Recursively computes the size of the directory in bytes. */
+ protected Long directorySize(File dir, Long currentSize) {
+ Long size = currentSize;
+ File[] files = dir.listFiles();
+ for (File file : files) {
+ if (file.isDirectory()) {
+ size = directorySize(file, size);
+ } else {
+ size = size + file.length();
+ }
+ }
+ return size;
+ }
+
+ /**
+ * Import recursively a directory and its content to the repository.
+ */
+ protected void importDirectory(Node folder, File dir,
+ IProgressMonitor monitor, Stats stats) {
+ try {
+ File[] files = dir.listFiles();
+ for (File file : files) {
+ if (file.isDirectory()) {
+ Node childFolder = folder.addNode(file.getName(),
+ NodeType.NT_FOLDER);
+ importDirectory(childFolder, file, monitor, stats);
+ folder.getSession().save();
+ stats.dirCount++;
+ } else {
+ Long fileSize = file.length();
+ // we skip temporary files that are created by apps when a
+ // file is being edited.
+ // TODO : make this configurable.
+ if (file.getName().lastIndexOf('~') != file.getName()
+ .length() - 1) {
+
+ monitor.subTask(file.getName() + " ("
+ + FileUtils.byteCountToDisplaySize(fileSize)
+ + ") " + file.getCanonicalPath());
+ try {
+ Node fileNode = folder.addNode(file.getName(),
+ NodeType.NT_FILE);
+ Node resNode = fileNode.addNode(
+ Property.JCR_CONTENT, NodeType.NT_RESOURCE);
+ Binary binary = null;
+ try {
+ binary = folder
+ .getSession()
+ .getValueFactory()
+ .createBinary(new FileInputStream(file));
+ resNode.setProperty(Property.JCR_DATA, binary);
+ } finally {
+ if (binary != null)
+ binary.dispose();
+ }
+ folder.getSession().save();
+ stats.fileCount++;
+ stats.sizeB = stats.sizeB + fileSize;
+ } catch (Exception e) {
+ log.warn("Import of "
+ + file
+ + " ("
+ + FileUtils
+ .byteCountToDisplaySize(fileSize)
+ + ") failed: " + e);
+ folder.getSession().refresh(false);
+ }
+ monitor.worked((int) (fileSize / FileUtils.ONE_KB));
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot import " + dir + " to " + folder,
+ e);
+ }
+ }
+
+ static class Stats {
+ public Long fileCount = 0l;
+ public Long dirCount = 0l;
+ public Long sizeB = 0l;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import javax.jcr.query.Query;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+public class JcrQueryEditorInput implements IEditorInput {
+ private final String query;
+ private final String queryType;
+
+ public JcrQueryEditorInput(String query, String queryType) {
+ this.query = query;
+ if (queryType == null)
+ this.queryType = Query.JCR_SQL2;
+ else
+ this.queryType = queryType;
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ return query;
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ public String getToolTipText() {
+ return query;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public String getQueryType() {
+ return queryType;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * A canonical editor input based on a path to a node. In a multirepository
+ * environment, path can be enriched with Repository Alias and workspace
+ */
+
+public class NodeEditorInput implements IEditorInput {
+ private final String path;
+
+ public NodeEditorInput(String path) {
+ this.path = path;
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ return path;
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ public String getToolTipText() {
+ return path;
+ }
+
+ public String getPath() {
+ return path;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.security.AccessControlEntry;
+import javax.jcr.security.AccessControlList;
+import javax.jcr.security.AccessControlManager;
+import javax.jcr.security.AccessControlPolicy;
+import javax.jcr.security.AccessControlPolicyIterator;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/** Display and edit a given node rights */
+public class NodePrivilegesPage extends FormPage {
+
+ private Node context;
+
+ private TableViewer viewer;
+
+ public NodePrivilegesPage(FormEditor editor, String title, Node context) {
+ super(editor, "NodePrivilegesPage", title);
+ this.context = context;
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ ScrolledForm form = managedForm.getForm();
+ form.setText(WorkbenchUiPlugin
+ .getMessage("nodeRightsManagementPageTitle"));
+ FillLayout layout = new FillLayout();
+ layout.marginHeight = 5;
+ layout.marginWidth = 5;
+ form.getBody().setLayout(layout);
+ createRightsPart(form.getBody());
+ }
+
+ /** Creates the authorization part */
+ protected void createRightsPart(Composite parent) {
+ Table table = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ table.setLinesVisible(true);
+ table.setHeaderVisible(true);
+ viewer = new TableViewer(table);
+
+ // Group / user name
+ TableViewerColumn column = createTableViewerColumn(viewer,
+ "User/Group Name", 280);
+ column.setLabelProvider(new ColumnLabelProvider() {
+ private static final long serialVersionUID = -2290781173498395973L;
+
+ public String getText(Object element) {
+ Node node = (Node) element;
+ try {
+ if (node.hasProperty("rep:principalName"))
+ return node.getProperty("rep:principalName")
+ .getString();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Unable to retrieve "
+ + "principal name on " + node, e);
+ }
+ return "";
+ }
+
+ public Image getImage(Object element) {
+ return null;
+ }
+ });
+
+ // Privileges
+ column = createTableViewerColumn(viewer, "Assigned privileges", 300);
+ column.setLabelProvider(new ColumnLabelProvider() {
+ private static final long serialVersionUID = -2290781173498395973L;
+ private String propertyName = "rep:privileges";
+
+ public String getText(Object element) {
+ Node node = (Node) element;
+ try {
+ if (node.hasProperty(propertyName)) {
+ String separator = ", ";
+ Value[] langs = node.getProperty(propertyName)
+ .getValues();
+ StringBuilder builder = new StringBuilder();
+ for (Value val : langs) {
+ String currStr = val.getString();
+ builder.append(currStr).append(separator);
+ }
+ if (builder.lastIndexOf(separator) >= 0)
+ return builder.substring(0, builder.length()
+ - separator.length());
+ else
+ return builder.toString();
+
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Unable to retrieve "
+ + "privileges on " + node, e);
+ }
+ return "";
+ }
+
+ public Image getImage(Object element) {
+ return null;
+ }
+ });
+
+ // Relevant node
+ column = createTableViewerColumn(viewer, "Relevant node", 300);
+ column.setLabelProvider(new ColumnLabelProvider() {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 4245522992038244849L;
+
+ public String getText(Object element) {
+ Node node = (Node) element;
+ try {
+ return node.getParent().getParent().getPath();
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Unable get path for " + node, e);
+ }
+ }
+
+ public Image getImage(Object element) {
+ return null;
+ }
+ });
+
+ viewer.setContentProvider(new RightsContentProvider());
+ viewer.setInput(getEditorSite());
+ }
+
+ protected TableViewerColumn createTableViewerColumn(TableViewer viewer,
+ String title, int bound) {
+ final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
+ SWT.NONE);
+ final TableColumn column = viewerColumn.getColumn();
+ column.setText(title);
+ column.setWidth(bound);
+ column.setResizable(true);
+ column.setMoveable(true);
+ return viewerColumn;
+ }
+
+ private class RightsContentProvider implements IStructuredContentProvider {
+ private static final long serialVersionUID = -7631476348552802706L;
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ // TODO JackRabbit specific retrieval of authorization. Clean and
+ // generalize
+ public Object[] getElements(Object inputElement) {
+ try {
+ List<Node> privs = new ArrayList<Node>();
+
+ Node currNode = context;
+ String currPath = currNode.getPath();
+
+ loop: while (true) {
+ if (currNode.hasNode("rep:policy")) {
+ NodeIterator nit = currNode.getNode("rep:policy")
+ .getNodes();
+ while (nit.hasNext()) {
+ Node currPrivNode = nit.nextNode();
+ if (currPrivNode.getName().equals("allow"))
+ privs.add(currPrivNode);
+ }
+ }
+ if ("/".equals(currPath))
+ break loop;
+ else {
+ currNode = currNode.getParent();
+ currPath = currNode.getPath();
+ }
+ }
+
+ AccessControlManager acm = context.getSession()
+ .getAccessControlManager();
+ AccessControlPolicyIterator acpi = acm
+ .getApplicablePolicies(context.getPath());
+
+ List<AccessControlPolicy> acps = new ArrayList<AccessControlPolicy>();
+ try {
+ while (true) {
+ Object obj = acpi.next();
+ acps.add((AccessControlPolicy) obj);
+ }
+ } catch (Exception e) {
+ // No more elements
+ }
+
+ AccessControlList acl = ((AccessControlList) acps.get(0));
+ AccessControlEntry[] entries = acl.getAccessControlEntries();
+
+ return privs.toArray();
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot retrieve authorization for "
+ + context, e);
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Map;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionHistory;
+import javax.jcr.version.VersionIterator;
+import javax.jcr.version.VersionManager;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
+import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.jcr.PropertyDiff;
+import org.argeo.jcr.VersionDiff;
+import org.argeo.eclipse.ui.workbench.internal.jcr.FullVersioningTreeContentProvider;
+import org.argeo.eclipse.ui.workbench.internal.jcr.GenericNodeDoubleClickListener;
+import org.argeo.eclipse.ui.workbench.internal.jcr.VersionLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.AbstractFormPart;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.forms.widgets.TableWrapData;
+import org.eclipse.ui.forms.widgets.TableWrapLayout;
+
+/**
+ * Offers two main sections : one to display a text area with a summary of all
+ * variations between a version and its predecessor and one tree view that
+ * enable browsing
+ * */
+public class NodeVersionHistoryPage extends FormPage implements
+ WorkbenchConstants {
+ // private final static Log log = LogFactory
+ // .getLog(NodeVersionHistoryPage.class);
+
+ // Utils
+ protected DateFormat timeFormatter = new SimpleDateFormat(DATE_TIME_FORMAT);
+
+ // business objects
+ private Node currentNode;
+
+ // this page UI components
+ private FullVersioningTreeContentProvider nodeContentProvider;
+ private TreeViewer nodesViewer;
+ private FormToolkit tk;
+
+ public NodeVersionHistoryPage(FormEditor editor, String title,
+ Node currentNode) {
+ super(editor, "NodeVersionHistoryPage", title);
+ this.currentNode = currentNode;
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ ScrolledForm form = managedForm.getForm();
+ form.setText(WorkbenchUiPlugin
+ .getMessage("nodeVersionHistoryPageTitle"));
+ tk = managedForm.getToolkit();
+ GridLayout twt = new GridLayout(1, false);
+ twt.marginWidth = twt.marginHeight = 5;
+ Composite body = form.getBody();
+ body.setLayout(twt);
+
+ try {
+ if (!currentNode.isNodeType(NodeType.MIX_VERSIONABLE)) {
+ tk.createLabel(body, WorkbenchUiPlugin
+ .getMessage("warningUnversionableNode"));
+ } else {
+ createHistorySection(form.getBody());
+ createTreeSection(form.getBody());
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected error while checking if node is versionable", e);
+ }
+ }
+
+ protected void createTreeSection(Composite parent) {
+ // Section Layout & MetaData
+ Section section = tk.createSection(parent, Section.TWISTIE);
+ section.setLayoutData(new GridData(GridData.FILL_BOTH));
+ section.setText(WorkbenchUiPlugin.getMessage("versionTreeSectionTitle"));
+
+ // Section Body
+ Composite body = tk.createComposite(section, SWT.FILL);
+ // WARNING : 2 following lines are compulsory or body won't be
+ // displayed.
+ body.setLayout(new GridLayout());
+ section.setClient(body);
+
+ body.setLayoutData(new GridData(GridData.FILL_BOTH));
+ section.setExpanded(true);
+
+ nodeContentProvider = new FullVersioningTreeContentProvider();
+ nodesViewer = createNodeViewer(body, nodeContentProvider);
+ nodesViewer.setInput(currentNode);
+ }
+
+ protected TreeViewer createNodeViewer(Composite parent,
+ final ITreeContentProvider nodeContentProvider) {
+
+ final TreeViewer tmpNodeViewer = new TreeViewer(parent, SWT.MULTI);
+
+ tmpNodeViewer.getTree().setLayoutData(
+ new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ tmpNodeViewer.setContentProvider(nodeContentProvider);
+ tmpNodeViewer.setLabelProvider(new VersionLabelProvider());
+ tmpNodeViewer
+ .addDoubleClickListener(new GenericNodeDoubleClickListener(
+ tmpNodeViewer));
+ return tmpNodeViewer;
+ }
+
+ protected void createHistorySection(Composite parent) {
+
+ // Section Layout
+ Section section = tk.createSection(parent, Section.TWISTIE);
+ section.setLayoutData(new GridData(TableWrapData.FILL_GRAB));
+ TableWrapLayout twt = new TableWrapLayout();
+ section.setLayout(twt);
+
+ // Set title of the section
+ section.setText(WorkbenchUiPlugin
+ .getMessage("versionHistorySectionTitle"));
+
+ final Text styledText = tk.createText(section, "", SWT.FULL_SELECTION
+ | SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
+ styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ section.setClient(styledText);
+ refreshHistory(styledText);
+ styledText.setEditable(false);
+ section.setExpanded(false);
+
+ AbstractFormPart part = new AbstractFormPart() {
+ public void commit(boolean onSave) {
+ }
+
+ public void refresh() {
+ super.refresh();
+ refreshHistory(styledText);
+ }
+ };
+ getManagedForm().addPart(part);
+ }
+
+ protected void refreshHistory(Text styledText) {
+ try {
+ List<VersionDiff> lst = listHistoryDiff();
+ StringBuffer main = new StringBuffer("");
+
+ for (int i = lst.size() - 1; i >= 0; i--) {
+ if (i == 0)
+ main.append("Creation (");
+ else
+ main.append("Update " + i + " (");
+
+ if (lst.get(i).getUserId() != null)
+ main.append("UserId : " + lst.get(i).getUserId());
+
+ if (lst.get(i).getUserId() != null
+ && lst.get(i).getUpdateTime() != null)
+ main.append(", ");
+
+ if (lst.get(i).getUpdateTime() != null)
+ main.append("Date : "
+ + timeFormatter.format(lst.get(i).getUpdateTime()
+ .getTime()) + ")\n");
+
+ StringBuffer buf = new StringBuffer("");
+ Map<String, PropertyDiff> diffs = lst.get(i).getDiffs();
+ for (String prop : diffs.keySet()) {
+ PropertyDiff pd = diffs.get(prop);
+ // String propName = pd.getRelPath();
+ Value refValue = pd.getReferenceValue();
+ Value newValue = pd.getNewValue();
+ String refValueStr = "";
+ String newValueStr = "";
+
+ if (refValue != null) {
+ if (refValue.getType() == PropertyType.DATE) {
+ refValueStr = timeFormatter.format(refValue
+ .getDate().getTime());
+ } else
+ refValueStr = refValue.getString();
+ }
+ if (newValue != null) {
+ if (newValue.getType() == PropertyType.DATE) {
+ newValueStr = timeFormatter.format(newValue
+ .getDate().getTime());
+ } else
+ newValueStr = newValue.getString();
+ }
+
+ if (pd.getType() == PropertyDiff.MODIFIED) {
+ buf.append(prop).append(": ");
+ buf.append(refValueStr);
+ buf.append(" > ");
+ buf.append(newValueStr);
+ buf.append("\n");
+ } else if (pd.getType() == PropertyDiff.ADDED
+ && !"".equals(newValueStr)) {
+ // we don't list property that have been added with an
+ // empty string as value
+ buf.append(prop).append(": ");
+ buf.append(" + ");
+ buf.append(newValueStr);
+ buf.append("\n");
+ } else if (pd.getType() == PropertyDiff.REMOVED) {
+ buf.append(prop).append(": ");
+ buf.append(" - ");
+ buf.append(refValueStr);
+ buf.append("\n");
+ }
+ }
+ buf.append("\n");
+ main.append(buf);
+ }
+ styledText.setText(main.toString());
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot generate history for node", e);
+ }
+
+ }
+
+ public List<VersionDiff> listHistoryDiff() {
+ try {
+ List<VersionDiff> res = new ArrayList<VersionDiff>();
+ VersionManager versionManager = currentNode.getSession()
+ .getWorkspace().getVersionManager();
+ VersionHistory versionHistory = versionManager
+ .getVersionHistory(currentNode.getPath());
+
+ VersionIterator vit = versionHistory.getAllLinearVersions();
+ while (vit.hasNext()) {
+ Version version = vit.nextVersion();
+ Node node = version.getFrozenNode();
+ Version predecessor = null;
+ try {
+ predecessor = version.getLinearPredecessor();
+ } catch (Exception e) {
+ // no predecessor seems to throw an exception even if it
+ // shouldn't...
+ }
+ if (predecessor == null) {// original
+ } else {
+ Map<String, PropertyDiff> diffs = JcrUtils.diffProperties(
+ predecessor.getFrozenNode(), node);
+ if (!diffs.isEmpty()) {
+ String lastUserName = null;
+ Calendar lastUpdate = null;
+ try {
+ if (currentNode
+ .isNodeType(NodeType.MIX_LAST_MODIFIED)) {
+ lastUserName = node.getProperty(
+ Property.JCR_LAST_MODIFIED_BY)
+ .getString();
+ lastUpdate = node.getProperty(
+ Property.JCR_LAST_MODIFIED).getDate();
+ } else
+ lastUpdate = version.getProperty(
+ Property.JCR_CREATED).getDate();
+
+ } catch (Exception e) {
+ // Silent that info is optional
+ }
+ VersionDiff vd = new VersionDiff(lastUserName,
+ lastUpdate, diffs);
+ res.add(vd);
+ }
+ }
+ }
+ return res;
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot generate history for node ");
+ }
+
+ }
+
+ @Override
+ public void setActive(boolean active) {
+ super.setActive(active);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.jcr.parts;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * An editor input based on three strings define a node :
+ * <ul>
+ * <li>complete path to the node</li>
+ * <li>the workspace name</li>
+ * <li>the repository alias</li>
+ * </ul>
+ * In a single workspace and/or repository environment, name and alias can be
+ * null.
+ *
+ * Note : unused for the time being.
+ */
+
+public class StringNodeEditorInput implements IEditorInput {
+ private final String path;
+ private final String repositoryAlias;
+ private final String workspaceName;
+
+ /**
+ * In order to implement a generic explorer that supports remote and multi
+ * workspaces repositories, node path can be detailed by these strings.
+ *
+ * @param repositoryAlias
+ * : can be null
+ * @param workspaceName
+ * : can be null
+ * @param path
+ */
+ public StringNodeEditorInput(String repositoryAlias, String workspaceName,
+ String path) {
+ this.path = path;
+ this.repositoryAlias = repositoryAlias;
+ this.workspaceName = workspaceName;
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ public String getName() {
+ return path;
+ }
+
+ public String getRepositoryAlias() {
+ return repositoryAlias;
+ }
+
+ public String getWorkspaceName() {
+ return workspaceName;
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ public String getToolTipText() {
+ return path;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+
+ StringNodeEditorInput other = (StringNodeEditorInput) obj;
+
+ if (!path.equals(other.getPath()))
+ return false;
+
+ String own = other.getWorkspaceName();
+ if ((workspaceName == null && own != null)
+ || (workspaceName != null && (own == null || !workspaceName
+ .equals(own))))
+ return false;
+
+ String ora = other.getRepositoryAlias();
+ if ((repositoryAlias == null && ora != null)
+ || (repositoryAlias != null && (ora == null || !repositoryAlias
+ .equals(ora))))
+ return false;
+
+ return true;
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.eclipse.ui.workbench.internal.users;
+
+import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
+import org.eclipse.swt.graphics.Image;
+
+/** Specific users icons. TODO centralize and use an image registry */
+public class UsersImages {
+ private final static String PREFIX = "icons/";
+
+ public final static Image ICON_USER = WorkbenchUiPlugin.getImageDescriptor(
+ PREFIX + "user.gif").createImage();
+ public final static Image ICON_GROUP = WorkbenchUiPlugin
+ .getImageDescriptor(PREFIX + "users.gif").createImage();
+ public final static Image ICON_ROLE = WorkbenchUiPlugin.getImageDescriptor(
+ PREFIX + "role.gif").createImage();
+}
--- /dev/null
+package org.argeo.eclipse.ui.workbench.internal.users;
+
+import java.security.AccessController;
+import java.util.List;
+
+import javax.naming.InvalidNameException;
+import javax.naming.ldap.LdapName;
+import javax.naming.ldap.Rdn;
+import javax.security.auth.Subject;
+import javax.security.auth.x500.X500Principal;
+
+import org.argeo.ArgeoException;
+import org.argeo.osgi.useradmin.LdifName;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
+
+/** Utility methods to manage user concepts in the ui.workbench bundle */
+public class UsersUtils {
+ // TODO this constant is defined in the CMS
+ public final static String ROLES_BASEDN = "ou=roles,ou=node";
+
+ public final static boolean isCurrentUser(User user) {
+ String userName = getProperty(user, LdifName.dn.name());
+ try {
+ LdapName selfUserName = getLdapName();
+ LdapName userLdapName = new LdapName(userName);
+ if (userLdapName.equals(selfUserName))
+ return true;
+ else
+ return false;
+ } catch (InvalidNameException e) {
+ throw new ArgeoException("User " + user + " has an unvalid dn: "
+ + userName, e);
+ }
+ }
+
+ public final static LdapName getLdapName() {
+ Subject subject = Subject.getSubject(AccessController.getContext());
+ String name = subject.getPrincipals(X500Principal.class).iterator()
+ .next().toString();
+ LdapName dn;
+ try {
+ dn = new LdapName(name);
+ } catch (InvalidNameException e) {
+ throw new ArgeoException("Invalid user dn " + name, e);
+ }
+ return dn;
+ }
+
+ public final static String getCommonName(User user) {
+ return getProperty(user, LdifName.cn.name());
+ }
+
+ /** Simply retrieves a display name of the relevant domain */
+ public final static String getDomainName(User user) {
+ String dn = (String) user.getProperties().get(LdifName.dn.name());
+ if (dn.endsWith(ROLES_BASEDN))
+ return "System roles";
+ try {
+ LdapName name;
+ name = new LdapName(dn);
+ List<Rdn> rdns = name.getRdns();
+ String dname = null;
+ int i = 0;
+ loop: while (i < rdns.size()) {
+ Rdn currrRdn = rdns.get(i);
+ if (!"dc".equals(currrRdn.getType()))
+ break loop;
+ else {
+ String currVal = (String) currrRdn.getValue();
+ dname = dname == null ? currVal : currVal + "." + dname;
+ }
+ i++;
+ }
+ return dname;
+ } catch (InvalidNameException e) {
+ throw new ArgeoException("Unable to get domain name for " + dn, e);
+ }
+ }
+
+ public final static String getProperty(Role role, String key) {
+ Object obj = role.getProperties().get(key);
+ if (obj != null)
+ return (String) obj;
+ else
+ return "";
+ }
+
+ /*
+ * INTERNAL METHODS: Below methods are meant to stay here and are not part
+ * of a potential generic backend to manage the useradmin
+ */
+ public final static boolean notNull(String string) {
+ if (string == null)
+ return false;
+ else
+ return !"".equals(string.trim());
+ }
+
+}
\ No newline at end of file
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.ChildNodesPage;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.GenericNodeEditorInput;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.GenericPropertyPage;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.NodePrivilegesPage;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.NodeVersionHistoryPage;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.ChildNodesPage;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.GenericNodeEditorInput;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.GenericPropertyPage;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.NodePrivilegesPage;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.NodeVersionHistoryPage;
import org.argeo.jcr.JcrUtils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.IEditorInput;
package org.argeo.eclipse.ui.workbench.jcr;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.AbstractJcrQueryEditor;
+import org.argeo.eclipse.ui.workbench.internal.jcr.parts.AbstractJcrQueryEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.argeo.eclipse.ui.jcr.AsyncUiEventListener;
import org.argeo.eclipse.ui.jcr.utils.NodeViewerComparer;
import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.internal.GenericNodeDoubleClickListener;
-import org.argeo.eclipse.ui.workbench.jcr.internal.JcrBrowserUtils;
-import org.argeo.eclipse.ui.workbench.jcr.internal.NodeContentProvider;
-import org.argeo.eclipse.ui.workbench.jcr.internal.NodeLabelProvider;
-import org.argeo.eclipse.ui.workbench.jcr.internal.PropertiesContentProvider;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
+import org.argeo.eclipse.ui.workbench.internal.jcr.GenericNodeDoubleClickListener;
+import org.argeo.eclipse.ui.workbench.internal.jcr.JcrBrowserUtils;
+import org.argeo.eclipse.ui.workbench.internal.jcr.NodeContentProvider;
+import org.argeo.eclipse.ui.workbench.internal.jcr.NodeLabelProvider;
+import org.argeo.eclipse.ui.workbench.internal.jcr.PropertiesContentProvider;
+import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem;
import org.argeo.jcr.RepositoryRegister;
import org.argeo.util.security.Keyring;
import org.eclipse.jface.action.MenuManager;
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.version.Version;
-import javax.jcr.version.VersionHistory;
-import javax.jcr.version.VersionIterator;
-import javax.jcr.version.VersionManager;
-
-import org.argeo.ArgeoException;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-/**
- * Display some version information of a JCR full versionable node in a tree
- * like structure
- */
-public class FullVersioningTreeContentProvider implements ITreeContentProvider {
- private static final long serialVersionUID = 8691772509491211112L;
-
- /**
- * Sends back the first level of the Tree. input element must be a single
- * node object
- */
- public Object[] getElements(Object inputElement) {
- try {
- Node rootNode = (Node) inputElement;
- String curPath = rootNode.getPath();
- VersionManager vm = rootNode.getSession().getWorkspace()
- .getVersionManager();
-
- VersionHistory vh = vm.getVersionHistory(curPath);
- List<Version> result = new ArrayList<Version>();
- VersionIterator vi = vh.getAllLinearVersions();
-
- while (vi.hasNext()) {
- result.add(vi.nextVersion());
- }
- return result.toArray();
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while getting version elements", re);
- }
- }
-
- public Object[] getChildren(Object parentElement) {
- try {
- if (parentElement instanceof Version) {
- List<Node> tmp = new ArrayList<Node>();
- tmp.add(((Version) parentElement).getFrozenNode());
- return tmp.toArray();
- }
- } catch (RepositoryException re) {
- throw new ArgeoException("Unexpected error while getting child "
- + "node for version element", re);
- }
- return null;
- }
-
- public Object getParent(Object element) {
- try {
- // this will not work in a simpleVersionning environment, parent is
- // not a node.
- if (element instanceof Node
- && ((Node) element).isNodeType(NodeType.NT_FROZEN_NODE)) {
- Node node = (Node) element;
- return node.getParent();
- } else
- return null;
- } catch (RepositoryException e) {
- return null;
- }
- }
-
- public boolean hasChildren(Object element) {
- try {
- if (element instanceof Version)
- return true;
- else if (element instanceof Node)
- return ((Node) element).hasNodes();
- else
- 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) {
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.NodeType;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.DefaultNodeEditor;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoryElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.parts.GenericNodeEditorInput;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.ui.PartInitException;
-
-/** Centralizes the management of double click on a NodeTreeViewer */
-public class GenericNodeDoubleClickListener implements IDoubleClickListener {
- // private final static Log log = LogFactory
- // .getLog(GenericNodeDoubleClickListener.class);
-
- private TreeViewer nodeViewer;
-
- // private JcrFileProvider jfp;
- // private FileHandler fileHandler;
-
- public GenericNodeDoubleClickListener(TreeViewer nodeViewer) {
- this.nodeViewer = nodeViewer;
- // jfp = new JcrFileProvider();
- // Commented out. see https://www.argeo.org/bugzilla/show_bug.cgi?id=188
- // fileHandler = null;
- // fileHandler = new FileHandler(jfp);
- }
-
- public void doubleClick(DoubleClickEvent event) {
- if (event.getSelection() == null || event.getSelection().isEmpty())
- return;
- Object obj = ((IStructuredSelection) event.getSelection())
- .getFirstElement();
- if (obj instanceof RepositoryElem) {
- RepositoryElem rpNode = (RepositoryElem) obj;
- if (!rpNode.isConnected()) {
- rpNode.login();
- nodeViewer.refresh(obj);
- }
- } else if (obj instanceof WorkspaceElem) {
- WorkspaceElem wn = (WorkspaceElem) obj;
- if (wn.isConnected())
- wn.logout();
- else
- wn.login();
- nodeViewer.refresh(obj);
- } else if (obj instanceof SingleJcrNodeElem) {
- SingleJcrNodeElem sjn = (SingleJcrNodeElem) obj;
- Node node = sjn.getNode();
- try {
- if (node.isNodeType(NodeType.NT_FILE)) {
- // double click on a file node triggers its opening
- // String name = node.getName();
- // String id = node.getIdentifier();
-
- // TODO add integration of direct retrieval of the binary in
- // a JCR repo.
- // Map<String, String> params = new HashMap<String,
- // String>();
- // params.put(OpenFile.PARAM_FILE_NAME, name);
- // params.put(OpenFile.PARAM_FILE_URI, "jcr://" + id);
- // CommandUtils
- // .callCommand("org.argeo.security.ui.specific.openFile",
- // params);
-
- // For the file provider to be able to browse the
- // various
- // repository.
- // TODO : enhanced that.
- // ITreeContentProvider itcp = (ITreeContentProvider)
- // nodeViewer
- // .getContentProvider();
- // jfp.setReferenceNode(node);
- // if (fileHandler != null)
- // fileHandler.openFile(name, id);
- }
- GenericNodeEditorInput gnei = new GenericNodeEditorInput(node);
- WorkbenchUiPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow().getActivePage()
- .openEditor(gnei, DefaultNodeEditor.ID);
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Repository error while getting node info", re);
- } catch (PartInitException pie) {
- throw new ArgeoException(
- "Unexepected exception while opening node editor", pie);
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoriesElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoryElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
-
-/** Centralizes useful methods to manage the JCR Browser */
-public class JcrBrowserUtils {
-
- /** Insure that the UI component is not stale, refresh if needed */
- public static void forceRefreshIfNeeded(TreeParent element) {
- Node curNode = null;
-
- boolean doRefresh = false;
-
- try {
- if (element instanceof SingleJcrNodeElem) {
- curNode = ((SingleJcrNodeElem) element).getNode();
- } else if (element instanceof WorkspaceElem) {
- curNode = ((WorkspaceElem) element).getRootNode();
- }
-
- if (curNode != null
- && element.getChildren().length != curNode.getNodes()
- .getSize())
- doRefresh = true;
- else if (element instanceof RepositoryElem) {
- RepositoryElem rn = (RepositoryElem) element;
- if (rn.isConnected()) {
- String[] wkpNames = rn.getAccessibleWorkspaceNames();
- if (element.getChildren().length != wkpNames.length)
- doRefresh = true;
- }
- } else if (element instanceof RepositoriesElem) {
- doRefresh = true;
- // Always force refresh for RepositoriesElem : the condition
- // below does not take remote repository into account and it is
- // not trivial to do so.
-
- // RepositoriesElem rn = (RepositoriesElem) element;
- // if (element.getChildren().length !=
- // rn.getRepositoryRegister()
- // .getRepositories().size())
- // doRefresh = true;
- }
- if (doRefresh) {
- element.clearChildren();
- element.getChildren();
- }
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while synchronising the UI with the JCR repository",
- re);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.RepositoryFactory;
-import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
-
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.jcr.ArgeoJcrConstants;
-import org.argeo.jcr.RepositoryRegister;
-import org.argeo.jcr.UserJcrUtils;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoriesElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
-import org.argeo.util.security.Keyring;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-/**
- * Implementation of the {@code ITreeContentProvider} to display multiple
- * repository environment in a tree like structure
- */
-public class NodeContentProvider implements ITreeContentProvider {
- private static final long serialVersionUID = -4083809398848374403L;
- final private RepositoryRegister repositoryRegister;
- final private RepositoryFactory repositoryFactory;
-
- // Current user session on the default workspace of the argeo Node
- final private Session userSession;
- final private Keyring keyring;
- private boolean sortChildren;
-
- // Reference for cleaning
- private SingleJcrNodeElem homeNode = null;
- private RepositoriesElem repositoriesNode = null;
-
- // Utils
- private TreeBrowserComparator itemComparator = new TreeBrowserComparator();
-
- public NodeContentProvider(Session userSession, Keyring keyring,
- RepositoryRegister repositoryRegister,
- RepositoryFactory repositoryFactory, Boolean sortChildren) {
- this.userSession = userSession;
- this.keyring = keyring;
- this.repositoryRegister = repositoryRegister;
- this.repositoryFactory = repositoryFactory;
- this.sortChildren = sortChildren;
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if (newInput == null)// dispose
- return;
-
- if (userSession != null) {
- Node userHome = UserJcrUtils.getUserHome(userSession);
- if (userHome != null) {
- // TODO : find a way to dynamically get alias for the node
- if (homeNode != null)
- homeNode.dispose();
- homeNode = new SingleJcrNodeElem(null, userHome,
- userSession.getUserID(), ArgeoJcrConstants.ALIAS_NODE);
- }
- }
- if (repositoryRegister != null) {
- if (repositoriesNode != null)
- repositoriesNode.dispose();
- repositoriesNode = new RepositoriesElem("Repositories",
- repositoryRegister, repositoryFactory, null, userSession,
- keyring);
- }
- }
-
- /**
- * Sends back the first level of the Tree. Independent from inputElement
- * that can be null
- */
- public Object[] getElements(Object inputElement) {
- List<Object> objs = new ArrayList<Object>();
- if (homeNode != null)
- objs.add(homeNode);
- if (repositoriesNode != null)
- objs.add(repositoriesNode);
- return objs.toArray();
- }
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof TreeParent) {
- if (sortChildren) {
- Object[] tmpArr = ((TreeParent) parentElement).getChildren();
- if (tmpArr == null)
- return new Object[0];
- TreeParent[] arr = new TreeParent[tmpArr.length];
- for (int i = 0; i < tmpArr.length; i++)
- arr[i] = (TreeParent) tmpArr[i];
- Arrays.sort(arr, itemComparator);
- return arr;
- } else
- return ((TreeParent) parentElement).getChildren();
- } else
- return new Object[0];
- }
-
- /**
- * Sets whether the content provider should order the children nodes or not.
- * It is user duty to call a full refresh of the tree after changing this
- * parameter.
- */
- public void setSortChildren(boolean sortChildren) {
- this.sortChildren = sortChildren;
- }
-
- public Object getParent(Object element) {
- if (element instanceof TreeParent) {
- return ((TreeParent) element).getParent();
- } else
- return null;
- }
-
- public boolean hasChildren(Object element) {
- if (element instanceof RepositoriesElem) {
- RepositoryRegister rr = ((RepositoriesElem) element)
- .getRepositoryRegister();
- return rr.getRepositories().size() > 0;
- } else if (element instanceof TreeParent) {
- TreeParent tp = (TreeParent) element;
- return tp.hasChildren();
- }
- return false;
- }
-
- public void dispose() {
- if (homeNode != null)
- homeNode.dispose();
- if (repositoriesNode != null) {
- // logs out open sessions
- // see https://bugzilla.argeo.org/show_bug.cgi?id=23
- repositoriesNode.dispose();
- }
- }
-
- /**
- * Specific comparator for this view. See specification here:
- * https://www.argeo.org/bugzilla/show_bug.cgi?id=139
- */
- private class TreeBrowserComparator implements Comparator<TreeParent> {
-
- public int category(TreeParent element) {
- if (element instanceof SingleJcrNodeElem) {
- Node node = ((SingleJcrNodeElem) element).getNode();
- try {
- if (node.isNodeType(NodeType.NT_FOLDER))
- return 5;
- } catch (RepositoryException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return 10;
- }
-
- public int compare(TreeParent o1, TreeParent o2) {
- int cat1 = category(o1);
- int cat2 = category(o2);
-
- if (cat1 != cat2) {
- return cat1 - cat2;
- }
- return o1.getName().compareTo(o2.getName());
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.NodeType;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.workbench.jcr.JcrImages;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.RemoteRepositoryElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoriesElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoryElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
-import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
-import org.argeo.jcr.ArgeoTypes;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.swt.graphics.Image;
-
-/** Provides reasonable defaults for know JCR types. */
-public class NodeLabelProvider extends ColumnLabelProvider {
- private static final long serialVersionUID = -3662051696443321843L;
-
- private final static Log log = LogFactory.getLog(NodeLabelProvider.class);
-
- public String getText(Object element) {
- try {
- if (element instanceof SingleJcrNodeElem) {
- SingleJcrNodeElem sjn = (SingleJcrNodeElem) element;
- return getText(sjn.getNode());
- } else if (element instanceof Node) {
- return getText((Node) element);
- } else
- return super.getText(element);
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected JCR error while getting node name.");
- }
- }
-
- protected String getText(Node node) throws RepositoryException {
- String label = node.getName();
- StringBuffer mixins = new StringBuffer("");
- for (NodeType type : node.getMixinNodeTypes())
- mixins.append(' ').append(type.getName());
-
- return label + " [" + node.getPrimaryNodeType().getName() + mixins
- + "]";
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof RemoteRepositoryElem) {
- if (((RemoteRepositoryElem) element).isConnected())
- return JcrImages.REMOTE_CONNECTED;
- else
- return JcrImages.REMOTE_DISCONNECTED;
- } else if (element instanceof RepositoryElem) {
- if (((RepositoryElem) element).isConnected())
- return JcrImages.REPOSITORY_CONNECTED;
- else
- return JcrImages.REPOSITORY_DISCONNECTED;
- } else if (element instanceof WorkspaceElem) {
- if (((WorkspaceElem) element).isConnected())
- return JcrImages.WORKSPACE_CONNECTED;
- else
- return JcrImages.WORKSPACE_DISCONNECTED;
- } else if (element instanceof RepositoriesElem) {
- return JcrImages.REPOSITORIES;
- } else if (element instanceof SingleJcrNodeElem) {
- Node nodeElem = ((SingleJcrNodeElem) element).getNode();
- return getImage(nodeElem);
-
- // if (element instanceof Node) {
- // return getImage((Node) element);
- // } else if (element instanceof WrappedNode) {
- // return getImage(((WrappedNode) element).getNode());
- // } else if (element instanceof NodesWrapper) {
- // return getImage(((NodesWrapper) element).getNode());
- // }
- }
- // try {
- // return super.getImage();
- // } catch (RepositoryException e) {
- // return null;
- // }
- return super.getImage(element);
- }
-
- protected Image getImage(Node node) {
- try {
- if (node.getPrimaryNodeType().isNodeType(NodeType.NT_FILE))
- return JcrImages.FILE;
- else if (node.getPrimaryNodeType().isNodeType(NodeType.NT_FOLDER))
- return JcrImages.FOLDER;
- else if (node.getPrimaryNodeType().isNodeType(NodeType.NT_RESOURCE))
- return JcrImages.BINARY;
- else if (node.isNodeType(ArgeoTypes.ARGEO_USER_HOME))
- return JcrImages.HOME;
- else
- return JcrImages.NODE;
- } catch (RepositoryException e) {
- log.warn("Error while retrieving type for " + node
- + " in order to display corresponding image");
- e.printStackTrace();
- return null;
- }
-
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal;
-
-import java.util.Set;
-import java.util.TreeSet;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.RepositoryException;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.jcr.utils.JcrItemsComparator;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-public class PropertiesContentProvider implements IStructuredContentProvider {
- private static final long serialVersionUID = 5227554668841613078L;
- private JcrItemsComparator itemComparator = new JcrItemsComparator();
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- public Object[] getElements(Object inputElement) {
- try {
- if (inputElement instanceof Node) {
- Set<Property> props = new TreeSet<Property>(itemComparator);
- PropertyIterator pit = ((Node) inputElement).getProperties();
- while (pit.hasNext())
- props.add(pit.nextProperty());
- return props.toArray();
- }
- return new Object[] {};
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot get element for " + inputElement,
- e);
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-
-import javax.jcr.Property;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
-import org.argeo.jcr.JcrUtils;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ViewerCell;
-
-/** Default basic label provider for a given JCR Node's properties */
-public class PropertyLabelProvider extends ColumnLabelProvider implements
- WorkbenchConstants {
- private static final long serialVersionUID = -5405794508731390147L;
-
- // To be able to change column order easily
- public static final int COLUMN_PROPERTY = 0;
- public static final int COLUMN_VALUE = 1;
- public static final int COLUMN_ATTRIBUTES = 2;
-
- // Utils
- protected DateFormat timeFormatter = new SimpleDateFormat(DATE_TIME_FORMAT);
-
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- cell.setText(getColumnText(element, cell.getColumnIndex()));
- }
-
- public String getColumnText(Object element, int columnIndex) {
- try {
- if (element instanceof Property) {
- Property prop = (Property) element;
- if (prop.isMultiple()) {
- switch (columnIndex) {
- case COLUMN_PROPERTY:
- return prop.getName();
- case COLUMN_VALUE:
- // Corresponding values are listed on children
- return "";
- case COLUMN_ATTRIBUTES:
- return JcrUtils.getPropertyDefinitionAsString(prop);
- }
- } else {
- switch (columnIndex) {
- case COLUMN_PROPERTY:
- return prop.getName();
- case COLUMN_VALUE:
- return formatValueAsString(prop.getValue());
- case COLUMN_ATTRIBUTES:
- return JcrUtils.getPropertyDefinitionAsString(prop);
- }
- }
- } else if (element instanceof Value) {
- Value val = (Value) element;
-
- switch (columnIndex) {
- case COLUMN_PROPERTY:
- // Nothing to show
- return "";
- case COLUMN_VALUE:
- return formatValueAsString(val);
- case COLUMN_ATTRIBUTES:
- // Corresponding attributes are listed on the parent
- return "";
- }
- }
-
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexepected error while getting property values", re);
- }
- return null;
- }
-
- private String formatValueAsString(Value value) {
- // TODO enhance this method
- try {
- String strValue;
-
- if (value.getType() == PropertyType.BINARY)
- strValue = "<binary>";
- else if (value.getType() == PropertyType.DATE)
- strValue = timeFormatter.format(value.getDate().getTime());
- else
- strValue = value.getString();
- return strValue;
- } catch (RepositoryException e) {
- throw new ArgeoException("unexpected error while formatting value",
- e);
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.jcr.utils.JcrItemsComparator;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-/**
- * Implementation of the {@code ITreeContentProvider} in order to display a
- * single JCR node and its children in a tree like structure
- */
-public class SingleNodeAsTreeContentProvider implements ITreeContentProvider {
- private static final long serialVersionUID = -2128326504754297297L;
- // private Node rootNode;
- private JcrItemsComparator itemComparator = new JcrItemsComparator();
-
- /**
- * Sends back the first level of the Tree. input element must be a single
- * node object
- */
- public Object[] getElements(Object inputElement) {
- try {
- Node rootNode = (Node) inputElement;
- List<Node> result = new ArrayList<Node>();
- NodeIterator ni = rootNode.getNodes();
- while (ni.hasNext()) {
- result.add(ni.nextNode());
- }
-
- return result.toArray();
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while getting child nodes for children editor page ",
- re);
- }
- }
-
- public Object[] getChildren(Object parentElement) {
- return childrenNodes((Node) parentElement);
- }
-
- public Object getParent(Object element) {
- try {
- Node node = (Node) element;
- if (!node.getPath().equals("/"))
- return node.getParent();
- else
- return null;
- } catch (RepositoryException e) {
- return null;
- }
- }
-
- public boolean hasChildren(Object element) {
- try {
- return ((Node) element).hasNodes();
- } 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);
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.version.Version;
-
-import org.argeo.ArgeoException;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-
-/**
- * Simple wrapping of the ColumnLabelProvider class to provide text display in
- * order to build a tree for version. The getText() method does not assume that
- * {@link Version} extends {@link Node} class to respect JCR 2.0 specification
- *
- */
-public class VersionLabelProvider extends ColumnLabelProvider {
- private static final long serialVersionUID = 5270739851193688238L;
-
- public String getText(Object element) {
- try {
- if (element instanceof Version) {
- Version version = (Version) element;
- return version.getName();
- } else if (element instanceof Node) {
- return ((Node) element).getName();
- }
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while getting element name", re);
- }
- return super.getText(element);
- }
-}
+++ /dev/null
-package org.argeo.eclipse.ui.workbench.jcr.internal.model;
-
-import javax.jcr.Repository;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.jcr.MaintainedRepository;
-
-/** Wrap a {@link MaintainedRepository} */
-public class MaintainedRepositoryElem extends RepositoryElem {
-
- public MaintainedRepositoryElem(String alias, Repository repository,
- TreeParent parent) {
- super(alias, repository, parent);
- if (!(repository instanceof MaintainedRepository)) {
- throw new ArgeoException("Repository " + alias
- + " is not amiantained repository");
- }
- }
-
- protected MaintainedRepository getMaintainedRepository() {
- return (MaintainedRepository) getRepository();
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.model;
-
-import java.util.Arrays;
-
-import javax.jcr.Node;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.RepositoryFactory;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.jcr.ArgeoJcrUtils;
-import org.argeo.jcr.ArgeoNames;
-import org.argeo.util.security.Keyring;
-
-/** Root of a remote repository */
-public class RemoteRepositoryElem extends RepositoryElem {
- private final Keyring keyring;
- /**
- * A session of the logged in user on the default workspace of the node
- * repository.
- */
- private final Session userSession;
- private final String remoteNodePath;
-
- private final RepositoryFactory repositoryFactory;
- private final String uri;
-
- public RemoteRepositoryElem(String alias,
- RepositoryFactory repositoryFactory, String uri, TreeParent parent,
- Session userSession, Keyring keyring, String remoteNodePath) {
- super(alias, null, parent);
- this.repositoryFactory = repositoryFactory;
- this.uri = uri;
- this.keyring = keyring;
- this.userSession = userSession;
- this.remoteNodePath = remoteNodePath;
- }
-
- @Override
- protected Session repositoryLogin(String workspaceName)
- throws RepositoryException {
- Node remoteRepository = userSession.getNode(remoteNodePath);
- String userID = remoteRepository.getProperty(ArgeoNames.ARGEO_USER_ID)
- .getString();
- String pwdPath = remoteRepository.getPath() + '/'
- + ArgeoNames.ARGEO_PASSWORD;
- char[] password = keyring.getAsChars(pwdPath);
-
- try {
- SimpleCredentials credentials = new SimpleCredentials(userID,
- password);
- return getRepository().login(credentials, workspaceName);
- } finally {
- Arrays.fill(password, 0, password.length, ' ');
- }
- }
-
- @Override
- public Repository getRepository() {
- if (repository == null)
- repository = ArgeoJcrUtils.getRepositoryByUri(repositoryFactory,
- uri);
- return super.getRepository();
- }
-
- public void remove() {
- try {
- Node remoteNode = userSession.getNode(remoteNodePath);
- remoteNode.remove();
- remoteNode.getSession().save();
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot remove " + remoteNodePath, e);
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.model;
-
-import java.util.Map;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.RepositoryFactory;
-import javax.jcr.Session;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
-import org.argeo.jcr.ArgeoNames;
-import org.argeo.jcr.MaintainedRepository;
-import org.argeo.jcr.RepositoryRegister;
-import org.argeo.jcr.UserJcrUtils;
-import org.argeo.util.security.Keyring;
-
-/**
- * UI Tree component that 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 RepositoriesElem extends TreeParent implements ArgeoNames {
- private final RepositoryRegister repositoryRegister;
- private final RepositoryFactory repositoryFactory;
-
- /**
- * A session of the logged in user on the default workspace of the node
- * repository.
- */
- private final Session userSession;
- private final Keyring keyring;
-
- public RepositoriesElem(String name, RepositoryRegister repositoryRegister,
- RepositoryFactory repositoryFactory, TreeParent parent,
- Session userSession, Keyring keyring) {
- super(name);
- this.repositoryRegister = repositoryRegister;
- this.repositoryFactory = repositoryFactory;
- this.userSession = userSession;
- this.keyring = keyring;
- }
-
- /**
- * Override normal behavior 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()) {
- Repository repository = refRepos.get(name);
- if (repository instanceof MaintainedRepository)
- super.addChild(new MaintainedRepositoryElem(name,
- repository, this));
- else
- super.addChild(new RepositoryElem(name, repository, this));
- }
-
- // remote
- if (keyring != null) {
- try {
- addRemoteRepositories(keyring);
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Cannot browse remote repositories", e);
- }
- }
- return super.getChildren();
- }
- }
-
- protected void addRemoteRepositories(Keyring jcrKeyring)
- throws RepositoryException {
- Node userHome = UserJcrUtils.getUserHome(userSession);
- if (userHome != null && userHome.hasNode(ARGEO_REMOTE)) {
- NodeIterator it = userHome.getNode(ARGEO_REMOTE).getNodes();
- while (it.hasNext()) {
- Node remoteNode = it.nextNode();
- String uri = remoteNode.getProperty(ARGEO_URI).getString();
- try {
- RemoteRepositoryElem remoteRepositoryNode = new RemoteRepositoryElem(
- remoteNode.getName(), repositoryFactory, uri, this,
- userSession, jcrKeyring, remoteNode.getPath());
- super.addChild(remoteRepositoryNode);
- } catch (Exception e) {
- ErrorFeedback.show("Cannot add remote repository "
- + remoteNode, e);
- }
- }
- }
- }
-
- 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 this object. */
- public RepositoryRegister getRepositoryRegister() {
- return repositoryRegister;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.model;
-
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-
-/**
- * UI Tree component that 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 RepositoryElem extends TreeParent {
- private String alias;
- protected Repository repository;
- private Session defaultSession = null;
-
- /** Create a new repository with distinct name & alias */
- public RepositoryElem(String alias, Repository repository, TreeParent parent) {
- super(alias);
- this.repository = repository;
- setParent(parent);
- this.alias = alias;
- }
-
- public void login() {
- try {
- defaultSession = repositoryLogin("main");
- String[] wkpNames = defaultSession.getWorkspace()
- .getAccessibleWorkspaceNames();
- for (String wkpName : wkpNames) {
- if (wkpName.equals(defaultSession.getWorkspace().getName()))
- addChild(new WorkspaceElem(this, wkpName, defaultSession));
- else
- addChild(new WorkspaceElem(this, wkpName));
- }
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot connect to repository " + alias, e);
- }
- }
-
- /**
- * Actual call to the
- * {@link Repository#login(javax.jcr.Credentials, String)} method. To be
- * overridden.
- */
- protected Session repositoryLogin(String workspaceName)
- throws RepositoryException {
- return repository.login(workspaceName);
- }
-
- public String[] getAccessibleWorkspaceNames() {
- try {
- return defaultSession.getWorkspace().getAccessibleWorkspaceNames();
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot retrieve workspace names", e);
- }
- }
-
- public void createWorkspace(String workspaceName) {
- if (!isConnected())
- login();
- try {
- defaultSession.getWorkspace().createWorkspace(workspaceName);
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot create workspace", e);
- }
- }
-
- /** returns the {@link Repository} referenced by the current UI Node */
- public Repository getRepository() {
- return repository;
- }
-
- public String getAlias() {
- return alias;
- }
-
- public Boolean isConnected() {
- if (defaultSession != null && defaultSession.isLive())
- return true;
- else
- return false;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.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 WorkspaceElem}, a
- * {@link SingleJcrNodeElem} or null if the node is "mounted" as the root of the UI
- * tree.
- */
-
-public class SingleJcrNodeElem extends TreeParent {
-
- 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 SingleJcrNodeElem(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 SingleJcrNodeElem(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;
- }
-
- protected String getRepositoryAlias() {
- return alias;
- }
-
- /**
- * Override normal behavior 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 SingleJcrNodeElem(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 {
- if (node.getSession().isLive())
- return node.hasNodes();
- else
- return false;
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while checking children node existence",
- re);
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.model;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-// import javax.jcr.Workspace;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.jcr.JcrUtils;
-
-/**
- * UI Tree component. Wraps the root node of a JCR {@link Workspace}. It also
- * keeps a reference to its parent {@link RepositoryElem}, to be able to
- * retrieve alias of the current used repository
- */
-public class WorkspaceElem extends TreeParent {
- private Session session = null;
-
- public WorkspaceElem(RepositoryElem parent, String name) {
- this(parent, name, null);
- }
-
- public WorkspaceElem(RepositoryElem parent, String name, Session session) {
- super(name);
- this.session = session;
- setParent(parent);
- }
-
- public synchronized Session getSession() {
- return session;
- }
-
- public synchronized 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 synchronized void login() {
- try {
- session = ((RepositoryElem) getParent()).repositoryLogin(getName());
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot connect to repository "
- + getName(), e);
- }
- }
-
- public Boolean isConnected() {
- if (session != null && session.isLive())
- return true;
- else
- return false;
- }
-
- @Override
- public synchronized void dispose() {
- logout();
- super.dispose();
- }
-
- /** Logouts the session, does not nothing if there is no live session. */
- public synchronized void logout() {
- clearChildren();
- JcrUtils.logoutQuietly(session);
- session = null;
- }
-
- @Override
- public synchronized boolean hasChildren() {
- try {
- if (isConnected())
- return session.getRootNode().hasNodes();
- else
- return false;
- } 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 SingleJcrNodeElem(this, node, node.getName()));
- }
- return super.getChildren();
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Cannot initialize WorkspaceNode UI object."
- + getName(), e);
- }
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.query.QueryResult;
-import javax.jcr.query.Row;
-import javax.jcr.query.RowIterator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.GenericTableComparator;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.SashForm;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.part.EditorPart;
-
-/** Executes any JCR query. */
-public abstract class AbstractJcrQueryEditor extends EditorPart {
- private final static Log log = LogFactory
- .getLog(AbstractJcrQueryEditor.class);
-
- protected String initialQuery;
- protected String initialQueryType;
-
- /* DEPENDENCY INJECTION */
- private Session session;
-
- // Widgets
- private TableViewer viewer;
- private List<TableViewerColumn> tableViewerColumns = new ArrayList<TableViewerColumn>();
- private GenericTableComparator comparator;
-
- /** Override to layout a form enabling the end user to build his query */
- protected abstract void createQueryForm(Composite parent);
-
- @Override
- public void init(IEditorSite site, IEditorInput input)
- throws PartInitException {
- JcrQueryEditorInput editorInput = (JcrQueryEditorInput) input;
- initialQuery = editorInput.getQuery();
- initialQueryType = editorInput.getQueryType();
- setSite(site);
- setInput(editorInput);
- }
-
- @Override
- public final void createPartControl(final Composite parent) {
- parent.setLayout(new FillLayout());
-
- SashForm sashForm = new SashForm(parent, SWT.VERTICAL);
- sashForm.setSashWidth(4);
- sashForm.setLayout(new FillLayout());
-
- Composite top = new Composite(sashForm, SWT.NONE);
- GridLayout gl = new GridLayout(1, false);
- top.setLayout(gl);
-
- createQueryForm(top);
-
- Composite bottom = new Composite(sashForm, SWT.NONE);
- bottom.setLayout(new GridLayout(1, false));
- sashForm.setWeights(getWeights());
-
- viewer = new TableViewer(bottom);
- viewer.getTable().setLayoutData(
- new GridData(SWT.FILL, SWT.FILL, true, true));
- viewer.getTable().setHeaderVisible(true);
- viewer.setContentProvider(getQueryResultContentProvider());
- viewer.setInput(getEditorSite());
-
- if (getComparator() != null) {
- comparator = getComparator();
- viewer.setComparator(comparator);
- }
- if (getTableDoubleClickListener() != null)
- viewer.addDoubleClickListener(getTableDoubleClickListener());
-
- }
-
- protected void executeQuery(String statement) {
- try {
- if (log.isDebugEnabled())
- log.debug("Query : " + statement);
-
- QueryResult qr = session.getWorkspace().getQueryManager()
- .createQuery(statement, initialQueryType).execute();
-
- // remove previous columns
- for (TableViewerColumn tvc : tableViewerColumns)
- tvc.getColumn().dispose();
-
- int i = 0;
- for (final String columnName : qr.getColumnNames()) {
- TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE);
- configureColumn(columnName, tvc, i);
- tvc.setLabelProvider(getLabelProvider(columnName));
- tableViewerColumns.add(tvc);
- i++;
- }
-
- // Must create a local list: QueryResults can only be read once.
- try {
- List<Row> rows = new ArrayList<Row>();
- RowIterator rit = qr.getRows();
- while (rit.hasNext()) {
- rows.add(rit.nextRow());
- }
- viewer.setInput(rows);
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot read query result", e);
- }
-
- } catch (RepositoryException e) {
- ErrorDialog.openError(null, "Error", "Cannot execute JCR query: "
- + statement, new Status(IStatus.ERROR,
- "org.argeo.eclipse.ui.jcr", e.getMessage()));
- }
- }
-
- /**
- * To be overidden to adapt size of form and result frames.
- *
- * @return
- */
- protected int[] getWeights() {
- return new int[] { 30, 70 };
- }
-
- /**
- * To be overidden to implement a doubleclick Listener on one of the rows of
- * the table.
- *
- * @return
- */
- protected IDoubleClickListener getTableDoubleClickListener() {
- return null;
- }
-
- /**
- * To be overiden in order to implement a specific
- * QueryResultContentProvider
- */
- protected IStructuredContentProvider getQueryResultContentProvider() {
- return new QueryResultContentProvider();
- }
-
- /**
- * Enable specific implementation for columns
- */
- protected List<TableViewerColumn> getTableViewerColumns() {
- return tableViewerColumns;
- }
-
- /**
- * Enable specific implementation for columns
- */
- protected TableViewer getTableViewer() {
- return viewer;
- }
-
- /**
- * To be overridden in order to configure column label providers .
- */
- protected ColumnLabelProvider getLabelProvider(final String columnName) {
- return new ColumnLabelProvider() {
- private static final long serialVersionUID = -3539689333250152606L;
-
- public String getText(Object element) {
- Row row = (Row) element;
- try {
- return row.getValue(columnName).getString();
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot display row " + row, e);
- }
- }
-
- public Image getImage(Object element) {
- return null;
- }
- };
- }
-
- /**
- * To be overridden in order to configure the columns.
- *
- * @deprecated use {@link
- * org.argeo.eclipse.ui.jcr.editors.AbstractJcrQueryEditor.
- * configureColumn(String jcrColumnName, TableViewerColumn
- * column, int columnIndex)} instead
- */
- protected void configureColumn(String jcrColumnName,
- TableViewerColumn column) {
- column.getColumn().setWidth(50);
- column.getColumn().setText(jcrColumnName);
- }
-
- /** To be overridden in order to configure the columns. */
- protected void configureColumn(String jcrColumnName,
- TableViewerColumn column, int columnIndex) {
- column.getColumn().setWidth(50);
- column.getColumn().setText(jcrColumnName);
- }
-
- private class QueryResultContentProvider implements
- IStructuredContentProvider {
- private static final long serialVersionUID = -5421095459600554741L;
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- public Object[] getElements(Object inputElement) {
-
- if (inputElement instanceof List)
- return ((List<?>) inputElement).toArray();
-
- // Never reached might be deleted in future release
- if (!(inputElement instanceof QueryResult))
- return new String[] {};
-
- try {
- QueryResult queryResult = (QueryResult) inputElement;
- List<Row> rows = new ArrayList<Row>();
- RowIterator rit = queryResult.getRows();
- while (rit.hasNext()) {
- rows.add(rit.nextRow());
- }
-
- // List<Node> elems = new ArrayList<Node>();
- // NodeIterator nit = queryResult.getNodes();
- // while (nit.hasNext()) {
- // elems.add(nit.nextNode());
- // }
- return rows.toArray();
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot read query result", e);
- }
- }
-
- }
-
- /**
- * Might be used by children classes to sort columns.
- *
- * @param column
- * @param index
- * @return
- */
- protected SelectionAdapter getSelectionAdapter(final TableColumn column,
- final int index) {
-
- // A comparator must be define
- if (comparator == null)
- return null;
-
- SelectionAdapter selectionAdapter = new SelectionAdapter() {
- private static final long serialVersionUID = 239829307927778349L;
-
- @Override
- public void widgetSelected(SelectionEvent e) {
-
- try {
-
- comparator.setColumn(index);
- int dir = viewer.getTable().getSortDirection();
- if (viewer.getTable().getSortColumn() == column) {
- dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
- } else {
-
- dir = SWT.DOWN;
- }
- viewer.getTable().setSortDirection(dir);
- viewer.getTable().setSortColumn(column);
- viewer.refresh();
- } catch (Exception exc) {
- exc.printStackTrace();
- }
- }
- };
- return selectionAdapter;
- }
-
- /**
- * To be overridden to enable sorting.
- */
- protected GenericTableComparator getComparator() {
- return null;
- }
-
- @Override
- public boolean isDirty() {
- return false;
- }
-
- @Override
- public void doSave(IProgressMonitor monitor) {
- // TODO save the query in JCR?
- }
-
- @Override
- public void doSaveAs() {
- }
-
- @Override
- public boolean isSaveAsAllowed() {
- return false;
- }
-
- /** Returns the injected current session */
- protected Session getSession() {
- return session;
- }
-
- /* DEPENDENCY INJECTION */
- public void setSession(Session session) {
- this.session = session;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.security.Privilege;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.EclipseUiUtils;
-import org.argeo.eclipse.ui.workbench.users.PickUpUserDialog;
-import org.argeo.eclipse.ui.workbench.users.internal.UsersUtils;
-import org.argeo.jcr.JcrUtils;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.window.Window;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Link;
-import org.eclipse.swt.widgets.Text;
-import org.osgi.service.useradmin.User;
-import org.osgi.service.useradmin.UserAdmin;
-
-/** Add Jcr privileges to the chosen user group on a given node */
-public class AddPrivilegeWizard extends Wizard {
-
- // Context
- private UserAdmin userAdmin;
- private Session currentSession;
- private String targetPath;
- // Chosen parameters
- private User chosenUser;
- private String jcrPrivilege;
-
- // UI Object
- private DefinePrivilegePage page;
-
- // TODO enable external definition of possible values and corresponding
- // description
- protected static final Map<String, String> AUTH_TYPE_LABELS;
- static {
- Map<String, String> tmpMap = new HashMap<String, String>();
- tmpMap.put(Privilege.JCR_READ, "jcr:read");
- tmpMap.put(Privilege.JCR_WRITE, "jcr:write");
- tmpMap.put(Privilege.JCR_ALL, "jcr:all");
- AUTH_TYPE_LABELS = Collections.unmodifiableMap(tmpMap);
- }
-
- protected static final Map<String, String> AUTH_TYPE_DESC;
- static {
- Map<String, String> tmpMap = new HashMap<String, String>();
- tmpMap.put(Privilege.JCR_READ,
- "The privilege to retrieve a node and get its properties and their values.");
- tmpMap.put(Privilege.JCR_WRITE, "An aggregate privilege that "
- + "contains: jcr:modifyProperties, jcr:addChildNodes, "
- + "jcr:removeNode, jcr:removeChildNodes");
- tmpMap.put(Privilege.JCR_ALL, "An aggregate privilege that "
- + "contains all JCR predefined privileges, "
- + "plus all implementation-defined privileges. ");
- AUTH_TYPE_DESC = Collections.unmodifiableMap(tmpMap);
- }
-
- public AddPrivilegeWizard(Session currentSession, String path,
- UserAdmin userAdmin) {
- super();
- this.userAdmin = userAdmin;
- this.currentSession = currentSession;
- this.targetPath = path;
- }
-
- @Override
- public void addPages() {
- try {
- setWindowTitle("Add privilege on " + targetPath);
- page = new DefinePrivilegePage(userAdmin, targetPath);
- addPage(page);
- } catch (Exception e) {
- throw new ArgeoException("Cannot add page to wizard ", e);
- }
- }
-
- @Override
- public boolean performFinish() {
- if (!canFinish())
- return false;
- try {
- JcrUtils.addPrivilege(currentSession, targetPath,
- chosenUser.getName(), jcrPrivilege);
- } catch (RepositoryException re) {
- throw new ArgeoException("Cannot set " + jcrPrivilege + " for "
- + chosenUser.getName() + " on " + targetPath, re);
- }
- return true;
- }
-
- private class DefinePrivilegePage extends WizardPage implements
- ModifyListener {
- private static final long serialVersionUID = 8084431378762283920L;
-
- // Context
- final private UserAdmin userAdmin;
-
- public DefinePrivilegePage(UserAdmin userAdmin, String path) {
- super("Main");
- this.userAdmin = userAdmin;
- setTitle("Define the privilege to apply to " + path);
- setMessage("Please choose a user or a group and relevant JCR Privilege.");
- }
-
- public void createControl(Composite parent) {
- final Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayout(new GridLayout(3, false));
-
- // specify subject
- createBoldLabel(composite, "User or group name");
- final Label groupNameLbl = new Label(composite, SWT.LEAD);
- groupNameLbl.setLayoutData(EclipseUiUtils.fillWidth());
-
- Link pickUpLk = new Link(composite, SWT.LEFT);
- pickUpLk.setText(" <a>Change</a> ");
-
- createBoldLabel(composite, "User or group DN");
- final Text groupNameTxt = new Text(composite, SWT.LEAD | SWT.BORDER);
- groupNameTxt.setLayoutData(EclipseUiUtils.fillWidth(2));
-
- pickUpLk.addSelectionListener(new SelectionAdapter() {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- PickUpUserDialog dialog = new PickUpUserDialog(
- getShell(), "Choose a group or a user", userAdmin);
- if (dialog.open() == Window.OK) {
- chosenUser = dialog.getSelected();
- groupNameLbl.setText(UsersUtils
- .getCommonName(chosenUser));
- groupNameTxt.setText(chosenUser.getName());
- }
- }
- });
-
- groupNameTxt.addFocusListener(new FocusListener() {
- private static final long serialVersionUID = 1965498600105667738L;
-
- @Override
- public void focusLost(FocusEvent event) {
- String dn = groupNameTxt.getText();
- User newChosen = null;
- try {
- newChosen = (User) userAdmin.getRole(dn);
- } catch (Exception e) {
- boolean tryAgain = MessageDialog.openQuestion(
- getShell(), "Unvalid DN",
- "DN " + dn + " is not valid.\nError message: "
- + e.getMessage()
- + "\n\t\tDo you want to try again?");
- if (tryAgain)
- groupNameTxt.setFocus();
- else
- resetOnFail();
- }
-
- if (userAdmin.getRole(dn) == null) {
- boolean tryAgain = MessageDialog.openQuestion(
- getShell(), "Unexisting role", "User/group "
- + dn + " does not exist. "
- + "Do you want to try again?");
- if (tryAgain)
- groupNameTxt.setFocus();
- else
- resetOnFail();
- } else {
- chosenUser = newChosen;
- groupNameLbl.setText(UsersUtils
- .getCommonName(chosenUser));
- }
- }
-
- private void resetOnFail() {
- String oldDn = chosenUser == null ? "" : chosenUser
- .getName();
- groupNameTxt.setText(oldDn);
- }
-
- @Override
- public void focusGained(FocusEvent event) {
- }
- });
-
- // JCR Privileges
- createBoldLabel(composite, "Privilege type");
- Combo authorizationCmb = new Combo(composite, SWT.BORDER
- | SWT.READ_ONLY | SWT.V_SCROLL);
- authorizationCmb.setItems(AUTH_TYPE_LABELS.values().toArray(
- new String[0]));
- authorizationCmb.setLayoutData(EclipseUiUtils.fillWidth(2));
- createBoldLabel(composite, ""); // empty cell
- final Label descLbl = new Label(composite, SWT.WRAP);
- descLbl.setLayoutData(EclipseUiUtils.fillWidth(2));
-
- authorizationCmb.addSelectionListener(new SelectionAdapter() {
- private static final long serialVersionUID = 1L;
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- String chosenPrivStr = ((Combo) e.getSource()).getText();
- if (AUTH_TYPE_LABELS.containsValue(chosenPrivStr)) {
- loop: for (String key : AUTH_TYPE_LABELS.keySet()) {
- if (AUTH_TYPE_LABELS.get(key).equals(chosenPrivStr)) {
- jcrPrivilege = key;
- break loop;
- }
- }
- }
-
- if (jcrPrivilege != null) {
- descLbl.setText(AUTH_TYPE_DESC.get(jcrPrivilege));
- composite.layout(true, true);
- }
- }
- });
-
- // Compulsory
- setControl(composite);
- }
-
- public void modifyText(ModifyEvent event) {
- String message = checkComplete();
- if (message != null)
- setMessage(message, WizardPage.ERROR);
- else {
- setMessage("Complete", WizardPage.INFORMATION);
- setPageComplete(true);
- }
- }
-
- /** @return error message or null if complete */
- protected String checkComplete() {
- if (chosenUser == null)
- return "Please choose a relevant group or user";
- else if (userAdmin.getRole(chosenUser.getName()) == null)
- return "Please choose a relevant group or user";
- else if (jcrPrivilege == null)
- return "Please choose a relevant JCR privilege";
- return null;
- }
- }
-
- private Label createBoldLabel(Composite parent, String value) {
- Label label = new Label(parent, SWT.RIGHT);
- label.setText(" " + value);
- label.setFont(EclipseUiUtils.getBoldFont(parent));
- label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
- return label;
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import javax.jcr.Node;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.EclipseUiUtils;
-import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.DefaultNodeEditor;
-import org.argeo.eclipse.ui.workbench.jcr.internal.NodeLabelProvider;
-import org.argeo.eclipse.ui.workbench.jcr.internal.SingleNodeAsTreeContentProvider;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-
-/**
- * List all childs of the current node and brings some browsing capabilities
- * accross the repository
- */
-public class ChildNodesPage extends FormPage {
- // private final static Log log = LogFactory.getLog(ChildNodesPage.class);
-
- // business objects
- private Node currentNode;
-
- // this page UI components
- private SingleNodeAsTreeContentProvider nodeContentProvider;
- private TreeViewer nodesViewer;
-
- public ChildNodesPage(FormEditor editor, String title, Node currentNode) {
- super(editor, "ChildNodesPage", title);
- this.currentNode = currentNode;
- }
-
- protected void createFormContent(IManagedForm managedForm) {
- try {
- ScrolledForm form = managedForm.getForm();
- form.setText(WorkbenchUiPlugin.getMessage("childNodesPageTitle"));
- Composite body = form.getBody();
- GridLayout twt = new GridLayout(1, false);
- twt.marginWidth = twt.marginHeight = 5;
- body.setLayout(twt);
- if (!currentNode.hasNodes()) {
- managedForm.getToolkit().createLabel(body,
- WorkbenchUiPlugin.getMessage("warningNoChildNode"));
- } else {
- nodeContentProvider = new SingleNodeAsTreeContentProvider();
- nodesViewer = createNodeViewer(body, nodeContentProvider);
- nodesViewer.setInput(currentNode);
- }
- } catch (Exception e) {
- throw new ArgeoException(
- "Unexpected error while creating child node page", e);
- }
- }
-
- protected TreeViewer createNodeViewer(Composite parent,
- final ITreeContentProvider nodeContentProvider) {
-
- final TreeViewer tmpNodeViewer = new TreeViewer(parent, SWT.BORDER);
- Tree tree = tmpNodeViewer.getTree();
- tree.setLinesVisible(true);
- tmpNodeViewer.getTree().setLayoutData(EclipseUiUtils.fillAll());
- tmpNodeViewer.setContentProvider(nodeContentProvider);
- tmpNodeViewer.setLabelProvider(new NodeLabelProvider());
- tmpNodeViewer.addDoubleClickListener(new DClickListener());
- return tmpNodeViewer;
- }
-
- public class DClickListener implements IDoubleClickListener {
-
- public void doubleClick(DoubleClickEvent event) {
- if (event.getSelection() == null || event.getSelection().isEmpty())
- return;
- Object obj = ((IStructuredSelection) event.getSelection())
- .getFirstElement();
- if (obj instanceof Node) {
- Node node = (Node) obj;
- try {
- GenericNodeEditorInput gnei = new GenericNodeEditorInput(
- node);
- WorkbenchUiPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow().getActivePage()
- .openEditor(gnei, DefaultNodeEditor.ID);
- } catch (PartInitException pie) {
- throw new ArgeoException(
- "Unexepected exception while opening node editor",
- pie);
- }
- }
- }
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-
-/** Dialog to change the current user password */
-public class ChooseNameDialog extends TitleAreaDialog {
- private static final long serialVersionUID = 280139710002698692L;
- private Text nameTxt;
-
- public ChooseNameDialog(Shell parentShell) {
- super(parentShell);
- setTitle("Choose name");
- }
-
- protected Point getInitialSize() {
- return new Point(300, 250);
- }
-
- protected Control createDialogArea(Composite parent) {
- Composite dialogarea = (Composite) super.createDialogArea(parent);
- dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- Composite composite = new Composite(dialogarea, SWT.NONE);
- composite.setLayout(new GridLayout(2, false));
- composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- nameTxt = createLT(composite, "Name");
-
- setMessage("Choose name", IMessageProvider.INFORMATION);
- parent.pack();
- return composite;
- }
-
- /** Creates label and text. */
- protected Text createLT(Composite parent, String label) {
- new Label(parent, SWT.NONE).setText(label);
- Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
- text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- return text;
- }
-
- public String getName() {
- return nameTxt.getText();
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-
-/**
- * This page is only used at editor's creation time when current node has not
- * yet been set
- */
-public class EmptyNodePage extends FormPage {
- // private final static Log log = LogFactory.getLog(EmptyNodePage.class);
-
- public EmptyNodePage(FormEditor editor, String title) {
- super(editor, "Empty Page", title);
- }
-
- protected void createFormContent(IManagedForm managedForm) {
- try {
- ScrolledForm form = managedForm.getForm();
- GridLayout twt = new GridLayout(1, false);
- twt.marginWidth = twt.marginHeight = 0;
- form.getBody().setLayout(twt);
- Label lbl = new Label(form.getBody(), SWT.NONE);
- lbl.setText("Empty page");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
-import org.argeo.ArgeoException;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-
-/**
- * An editor input based the JCR node object.
- * */
-
-public class GenericNodeEditorInput implements IEditorInput {
- private final Node currentNode;
-
- // cache key properties at creation time to avoid Exception at recoring time
- // when the session has been closed
- private String path;
- private String uid;
- private String name;
-
- public GenericNodeEditorInput(Node currentNode) {
- this.currentNode = currentNode;
- try {
- name = currentNode.getName();
- uid = currentNode.getIdentifier();
- path = currentNode.getPath();
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "unexpected error while getting node key values at creation time",
- re);
- }
- }
-
- public Node getCurrentNode() {
- return currentNode;
- }
-
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- return null;
- }
-
- public boolean exists() {
- return true;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- public String getName() {
- return name;
- }
-
- public String getUid() {
- return uid;
- }
-
- public String getToolTipText() {
- return path;
- }
-
- public String getPath() {
- return path;
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
- /**
- * equals method based on UID that is unique within a workspace and path of
- * the node, thus 2 shared node that have same UID as defined in the spec
- * but 2 different pathes will open two distinct editors.
- *
- * TODO enhance this method to support multirepository and multiworkspace
- * environments
- */
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
-
- GenericNodeEditorInput other = (GenericNodeEditorInput) obj;
- if (!getUid().equals(other.getUid()))
- return false;
- if (!getPath().equals(other.getPath()))
- return false;
- return true;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.ListIterator;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
-import org.argeo.jcr.JcrUtils;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.forms.AbstractFormPart;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-
-/**
- * Main node editor page. Lists all properties of the current node and enable
- * access and editing for some of them.
- */
-
-public class GenericNodePage extends FormPage implements WorkbenchConstants {
- // private final static Log log = LogFactory.getLog(GenericNodePage.class);
-
- // local constants
- private final static String JCR_PROPERTY_NAME = "jcr:name";
-
- // Utils
- protected DateFormat timeFormatter = new SimpleDateFormat(DATE_TIME_FORMAT);
-
- // Main business Objects
- private Node currentNode;
-
- // This page widgets
- private FormToolkit tk;
- private List<Control> modifyableProperties = new ArrayList<Control>();
-
- public GenericNodePage(FormEditor editor, String title, Node currentNode) {
- super(editor, "id", title);
- this.currentNode = currentNode;
- }
-
- protected void createFormContent(IManagedForm managedForm) {
- tk = managedForm.getToolkit();
- ScrolledForm form = managedForm.getForm();
- GridLayout twt = new GridLayout(3, false);
- twt.marginWidth = twt.marginHeight = 5;
-
- form.getBody().setLayout(twt);
- createPropertiesPart(form.getBody());
- }
-
- private void createPropertiesPart(Composite parent) {
- try {
-
- PropertyIterator pi = currentNode.getProperties();
-
- // Initializes form part
- AbstractFormPart part = new AbstractFormPart() {
- public void commit(boolean onSave) {
- try {
- if (onSave) {
- ListIterator<Control> it = modifyableProperties
- .listIterator();
- while (it.hasNext()) {
- // we only support Text controls for the time
- // being
- Text curControl = (Text) it.next();
- String value = curControl.getText();
- currentNode.setProperty((String) curControl
- .getData(JCR_PROPERTY_NAME), value);
- }
-
- // We only commit when onSave = true,
- // thus it is still possible to save after a tab
- // change.
- super.commit(onSave);
- }
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while saving properties", re);
- }
- }
- };
-
- while (pi.hasNext()) {
- Property prop = pi.nextProperty();
- addPropertyLine(parent, part, prop);
- }
-
- getManagedForm().addPart(part);
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Error during creation of network details section", re);
- }
-
- }
-
- private void addPropertyLine(Composite parent, AbstractFormPart part,
- Property prop) {
- try {
- tk.createLabel(parent, prop.getName());
- tk.createLabel(parent,
- "[" + JcrUtils.getPropertyDefinitionAsString(prop) + "]");
-
- if (prop.getDefinition().isProtected()) {
- tk.createLabel(parent, formatReadOnlyPropertyValue(prop));
- } else
- addModifyableValueWidget(parent, part, prop);
- } catch (RepositoryException re) {
- throw new ArgeoException("Cannot get property " + prop, re);
- }
- }
-
- private String formatReadOnlyPropertyValue(Property prop) {
- try {
- String strValue;
-
- if (prop.getType() == PropertyType.BINARY)
- strValue = "<binary>";
- else if (prop.isMultiple())
- strValue = Arrays.asList(prop.getValues()).toString();
- else if (prop.getType() == PropertyType.DATE)
- strValue = timeFormatter.format(prop.getValue().getDate()
- .getTime());
- else
- strValue = prop.getValue().getString();
-
- return strValue;
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while formatting read only property value",
- re);
- }
- }
-
- private Control addModifyableValueWidget(Composite parent,
- AbstractFormPart part, Property prop) {
- GridData gd;
- try {
- if (prop.getType() == PropertyType.STRING) {
- Text txt = tk.createText(parent, prop.getString());
- gd = new GridData(GridData.FILL_HORIZONTAL);
- txt.setLayoutData(gd);
- txt.addModifyListener(new ModifiedFieldListener(part));
- txt.setData(JCR_PROPERTY_NAME, prop.getName());
- modifyableProperties.add(txt);
- } else {
- // unsupported property type for editing, we create a read only
- // label.
- return tk
- .createLabel(parent, formatReadOnlyPropertyValue(prop));
- }
- return null;
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while formatting read only property value",
- re);
- }
-
- }
-
- private class ModifiedFieldListener implements ModifyListener {
- private static final long serialVersionUID = 2117484480773434646L;
- private AbstractFormPart formPart;
-
- public ModifiedFieldListener(AbstractFormPart generalPart) {
- this.formPart = generalPart;
- }
-
- public void modifyText(ModifyEvent e) {
- formPart.markDirty();
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
-import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.eclipse.ui.workbench.jcr.internal.PropertyLabelProvider;
-import org.eclipse.jface.layout.TreeColumnLayout;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeColumn;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-
-/**
- * Generic editor property page. Lists all properties of current node as a
- * complex tree. TODO: enable editing
- */
-public class GenericPropertyPage extends FormPage implements WorkbenchConstants {
- // private final static Log log =
- // LogFactory.getLog(GenericPropertyPage.class);
-
- // Main business Objects
- private Node currentNode;
-
- public GenericPropertyPage(FormEditor editor, String title, Node currentNode) {
- super(editor, "id", title);
- this.currentNode = currentNode;
- }
-
- protected void createFormContent(IManagedForm managedForm) {
- ScrolledForm form = managedForm.getForm();
- form.setText(WorkbenchUiPlugin.getMessage("genericNodePageTitle"));
-
- Composite body = form.getBody();
- FillLayout layout = new FillLayout();
- layout.marginHeight = 5;
- layout.marginWidth = 5;
- body.setLayout(layout);
- createComplexTree(body);
- // TODO TreeColumnLayout triggers a scroll issue with the form:
- // The inside body is always to big and a scroll bar is shown
- // Composite tableCmp = new Composite(body, SWT.NO_FOCUS);
- // createComplexTree(tableCmp);
- }
-
- private TreeViewer createComplexTree(Composite parent) {
- int style = SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION;
- Tree tree = new Tree(parent, style);
- TreeColumnLayout tableColumnLayout = new TreeColumnLayout();
-
- createColumn(tree, tableColumnLayout, "Property", SWT.LEFT, 200, 30);
- createColumn(tree, tableColumnLayout, "Value(s)", SWT.LEFT, 300, 60);
- createColumn(tree, tableColumnLayout, "Attributes", SWT.LEFT, 75, 0);
- // Do not apply the treeColumnLayout it does not work yet
- // parent.setLayout(tableColumnLayout);
-
- tree.setLinesVisible(true);
- tree.setHeaderVisible(true);
-
- TreeViewer treeViewer = new TreeViewer(tree);
- treeViewer.setContentProvider(new TreeContentProvider());
- treeViewer.setLabelProvider(new PropertyLabelProvider());
- treeViewer.setInput(currentNode);
- treeViewer.expandAll();
- return treeViewer;
- }
-
- private static TreeColumn createColumn(Tree parent,
- TreeColumnLayout tableColumnLayout, String name, int style,
- int width, int weight) {
- TreeColumn column = new TreeColumn(parent, style);
- column.setText(name);
- column.setWidth(width);
- column.setMoveable(true);
- column.setResizable(true);
- tableColumnLayout.setColumnData(column, new ColumnWeightData(weight,
- width, true));
- return column;
- }
-
- //
- // private void createPropertiesPart(Composite parent) {
- // try {
- //
- // PropertyIterator pi = currentNode.getProperties();
- //
- // // Initializes form part
- // AbstractFormPart part = new AbstractFormPart() {
- // public void commit(boolean onSave) {
- // try {
- // if (onSave) {
- // ListIterator<Control> it = modifyableProperties
- // .listIterator();
- // while (it.hasNext()) {
- // // we only support Text controls for the time
- // // being
- // Text curControl = (Text) it.next();
- // String value = curControl.getText();
- // currentNode.setProperty((String) curControl
- // .getData(JCR_PROPERTY_NAME), value);
- // }
- //
- // // We only commit when onSave = true,
- // // thus it is still possible to save after a tab
- // // change.
- // super.commit(onSave);
- // }
- // } catch (RepositoryException re) {
- // throw new ArgeoException(
- // "Unexpected error while saving properties", re);
- // }
- // }
- // };
- //
- // while (pi.hasNext()) {
- // Property prop = pi.nextProperty();
- // addPropertyLine(parent, part, prop);
- // }
- //
- // getManagedForm().addPart(part);
- // } catch (RepositoryException re) {
- // throw new ArgeoException(
- // "Error during creation of network details section", re);
- // }
- //
- // }
- //
- // private void addPropertyLine(Composite parent, AbstractFormPart part,
- // Property prop) {
- // try {
- // tk.createLabel(parent, prop.getName());
- // tk.createLabel(parent,
- // "[" + JcrUtils.getPropertyDefinitionAsString(prop) + "]");
- //
- // if (prop.getDefinition().isProtected()) {
- // tk.createLabel(parent, formatReadOnlyPropertyValue(prop));
- // } else
- // addModifyableValueWidget(parent, part, prop);
- // } catch (RepositoryException re) {
- // throw new ArgeoException("Cannot get property " + prop, re);
- // }
- // }
- //
- // private String formatReadOnlyPropertyValue(Property prop) {
- // try {
- // String strValue;
- //
- // if (prop.getType() == PropertyType.BINARY)
- // strValue = "<binary>";
- // else if (prop.isMultiple())
- // strValue = Arrays.asList(prop.getValues()).toString();
- // else if (prop.getType() == PropertyType.DATE)
- // strValue = timeFormatter.format(prop.getValue().getDate()
- // .getTime());
- // else
- // strValue = prop.getValue().getString();
- //
- // return strValue;
- // } catch (RepositoryException re) {
- // throw new ArgeoException(
- // "Unexpected error while formatting read only property value",
- // re);
- // }
- // }
- //
- // private Control addModifyableValueWidget(Composite parent,
- // AbstractFormPart part, Property prop) {
- // GridData gd;
- // try {
- // if (prop.getType() == PropertyType.STRING) {
- // Text txt = tk.createText(parent, prop.getString());
- // gd = new GridData(GridData.FILL_HORIZONTAL);
- // txt.setLayoutData(gd);
- // txt.addModifyListener(new ModifiedFieldListener(part));
- // txt.setData(JCR_PROPERTY_NAME, prop.getName());
- // modifyableProperties.add(txt);
- // } else {
- // // unsupported property type for editing, we create a read only
- // // label.
- // return tk
- // .createLabel(parent, formatReadOnlyPropertyValue(prop));
- // }
- // return null;
- // } catch (RepositoryException re) {
- // throw new ArgeoException(
- // "Unexpected error while formatting read only property value",
- // re);
- // }
- //
- // }
-
- // Multiple Value Model
- // protected class MultipleValueItem {
- // private int index;
- // private Value value;
- //
- // public MultipleValueItem(int index, Value value) {
- // this.index = index;
- // this.value = value;
- // }
- //
- // public int getIndex() {
- // return index;
- // }
- //
- // public Object getValue() {
- // return value;
- // }
- // }
-
- private class TreeContentProvider implements ITreeContentProvider {
- private static final long serialVersionUID = -6162736530019406214L;
-
- public Object[] getElements(Object parent) {
- Object[] props = null;
- try {
-
- if (parent instanceof Node) {
- Node node = (Node) parent;
- PropertyIterator pi;
- pi = node.getProperties();
- List<Property> propList = new ArrayList<Property>();
- while (pi.hasNext()) {
- propList.add(pi.nextProperty());
- }
- props = propList.toArray();
- }
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected exception while listing node properties", e);
- }
- return props;
- }
-
- public Object getParent(Object child) {
- return null;
- }
-
- public Object[] getChildren(Object parent) {
- Object[] result = null;
- if (parent instanceof Property) {
- Property prop = (Property) parent;
- try {
-
- if (prop.isMultiple()) {
- Value[] values = prop.getValues();
- // List<MultipleValueItem> list = new
- // ArrayList<MultipleValueItem>();
- // for (int i = 0; i < values.length; i++) {
- // MultipleValueItem mvi = new MultipleValueItem(i,
- // values[i]);
- // list.add(mvi);
- // }
-
- return values;
- }
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected error getting multiple values property.",
- e);
- }
- }
- return result;
- }
-
- public boolean hasChildren(Object parent) {
- try {
- if (parent instanceof Property
- && ((Property) parent).isMultiple()) {
- return true;
- }
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected exception while checking if property is multiple",
- e);
- }
- return false;
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- public void dispose() {
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
-import javax.jcr.Binary;
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.nodetype.NodeType;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
-import org.argeo.eclipse.ui.specific.UploadFileWizardPage;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.wizard.Wizard;
-
-public class ImportFileSystemWizard extends Wizard {
- private final static Log log = LogFactory
- .getLog(ImportFileSystemWizard.class);
-
- private UploadFileWizardPage importPage;
- private final Node folder;
-
- public ImportFileSystemWizard(Node folder) {
- this.folder = folder;
- setWindowTitle("Import from file system");
- }
-
- @Override
- public void addPages() {
- importPage = new UploadFileWizardPage();
- addPage(importPage);
- setNeedsProgressMonitor(importPage.getNeedsProgressMonitor());
- }
-
- /**
- * Called when the user click on 'Finish' in the wizard. The real upload to
- * the JCR repository is done here.
- */
- @Override
- public boolean performFinish() {
-
- // Initialization
- final String objectType = importPage.getObjectType();
- final String objectPath = importPage.getObjectPath();
-
- // We do not display a progress bar for one file only
- if (UploadFileWizardPage.FILE_ITEM_TYPE.equals(objectType)) {
- // In Rap we must force the "real" upload of the file
- // importPage.performFinish();
- try {
- Node fileNode = folder.addNode(importPage.getObjectName(),
- NodeType.NT_FILE);
- Node resNode = fileNode.addNode(Property.JCR_CONTENT,
- NodeType.NT_RESOURCE);
- Binary binary = null;
- InputStream is = null;
- try {
- is = importPage.getFileInputStream();
- binary = folder.getSession().getValueFactory()
- .createBinary(is);
- resNode.setProperty(Property.JCR_DATA, binary);
- } finally {
- if (binary != null)
- binary.dispose();
- IOUtils.closeQuietly(is);
- }
- folder.getSession().save();
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- return true;
- } else if (UploadFileWizardPage.FOLDER_ITEM_TYPE.equals(objectType)) {
- if (objectPath == null || !new File(objectPath).exists()) {
- ErrorFeedback.show("Directory " + objectPath
- + " does not exist");
- return false;
- }
-
- Boolean failed = false;
- final File dir = new File(objectPath).getAbsoluteFile();
- final Long sizeB = directorySize(dir, 0l);
- final Stats stats = new Stats();
- Long begin = System.currentTimeMillis();
- try {
- getContainer().run(true, true, new IRunnableWithProgress() {
- public void run(IProgressMonitor monitor) {
- try {
- Integer sizeKB = (int) (sizeB / FileUtils.ONE_KB);
- monitor.beginTask("", sizeKB);
- importDirectory(folder, dir, monitor, stats);
- monitor.done();
- } catch (Exception e) {
- if (e instanceof RuntimeException)
- throw (RuntimeException) e;
- else
- throw new ArgeoException("Cannot import "
- + objectPath, e);
- }
- }
- });
- } catch (Exception e) {
- ErrorFeedback.show("Cannot import " + objectPath, e);
- failed = true;
- }
-
- Long duration = System.currentTimeMillis() - begin;
- Long durationS = duration / 1000l;
- String durationStr = (durationS / 60) + " min " + (durationS % 60)
- + " s";
- StringBuffer message = new StringBuffer("Imported\n");
- message.append(stats.fileCount).append(" files\n");
- message.append(stats.dirCount).append(" directories\n");
- message.append(FileUtils.byteCountToDisplaySize(stats.sizeB));
- if (failed)
- message.append(" of planned ").append(
- FileUtils.byteCountToDisplaySize(sizeB));
- message.append("\n");
- message.append("in ").append(durationStr).append("\n");
- if (failed)
- MessageDialog.openError(getShell(), "Import failed",
- message.toString());
- else
- MessageDialog.openInformation(getShell(), "Import successful",
- message.toString());
-
- return true;
- }
- return false;
-
- }
-
- /** Recursively computes the size of the directory in bytes. */
- protected Long directorySize(File dir, Long currentSize) {
- Long size = currentSize;
- File[] files = dir.listFiles();
- for (File file : files) {
- if (file.isDirectory()) {
- size = directorySize(file, size);
- } else {
- size = size + file.length();
- }
- }
- return size;
- }
-
- /**
- * Import recursively a directory and its content to the repository.
- */
- protected void importDirectory(Node folder, File dir,
- IProgressMonitor monitor, Stats stats) {
- try {
- File[] files = dir.listFiles();
- for (File file : files) {
- if (file.isDirectory()) {
- Node childFolder = folder.addNode(file.getName(),
- NodeType.NT_FOLDER);
- importDirectory(childFolder, file, monitor, stats);
- folder.getSession().save();
- stats.dirCount++;
- } else {
- Long fileSize = file.length();
- // we skip temporary files that are created by apps when a
- // file is being edited.
- // TODO : make this configurable.
- if (file.getName().lastIndexOf('~') != file.getName()
- .length() - 1) {
-
- monitor.subTask(file.getName() + " ("
- + FileUtils.byteCountToDisplaySize(fileSize)
- + ") " + file.getCanonicalPath());
- try {
- Node fileNode = folder.addNode(file.getName(),
- NodeType.NT_FILE);
- Node resNode = fileNode.addNode(
- Property.JCR_CONTENT, NodeType.NT_RESOURCE);
- Binary binary = null;
- try {
- binary = folder
- .getSession()
- .getValueFactory()
- .createBinary(new FileInputStream(file));
- resNode.setProperty(Property.JCR_DATA, binary);
- } finally {
- if (binary != null)
- binary.dispose();
- }
- folder.getSession().save();
- stats.fileCount++;
- stats.sizeB = stats.sizeB + fileSize;
- } catch (Exception e) {
- log.warn("Import of "
- + file
- + " ("
- + FileUtils
- .byteCountToDisplaySize(fileSize)
- + ") failed: " + e);
- folder.getSession().refresh(false);
- }
- monitor.worked((int) (fileSize / FileUtils.ONE_KB));
- }
- }
- }
- } catch (Exception e) {
- throw new ArgeoException("Cannot import " + dir + " to " + folder,
- e);
- }
- }
-
- static class Stats {
- public Long fileCount = 0l;
- public Long dirCount = 0l;
- public Long sizeB = 0l;
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import javax.jcr.query.Query;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-
-public class JcrQueryEditorInput implements IEditorInput {
- private final String query;
- private final String queryType;
-
- public JcrQueryEditorInput(String query, String queryType) {
- this.query = query;
- if (queryType == null)
- this.queryType = Query.JCR_SQL2;
- else
- this.queryType = queryType;
- }
-
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- return null;
- }
-
- public boolean exists() {
- return true;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- public String getName() {
- return query;
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
- public String getToolTipText() {
- return query;
- }
-
- public String getQuery() {
- return query;
- }
-
- public String getQueryType() {
- return queryType;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-
-/**
- * A canonical editor input based on a path to a node. In a multirepository
- * environment, path can be enriched with Repository Alias and workspace
- */
-
-public class NodeEditorInput implements IEditorInput {
- private final String path;
-
- public NodeEditorInput(String path) {
- this.path = path;
- }
-
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- return null;
- }
-
- public boolean exists() {
- return true;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- public String getName() {
- return path;
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
- public String getToolTipText() {
- return path;
- }
-
- public String getPath() {
- return path;
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-
-/** Display and edit a given node rights */
-public class NodePrivilegesPage extends FormPage {
-
- private Node context;
-
- private TableViewer viewer;
-
- public NodePrivilegesPage(FormEditor editor, String title, Node context) {
- super(editor, "NodePrivilegesPage", title);
- this.context = context;
- }
-
- protected void createFormContent(IManagedForm managedForm) {
- ScrolledForm form = managedForm.getForm();
- form.setText(WorkbenchUiPlugin
- .getMessage("nodeRightsManagementPageTitle"));
- FillLayout layout = new FillLayout();
- layout.marginHeight = 5;
- layout.marginWidth = 5;
- form.getBody().setLayout(layout);
- createRightsPart(form.getBody());
- }
-
- /** Creates the authorization part */
- protected void createRightsPart(Composite parent) {
- Table table = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- table.setLinesVisible(true);
- table.setHeaderVisible(true);
- viewer = new TableViewer(table);
-
- // Group / user name
- TableViewerColumn column = createTableViewerColumn(viewer,
- "User/Group Name", 280);
- column.setLabelProvider(new ColumnLabelProvider() {
- private static final long serialVersionUID = -2290781173498395973L;
-
- public String getText(Object element) {
- Node node = (Node) element;
- try {
- if (node.hasProperty("rep:principalName"))
- return node.getProperty("rep:principalName")
- .getString();
- } catch (RepositoryException e) {
- throw new ArgeoException("Unable to retrieve "
- + "principal name on " + node, e);
- }
- return "";
- }
-
- public Image getImage(Object element) {
- return null;
- }
- });
-
- // Privileges
- column = createTableViewerColumn(viewer, "Assigned privileges", 300);
- column.setLabelProvider(new ColumnLabelProvider() {
- private static final long serialVersionUID = -2290781173498395973L;
- private String propertyName = "rep:privileges";
-
- public String getText(Object element) {
- Node node = (Node) element;
- try {
- if (node.hasProperty(propertyName)) {
- String separator = ", ";
- Value[] langs = node.getProperty(propertyName)
- .getValues();
- StringBuilder builder = new StringBuilder();
- for (Value val : langs) {
- String currStr = val.getString();
- builder.append(currStr).append(separator);
- }
- if (builder.lastIndexOf(separator) >= 0)
- return builder.substring(0, builder.length()
- - separator.length());
- else
- return builder.toString();
-
- }
- } catch (RepositoryException e) {
- throw new ArgeoException("Unable to retrieve "
- + "privileges on " + node, e);
- }
- return "";
- }
-
- public Image getImage(Object element) {
- return null;
- }
- });
-
- // Relevant node
- column = createTableViewerColumn(viewer, "Relevant node", 300);
- column.setLabelProvider(new ColumnLabelProvider() {
- /**
- *
- */
- private static final long serialVersionUID = 4245522992038244849L;
-
- public String getText(Object element) {
- Node node = (Node) element;
- try {
- return node.getParent().getParent().getPath();
- } catch (RepositoryException e) {
- throw new ArgeoException("Unable get path for " + node, e);
- }
- }
-
- public Image getImage(Object element) {
- return null;
- }
- });
-
- viewer.setContentProvider(new RightsContentProvider());
- viewer.setInput(getEditorSite());
- }
-
- protected TableViewerColumn createTableViewerColumn(TableViewer viewer,
- String title, int bound) {
- final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
- SWT.NONE);
- final TableColumn column = viewerColumn.getColumn();
- column.setText(title);
- column.setWidth(bound);
- column.setResizable(true);
- column.setMoveable(true);
- return viewerColumn;
- }
-
- private class RightsContentProvider implements IStructuredContentProvider {
- private static final long serialVersionUID = -7631476348552802706L;
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- // TODO JackRabbit specific retrieval of authorization. Clean and
- // generalize
- public Object[] getElements(Object inputElement) {
- try {
- List<Node> privs = new ArrayList<Node>();
-
- Node currNode = context;
- String currPath = currNode.getPath();
-
- loop: while (true) {
- if (currNode.hasNode("rep:policy")) {
- NodeIterator nit = currNode.getNode("rep:policy")
- .getNodes();
- while (nit.hasNext()) {
- Node currPrivNode = nit.nextNode();
- if (currPrivNode.getName().equals("allow"))
- privs.add(currPrivNode);
- }
- }
- if ("/".equals(currPath))
- break loop;
- else {
- currNode = currNode.getParent();
- currPath = currNode.getPath();
- }
- }
-
- return privs.toArray();
- } catch (Exception e) {
- throw new ArgeoException("Cannot retrieve authorization for "
- + context, e);
- }
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-import java.util.Map;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.version.Version;
-import javax.jcr.version.VersionHistory;
-import javax.jcr.version.VersionIterator;
-import javax.jcr.version.VersionManager;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
-import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.jcr.PropertyDiff;
-import org.argeo.jcr.VersionDiff;
-import org.argeo.eclipse.ui.workbench.jcr.internal.FullVersioningTreeContentProvider;
-import org.argeo.eclipse.ui.workbench.jcr.internal.GenericNodeDoubleClickListener;
-import org.argeo.eclipse.ui.workbench.jcr.internal.VersionLabelProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.forms.AbstractFormPart;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.ui.forms.widgets.TableWrapData;
-import org.eclipse.ui.forms.widgets.TableWrapLayout;
-
-/**
- * Offers two main sections : one to display a text area with a summary of all
- * variations between a version and its predecessor and one tree view that
- * enable browsing
- * */
-public class NodeVersionHistoryPage extends FormPage implements
- WorkbenchConstants {
- // private final static Log log = LogFactory
- // .getLog(NodeVersionHistoryPage.class);
-
- // Utils
- protected DateFormat timeFormatter = new SimpleDateFormat(DATE_TIME_FORMAT);
-
- // business objects
- private Node currentNode;
-
- // this page UI components
- private FullVersioningTreeContentProvider nodeContentProvider;
- private TreeViewer nodesViewer;
- private FormToolkit tk;
-
- public NodeVersionHistoryPage(FormEditor editor, String title,
- Node currentNode) {
- super(editor, "NodeVersionHistoryPage", title);
- this.currentNode = currentNode;
- }
-
- protected void createFormContent(IManagedForm managedForm) {
- ScrolledForm form = managedForm.getForm();
- form.setText(WorkbenchUiPlugin
- .getMessage("nodeVersionHistoryPageTitle"));
- tk = managedForm.getToolkit();
- GridLayout twt = new GridLayout(1, false);
- twt.marginWidth = twt.marginHeight = 5;
- Composite body = form.getBody();
- body.setLayout(twt);
-
- try {
- if (!currentNode.isNodeType(NodeType.MIX_VERSIONABLE)) {
- tk.createLabel(body, WorkbenchUiPlugin
- .getMessage("warningUnversionableNode"));
- } else {
- createHistorySection(form.getBody());
- createTreeSection(form.getBody());
- }
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected error while checking if node is versionable", e);
- }
- }
-
- protected void createTreeSection(Composite parent) {
- // Section Layout & MetaData
- Section section = tk.createSection(parent, Section.TWISTIE);
- section.setLayoutData(new GridData(GridData.FILL_BOTH));
- section.setText(WorkbenchUiPlugin.getMessage("versionTreeSectionTitle"));
-
- // Section Body
- Composite body = tk.createComposite(section, SWT.FILL);
- // WARNING : 2 following lines are compulsory or body won't be
- // displayed.
- body.setLayout(new GridLayout());
- section.setClient(body);
-
- body.setLayoutData(new GridData(GridData.FILL_BOTH));
- section.setExpanded(true);
-
- nodeContentProvider = new FullVersioningTreeContentProvider();
- nodesViewer = createNodeViewer(body, nodeContentProvider);
- nodesViewer.setInput(currentNode);
- }
-
- protected TreeViewer createNodeViewer(Composite parent,
- final ITreeContentProvider nodeContentProvider) {
-
- final TreeViewer tmpNodeViewer = new TreeViewer(parent, SWT.MULTI);
-
- tmpNodeViewer.getTree().setLayoutData(
- new GridData(SWT.FILL, SWT.FILL, true, true));
-
- tmpNodeViewer.setContentProvider(nodeContentProvider);
- tmpNodeViewer.setLabelProvider(new VersionLabelProvider());
- tmpNodeViewer
- .addDoubleClickListener(new GenericNodeDoubleClickListener(
- tmpNodeViewer));
- return tmpNodeViewer;
- }
-
- protected void createHistorySection(Composite parent) {
-
- // Section Layout
- Section section = tk.createSection(parent, Section.TWISTIE);
- section.setLayoutData(new GridData(TableWrapData.FILL_GRAB));
- TableWrapLayout twt = new TableWrapLayout();
- section.setLayout(twt);
-
- // Set title of the section
- section.setText(WorkbenchUiPlugin
- .getMessage("versionHistorySectionTitle"));
-
- final Text styledText = tk.createText(section, "", SWT.FULL_SELECTION
- | SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
- styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- section.setClient(styledText);
- refreshHistory(styledText);
- styledText.setEditable(false);
- section.setExpanded(false);
-
- AbstractFormPart part = new AbstractFormPart() {
- public void commit(boolean onSave) {
- }
-
- public void refresh() {
- super.refresh();
- refreshHistory(styledText);
- }
- };
- getManagedForm().addPart(part);
- }
-
- protected void refreshHistory(Text styledText) {
- try {
- List<VersionDiff> lst = listHistoryDiff();
- StringBuffer main = new StringBuffer("");
-
- for (int i = lst.size() - 1; i >= 0; i--) {
- if (i == 0)
- main.append("Creation (");
- else
- main.append("Update " + i + " (");
-
- if (lst.get(i).getUserId() != null)
- main.append("UserId : " + lst.get(i).getUserId());
-
- if (lst.get(i).getUserId() != null
- && lst.get(i).getUpdateTime() != null)
- main.append(", ");
-
- if (lst.get(i).getUpdateTime() != null)
- main.append("Date : "
- + timeFormatter.format(lst.get(i).getUpdateTime()
- .getTime()) + ")\n");
-
- StringBuffer buf = new StringBuffer("");
- Map<String, PropertyDiff> diffs = lst.get(i).getDiffs();
- for (String prop : diffs.keySet()) {
- PropertyDiff pd = diffs.get(prop);
- // String propName = pd.getRelPath();
- Value refValue = pd.getReferenceValue();
- Value newValue = pd.getNewValue();
- String refValueStr = "";
- String newValueStr = "";
-
- if (refValue != null) {
- if (refValue.getType() == PropertyType.DATE) {
- refValueStr = timeFormatter.format(refValue
- .getDate().getTime());
- } else
- refValueStr = refValue.getString();
- }
- if (newValue != null) {
- if (newValue.getType() == PropertyType.DATE) {
- newValueStr = timeFormatter.format(newValue
- .getDate().getTime());
- } else
- newValueStr = newValue.getString();
- }
-
- if (pd.getType() == PropertyDiff.MODIFIED) {
- buf.append(prop).append(": ");
- buf.append(refValueStr);
- buf.append(" > ");
- buf.append(newValueStr);
- buf.append("\n");
- } else if (pd.getType() == PropertyDiff.ADDED
- && !"".equals(newValueStr)) {
- // we don't list property that have been added with an
- // empty string as value
- buf.append(prop).append(": ");
- buf.append(" + ");
- buf.append(newValueStr);
- buf.append("\n");
- } else if (pd.getType() == PropertyDiff.REMOVED) {
- buf.append(prop).append(": ");
- buf.append(" - ");
- buf.append(refValueStr);
- buf.append("\n");
- }
- }
- buf.append("\n");
- main.append(buf);
- }
- styledText.setText(main.toString());
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot generate history for node", e);
- }
-
- }
-
- public List<VersionDiff> listHistoryDiff() {
- try {
- List<VersionDiff> res = new ArrayList<VersionDiff>();
- VersionManager versionManager = currentNode.getSession()
- .getWorkspace().getVersionManager();
- VersionHistory versionHistory = versionManager
- .getVersionHistory(currentNode.getPath());
-
- VersionIterator vit = versionHistory.getAllLinearVersions();
- while (vit.hasNext()) {
- Version version = vit.nextVersion();
- Node node = version.getFrozenNode();
- Version predecessor = null;
- try {
- predecessor = version.getLinearPredecessor();
- } catch (Exception e) {
- // no predecessor seems to throw an exception even if it
- // shouldn't...
- }
- if (predecessor == null) {// original
- } else {
- Map<String, PropertyDiff> diffs = JcrUtils.diffProperties(
- predecessor.getFrozenNode(), node);
- if (!diffs.isEmpty()) {
- String lastUserName = null;
- Calendar lastUpdate = null;
- try {
- if (currentNode
- .isNodeType(NodeType.MIX_LAST_MODIFIED)) {
- lastUserName = node.getProperty(
- Property.JCR_LAST_MODIFIED_BY)
- .getString();
- lastUpdate = node.getProperty(
- Property.JCR_LAST_MODIFIED).getDate();
- } else
- lastUpdate = version.getProperty(
- Property.JCR_CREATED).getDate();
-
- } catch (Exception e) {
- // Silent that info is optional
- }
- VersionDiff vd = new VersionDiff(lastUserName,
- lastUpdate, diffs);
- res.add(vd);
- }
- }
- }
- return res;
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot generate history for node ");
- }
-
- }
-
- @Override
- public void setActive(boolean active) {
- super.setActive(active);
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.jcr.internal.parts;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-
-/**
- * An editor input based on three strings define a node :
- * <ul>
- * <li>complete path to the node</li>
- * <li>the workspace name</li>
- * <li>the repository alias</li>
- * </ul>
- * In a single workspace and/or repository environment, name and alias can be
- * null.
- *
- * Note : unused for the time being.
- */
-
-public class StringNodeEditorInput implements IEditorInput {
- private final String path;
- private final String repositoryAlias;
- private final String workspaceName;
-
- /**
- * In order to implement a generic explorer that supports remote and multi
- * workspaces repositories, node path can be detailed by these strings.
- *
- * @param repositoryAlias
- * : can be null
- * @param workspaceName
- * : can be null
- * @param path
- */
- public StringNodeEditorInput(String repositoryAlias, String workspaceName,
- String path) {
- this.path = path;
- this.repositoryAlias = repositoryAlias;
- this.workspaceName = workspaceName;
- }
-
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
- return null;
- }
-
- public boolean exists() {
- return true;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return null;
- }
-
- public String getName() {
- return path;
- }
-
- public String getRepositoryAlias() {
- return repositoryAlias;
- }
-
- public String getWorkspaceName() {
- return workspaceName;
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
- public String getToolTipText() {
- return path;
- }
-
- public String getPath() {
- return path;
- }
-
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
-
- StringNodeEditorInput other = (StringNodeEditorInput) obj;
-
- if (!path.equals(other.getPath()))
- return false;
-
- String own = other.getWorkspaceName();
- if ((workspaceName == null && own != null)
- || (workspaceName != null && (own == null || !workspaceName
- .equals(own))))
- return false;
-
- String ora = other.getRepositoryAlias();
- if ((repositoryAlias == null && ora != null)
- || (repositoryAlias != null && (ora == null || !repositoryAlias
- .equals(ora))))
- return false;
-
- return true;
- }
-}
import org.argeo.eclipse.ui.ColumnDefinition;
import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.parts.LdifUsersTable;
-import org.argeo.eclipse.ui.workbench.users.internal.UsersUtils;
+import org.argeo.eclipse.ui.workbench.internal.users.UsersUtils;
import org.argeo.osgi.useradmin.LdifName;
import org.eclipse.jface.dialogs.TrayDialog;
import org.eclipse.jface.viewers.DoubleClickEvent;
import javax.naming.ldap.LdapName;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.workbench.users.internal.UsersImages;
-import org.argeo.eclipse.ui.workbench.users.internal.UsersUtils;
+import org.argeo.eclipse.ui.workbench.internal.users.UsersImages;
+import org.argeo.eclipse.ui.workbench.internal.users.UsersUtils;
import org.argeo.osgi.useradmin.LdifName;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.ColumnLabelProvider;
+++ /dev/null
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.argeo.eclipse.ui.workbench.users.internal;
-
-import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
-import org.eclipse.swt.graphics.Image;
-
-/** Specific users icons. TODO centralize and use an image registry */
-public class UsersImages {
- private final static String PREFIX = "icons/";
-
- public final static Image ICON_USER = WorkbenchUiPlugin.getImageDescriptor(
- PREFIX + "user.gif").createImage();
- public final static Image ICON_GROUP = WorkbenchUiPlugin
- .getImageDescriptor(PREFIX + "users.gif").createImage();
- public final static Image ICON_ROLE = WorkbenchUiPlugin.getImageDescriptor(
- PREFIX + "role.gif").createImage();
-}
+++ /dev/null
-package org.argeo.eclipse.ui.workbench.users.internal;
-
-import java.security.AccessController;
-import java.util.List;
-
-import javax.naming.InvalidNameException;
-import javax.naming.ldap.LdapName;
-import javax.naming.ldap.Rdn;
-import javax.security.auth.Subject;
-import javax.security.auth.x500.X500Principal;
-
-import org.argeo.ArgeoException;
-import org.argeo.osgi.useradmin.LdifName;
-import org.osgi.service.useradmin.Role;
-import org.osgi.service.useradmin.User;
-
-/** Utility methods to manage user concepts in the ui.workbench bundle */
-public class UsersUtils {
- // TODO this constant is defined in the CMS
- public final static String ROLES_BASEDN = "ou=roles,ou=node";
-
- public final static boolean isCurrentUser(User user) {
- String userName = getProperty(user, LdifName.dn.name());
- try {
- LdapName selfUserName = getLdapName();
- LdapName userLdapName = new LdapName(userName);
- if (userLdapName.equals(selfUserName))
- return true;
- else
- return false;
- } catch (InvalidNameException e) {
- throw new ArgeoException("User " + user + " has an unvalid dn: "
- + userName, e);
- }
- }
-
- public final static LdapName getLdapName() {
- Subject subject = Subject.getSubject(AccessController.getContext());
- String name = subject.getPrincipals(X500Principal.class).iterator()
- .next().toString();
- LdapName dn;
- try {
- dn = new LdapName(name);
- } catch (InvalidNameException e) {
- throw new ArgeoException("Invalid user dn " + name, e);
- }
- return dn;
- }
-
- public final static String getCommonName(User user) {
- return getProperty(user, LdifName.cn.name());
- }
-
- /** Simply retrieves a display name of the relevant domain */
- public final static String getDomainName(User user) {
- String dn = (String) user.getProperties().get(LdifName.dn.name());
- if (dn.endsWith(ROLES_BASEDN))
- return "System roles";
- try {
- LdapName name;
- name = new LdapName(dn);
- List<Rdn> rdns = name.getRdns();
- String dname = null;
- int i = 0;
- loop: while (i < rdns.size()) {
- Rdn currrRdn = rdns.get(i);
- if (!"dc".equals(currrRdn.getType()))
- break loop;
- else {
- String currVal = (String) currrRdn.getValue();
- dname = dname == null ? currVal : currVal + "." + dname;
- }
- i++;
- }
- return dname;
- } catch (InvalidNameException e) {
- throw new ArgeoException("Unable to get domain name for " + dn, e);
- }
- }
-
- public final static String getProperty(Role role, String key) {
- Object obj = role.getProperties().get(key);
- if (obj != null)
- return (String) obj;
- else
- return "";
- }
-
- /*
- * INTERNAL METHODS: Below methods are meant to stay here and are not part
- * of a potential generic backend to manage the useradmin
- */
- public final static boolean notNull(String string) {
- if (string == null)
- return false;
- else
- return !"".equals(string.trim());
- }
-
-}
\ No newline at end of file