<and>
<or>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.SingleJcrNode">
+ value="org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem">
</instanceof>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.WorkspaceNode">
+ value="org.argeo.jcr.ui.explorer.model.WorkspaceElem">
</instanceof>
</or>
<with variable="activeMenuSelection"><count value="1"/></with>
<and>
<or>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.SingleJcrNode">
+ value="org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem">
</instanceof>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.WorkspaceNode">
+ value="org.argeo.jcr.ui.explorer.model.WorkspaceElem">
</instanceof>
</or>
<with variable="activeMenuSelection"><count value="1"/></with>
<and>
<or>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.RepositoryNode">
+ value="org.argeo.jcr.ui.explorer.model.RepositoryElem">
</instanceof>
</or>
<with variable="activeMenuSelection"><count value="1"/></with>
<iterate>
<or>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.SingleJcrNode">
+ value="org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem">
</instanceof>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.WorkspaceNode">
+ value="org.argeo.jcr.ui.explorer.model.WorkspaceElem">
</instanceof>
</or>
</iterate>
<and>
<or>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.SingleJcrNode">
+ value="org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem">
</instanceof>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.WorkspaceNode">
+ value="org.argeo.jcr.ui.explorer.model.WorkspaceElem">
</instanceof>
</or>
<with variable="activeMenuSelection"><count value="1"/></with>
<iterate>
<or>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.RepositoriesNode">
+ value="org.argeo.jcr.ui.explorer.model.RepositoriesElem">
</instanceof>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.RepositoryNode">
+ value="org.argeo.jcr.ui.explorer.model.RepositoryElem">
</instanceof>
</or>
</iterate>
<iterate>
<or>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.RemoteRepositoryNode">
+ value="org.argeo.jcr.ui.explorer.model.RemoteRepositoryElem">
</instanceof>
</or>
</iterate>
<iterate>
<or>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.SingleJcrNode">
+ value="org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem">
</instanceof>
<instanceof
- value="org.argeo.jcr.ui.explorer.model.WorkspaceNode">
+ value="org.argeo.jcr.ui.explorer.model.WorkspaceElem">
</instanceof>
</or>
</iterate>
import org.argeo.jcr.ArgeoJcrConstants;
import org.argeo.jcr.RepositoryRegister;
import org.argeo.jcr.UserJcrUtils;
-import org.argeo.jcr.ui.explorer.model.RepositoriesNode;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
+import org.argeo.jcr.ui.explorer.model.RepositoriesElem;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
import org.argeo.jcr.ui.explorer.utils.TreeObjectsComparator;
import org.argeo.util.security.Keyring;
import org.eclipse.jface.viewers.ITreeContentProvider;
final private boolean sortChildren;
// reference for cleaning
- private SingleJcrNode homeNode = null;
- private RepositoriesNode repositoriesNode = null;
+ private SingleJcrNodeElem homeNode = null;
+ private RepositoriesElem repositoriesNode = null;
// Utils
private TreeObjectsComparator itemComparator = new TreeObjectsComparator();
// TODO : find a way to dynamically get alias for the node
if (homeNode != null)
homeNode.dispose();
- homeNode = new SingleJcrNode(null, userHome,
+ homeNode = new SingleJcrNodeElem(null, userHome,
userSession.getUserID(), ArgeoJcrConstants.ALIAS_NODE);
}
}
if (repositoryRegister != null) {
if (repositoriesNode != null)
repositoriesNode.dispose();
- repositoriesNode = new RepositoriesNode("Repositories",
+ repositoriesNode = new RepositoriesElem("Repositories",
repositoryRegister, repositoryFactory, null, userSession,
keyring);
}
}
public boolean hasChildren(Object element) {
- if (element instanceof RepositoriesNode) {
- RepositoryRegister rr = ((RepositoriesNode) element)
+ if (element instanceof RepositoriesElem) {
+ RepositoryRegister rr = ((RepositoriesElem) element)
.getRepositoryRegister();
return rr.getRepositories().size() > 0;
} else if (element instanceof TreeParent) {
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.jcr.DefaultNodeLabelProvider;
import org.argeo.eclipse.ui.jcr.JcrImages;
-import org.argeo.jcr.ui.explorer.model.RemoteRepositoryNode;
-import org.argeo.jcr.ui.explorer.model.RepositoriesNode;
-import org.argeo.jcr.ui.explorer.model.RepositoryNode;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
-import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.model.RemoteRepositoryElem;
+import org.argeo.jcr.ui.explorer.model.RepositoriesElem;
+import org.argeo.jcr.ui.explorer.model.RepositoryElem;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
+import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
import org.eclipse.swt.graphics.Image;
public class NodeLabelProvider extends DefaultNodeLabelProvider {
public String getText(Object element) {
try {
- if (element instanceof SingleJcrNode) {
- SingleJcrNode sjn = (SingleJcrNode) element;
+ if (element instanceof SingleJcrNodeElem) {
+ SingleJcrNodeElem sjn = (SingleJcrNodeElem) element;
return getText(sjn.getNode());
} else
return super.getText(element);
@Override
public Image getImage(Object element) {
- if (element instanceof RemoteRepositoryNode) {
- if (((RemoteRepositoryNode) element).isConnected())
+ if (element instanceof RemoteRepositoryElem) {
+ if (((RemoteRepositoryElem) element).isConnected())
return JcrImages.REMOTE_CONNECTED;
else
return JcrImages.REMOTE_DISCONNECTED;
- } else if (element instanceof RepositoryNode) {
- if (((RepositoryNode) element).isConnected())
+ } else if (element instanceof RepositoryElem) {
+ if (((RepositoryElem) element).isConnected())
return JcrImages.REPOSITORY_CONNECTED;
else
return JcrImages.REPOSITORY_DISCONNECTED;
- } else if (element instanceof WorkspaceNode) {
- if (((WorkspaceNode) element).isConnected())
+ } else if (element instanceof WorkspaceElem) {
+ if (((WorkspaceElem) element).isConnected())
return JcrImages.WORKSPACE_CONNECTED;
else
return JcrImages.WORKSPACE_DISCONNECTED;
- } else if (element instanceof RepositoriesNode) {
+ } else if (element instanceof RepositoriesElem) {
return JcrImages.REPOSITORIES;
- } else if (element instanceof SingleJcrNode)
+ } else if (element instanceof SingleJcrNodeElem)
try {
- return super.getImage(((SingleJcrNode) element).getNode());
+ return super.getImage(((SingleJcrNodeElem) element).getNode());
} catch (RepositoryException e) {
return null;
}
import org.argeo.eclipse.ui.dialogs.SingleValue;
import org.argeo.eclipse.ui.jcr.JcrUiPlugin;
import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
-import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
+import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.ui.handlers.HandlerUtil;
/**
- * Adds a node of type nt:folder, only on {@link SingleJcrNode} and
- * {@link WorkspaceNode} TreeObject types.
+ * Adds a node of type nt:folder, only on {@link SingleJcrNodeElem} and
+ * {@link WorkspaceElem} TreeObject types.
*
*
* This handler assumes that a selection provider is available and picks only
TreeParent treeParentNode = null;
Node jcrParentNode = null;
- if (obj instanceof SingleJcrNode) {
+ if (obj instanceof SingleJcrNodeElem) {
treeParentNode = (TreeParent) obj;
- jcrParentNode = ((SingleJcrNode) treeParentNode).getNode();
- } else if (obj instanceof WorkspaceNode) {
+ jcrParentNode = ((SingleJcrNodeElem) treeParentNode).getNode();
+ } else if (obj instanceof WorkspaceElem) {
treeParentNode = (TreeParent) obj;
- jcrParentNode = ((WorkspaceNode) treeParentNode).getRootNode();
+ jcrParentNode = ((WorkspaceElem) treeParentNode).getRootNode();
} else
return null;
import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
-import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
+import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
import org.argeo.jcr.ui.explorer.wizards.ChangeRightsWizard;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
TreeParent treeParentNode = null;
Node jcrParentNode = null;
- if (obj instanceof SingleJcrNode) {
+ if (obj instanceof SingleJcrNodeElem) {
treeParentNode = (TreeParent) obj;
- jcrParentNode = ((SingleJcrNode) treeParentNode).getNode();
- } else if (obj instanceof WorkspaceNode) {
+ jcrParentNode = ((SingleJcrNodeElem) treeParentNode).getNode();
+ } else if (obj instanceof WorkspaceElem) {
treeParentNode = (TreeParent) obj;
- jcrParentNode = ((WorkspaceNode) treeParentNode).getRootNode();
+ jcrParentNode = ((WorkspaceElem) treeParentNode).getRootNode();
} else
return null;
import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.dialogs.SingleValue;
import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
-import org.argeo.jcr.ui.explorer.model.RepositoryNode;
+import org.argeo.jcr.ui.explorer.model.RepositoryElem;
import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
if (selection != null && !selection.isEmpty()
&& selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
- if (!(obj instanceof RepositoryNode))
+ if (!(obj instanceof RepositoryElem))
return null;
- RepositoryNode repositoryNode = (RepositoryNode) obj;
+ RepositoryElem repositoryNode = (RepositoryElem) obj;
String workspaceName = SingleValue.ask("Workspace name",
"Enter workspace name");
if (workspaceName != null) {
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
-import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
+import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
StringBuffer buf = new StringBuffer("");
Iterator<?> lst = ((IStructuredSelection) selection).iterator();
while (lst.hasNext()) {
- SingleJcrNode sjn = ((SingleJcrNode) lst.next());
+ SingleJcrNodeElem sjn = ((SingleJcrNodeElem) lst.next());
buf.append(sjn.getName()).append(' ');
}
Boolean ok = MessageDialog.openConfirm(
if (ok) {
Iterator<?> it = ((IStructuredSelection) selection).iterator();
Object obj = null;
- SingleJcrNode ancestor = null;
- WorkspaceNode rootAncestor = null;
+ SingleJcrNodeElem ancestor = null;
+ WorkspaceElem rootAncestor = null;
try {
while (it.hasNext()) {
obj = it.next();
- if (obj instanceof SingleJcrNode) {
+ if (obj instanceof SingleJcrNodeElem) {
// Cache objects
- SingleJcrNode sjn = (SingleJcrNode) obj;
+ SingleJcrNodeElem sjn = (SingleJcrNodeElem) obj;
TreeParent tp = (TreeParent) sjn.getParent();
Node node = sjn.getNode();
tp.removeChild(sjn);
// Check if the parent is the root node
- if (tp instanceof WorkspaceNode)
- rootAncestor = (WorkspaceNode) tp;
+ if (tp instanceof WorkspaceElem)
+ rootAncestor = (WorkspaceElem) tp;
else
- ancestor = getOlder(ancestor, (SingleJcrNode) tp);
+ ancestor = getOlder(ancestor, (SingleJcrNodeElem) tp);
}
}
if (rootAncestor != null)
return null;
}
- private SingleJcrNode getOlder(SingleJcrNode A, SingleJcrNode B) {
+ private SingleJcrNodeElem getOlder(SingleJcrNodeElem A, SingleJcrNodeElem B) {
try {
if (A == null)
return B == null ? null : B;
import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.jcr.JcrUtils;
import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
-import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
+import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
Object obj = it.next();
String curPath;
Node node;
- if (obj instanceof SingleJcrNode) {
- node = ((SingleJcrNode) obj).getNode();
+ if (obj instanceof SingleJcrNodeElem) {
+ node = ((SingleJcrNodeElem) obj).getNode();
curPath = node.getSession().getWorkspace().getName();
curPath += "/" + node.getPath();
- } else if (obj instanceof WorkspaceNode) {
- node = ((WorkspaceNode) obj).getRootNode();
+ } else if (obj instanceof WorkspaceElem) {
+ node = ((WorkspaceElem) obj).getRootNode();
curPath = node.getSession().getWorkspace().getName();
} else
// unvalid object type
import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
-import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
+import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
import org.argeo.jcr.ui.explorer.wizards.ImportFileSystemWizard;
import org.eclipse.core.commands.AbstractHandler;
Object obj = ((IStructuredSelection) selection).getFirstElement();
try {
Node folder = null;
- if (obj instanceof SingleJcrNode) {
- folder = ((SingleJcrNode) obj).getNode();
- } else if (obj instanceof WorkspaceNode) {
- folder = ((WorkspaceNode) obj).getRootNode();
+ if (obj instanceof SingleJcrNodeElem) {
+ folder = ((SingleJcrNodeElem) obj).getNode();
+ } else if (obj instanceof WorkspaceElem) {
+ folder = ((WorkspaceElem) obj).getRootNode();
} else {
ErrorFeedback.show(JcrExplorerPlugin
.getMessage("warningInvalidNodeToImport"));
*/
package org.argeo.jcr.ui.explorer.commands;
-import org.argeo.jcr.ui.explorer.model.RemoteRepositoryNode;
+import org.argeo.jcr.ui.explorer.model.RemoteRepositoryElem;
import org.argeo.jcr.ui.explorer.views.GenericJcrBrowser;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
&& selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
- if (obj instanceof RemoteRepositoryNode) {
- ((RemoteRepositoryNode) obj).remove();
+ if (obj instanceof RemoteRepositoryElem) {
+ ((RemoteRepositoryElem) obj).remove();
view.refresh(null);
}
}
--- /dev/null
+package org.argeo.jcr.ui.explorer.model;
+
+import javax.jcr.Repository;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.MaintainedRepository;
+
+/** Wraps 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.jcr.ui.explorer.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.jcr.ui.explorer.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 RemoteRepositoryNode extends RepositoryNode {
- 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 RemoteRepositoryNode(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.jcr.ui.explorer.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.ErrorFeedback;
+import org.argeo.eclipse.ui.TreeParent;
+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. 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.jcr.ui.explorer.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.ErrorFeedback;
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.jcr.ArgeoNames;
-import org.argeo.jcr.RepositoryRegister;
-import org.argeo.jcr.UserJcrUtils;
-import org.argeo.util.security.Keyring;
-
-/**
- * UI Tree component. Implements the Argeo abstraction of a
- * {@link RepositoryFactory} that enable a user to "mount" various repositories
- * in a single Tree like View. It is usually meant to be at the root of the UI
- * Tree and thus {@link getParent()} method will return null.
- *
- * The {@link RepositoryFactory} is injected at instantiation time and must be
- * use get or register new {@link Repository} objects upon which a reference is
- * kept here.
- */
-
-public class RepositoriesNode extends TreeParent 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 RepositoriesNode(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()) {
- super.addChild(new RepositoryNode(name, refRepos.get(name),
- 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 {
- RemoteRepositoryNode remoteRepositoryNode = new RemoteRepositoryNode(
- 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.jcr.ui.explorer.model;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+
+/**
+ * UI Tree component. Wraps a JCR {@link Repository}. It also keeps a reference
+ * to its parent Tree Ui component; typically the unique {@link Repositories}
+ * object of the current view to enable bi-directionnal browsing in the tree.
+ */
+
+public class 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(null);
+ 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.jcr.ui.explorer.model;
-
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-
-/**
- * UI Tree component. Wraps a JCR {@link Repository}. It also keeps a reference
- * to its parent Tree Ui component; typically the unique {@link Repositories}
- * object of the current view to enable bi-directionnal browsing in the tree.
- */
-
-public class RepositoryNode extends TreeParent implements UiNode {
- private String alias;
- protected Repository repository;
- private Session defaultSession = null;
-
- /** Create a new repository with alias = name */
- public RepositoryNode(String alias, Repository repository, TreeParent parent) {
- this(alias, alias, repository, parent);
- }
-
- /** Create a new repository with distinct name & alias */
- public RepositoryNode(String alias, String name, Repository repository,
- TreeParent parent) {
- super(name);
- this.repository = repository;
- setParent(parent);
- this.alias = alias;
- }
-
- public void login() {
- try {
- defaultSession = repositoryLogin(null);
- String[] wkpNames = defaultSession.getWorkspace()
- .getAccessibleWorkspaceNames();
- for (String wkpName : wkpNames) {
- if (wkpName.equals(defaultSession.getWorkspace().getName()))
- addChild(new WorkspaceNode(this, wkpName, defaultSession));
- else
- addChild(new WorkspaceNode(this, wkpName));
- }
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot connect to repository " + alias, e);
- }
- }
-
- /**
- * 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.jcr.ui.explorer.model;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Workspace;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.TreeParent;
-
-/**
- * UI Tree component. Wraps a node of a JCR {@link Workspace}. It also keeps a
- * reference to its parent node that can either be a {@link WorkspaceNode}, a
- * {@link SingleJcrNode} or null if the node is "mounted" as the root of the UI
- * tree.
- */
-
-public class SingleJcrNode extends TreeParent implements UiNode {
-
- private final Node node;
- private String alias = null;
-
- // keeps a local reference to the node's name to avoid exception when the
- // session is lost
- // private final String name;
-
- /** Creates a new UiNode in the UI Tree */
- public SingleJcrNode(TreeParent parent, Node node, String name) {
- super(name);
- setParent(parent);
- this.node = node;
- }
-
- /**
- * Creates a new UiNode in the UI Tree, keeping a reference to the alias of
- * the corresponding repository in the current UI environment. It is useful
- * to be able to mount nodes as roots of the UI tree.
- */
- public SingleJcrNode(TreeParent parent, Node node, String name, String alias) {
- super(name);
- setParent(parent);
- this.node = node;
- this.alias = alias;
- }
-
- /** returns the node wrapped by the current Ui object */
- public Node getNode() {
- return node;
- }
-
- /**
- * Returns the alias corresponding to the repository abstraction that
- * contains current node. If the current object is mounted as root of the UI
- * tree, the alias is stored in the object. Otherwise, we must browse the
- * tree backward to the RepositoryNode.
- *
- * Alias is then cached in the current object so that next time it will be
- * here.
- */
- public String getAlias() {
- if (alias == null) {
- alias = ((UiNode) getParent()).getAlias();
- }
- return alias;
- }
-
- /**
- * Override normal 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 SingleJcrNode(this, curNode, curNode.getName()));
- }
- return super.getChildren();
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexcpected error while initializing children SingleJcrNode",
- re);
- }
- }
- }
-
- @Override
- public boolean hasChildren() {
- try {
- 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.jcr.ui.explorer.model;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Workspace;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.TreeParent;
+
+/**
+ * UI Tree component. Wraps a node of a JCR {@link Workspace}. It also keeps a
+ * reference to its parent node that can either be a {@link 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.jcr.ui.explorer.model;
-
-/**
- * insure presence of the useful specific methods used in the building a UI Tree
- * based on JCR repositories
- */
-public interface UiNode {
-
- public String getAlias();
-}
--- /dev/null
+/*
+ * 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.jcr.ui.explorer.model;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Workspace;
+
+import 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 Session getSession() {
+ return session;
+ }
+
+ public Node getRootNode() {
+ try {
+ if (session != null)
+ return session.getRootNode();
+ else
+ return null;
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot get root node of workspace "
+ + getName(), e);
+ }
+ }
+
+ public void login() {
+ try {
+ 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 void logout() {
+ clearChildren();
+ JcrUtils.logoutQuietly(session);
+ }
+
+ @Override
+ public 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.jcr.ui.explorer.model;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.Workspace;
-
-import 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 RepositoryNode}, to be able to
- * retrieve alias of the current used repository
- */
-public class WorkspaceNode extends TreeParent implements UiNode {
- private Session session = null;
-
- public WorkspaceNode(RepositoryNode parent, String name) {
- this(parent, name, null);
- }
-
- public WorkspaceNode(RepositoryNode parent, String name, Session session) {
- super(name);
- this.session = session;
- setParent(parent);
- }
-
- public Session getSession() {
- return session;
- }
-
- public Node getRootNode() {
- try {
- if (session != null)
- return session.getRootNode();
- else
- return null;
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot get root node of workspace "
- + getName(), e);
- }
- }
-
- public void login() {
- try {
- session = ((RepositoryNode) 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 void logout() {
- clearChildren();
- JcrUtils.logoutQuietly(session);
- }
-
- /** Returns the alias of the parent Repository */
- public String getAlias() {
- return ((UiNode) getParent()).getAlias();
- }
-
- @Override
- public 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 SingleJcrNode(this, node, node.getName()));
- }
- return super.getChildren();
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Cannot initialize WorkspaceNode UI object."
- + getName(), e);
- }
- }
- }
-}
import org.argeo.jcr.ui.explorer.JcrExplorerPlugin;
import org.argeo.jcr.ui.explorer.editors.GenericNodeEditor;
import org.argeo.jcr.ui.explorer.editors.GenericNodeEditorInput;
-import org.argeo.jcr.ui.explorer.model.RepositoryNode;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
-import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.model.RepositoryElem;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
+import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
return;
Object obj = ((IStructuredSelection) event.getSelection())
.getFirstElement();
- if (obj instanceof RepositoryNode) {
- RepositoryNode rpNode = (RepositoryNode) obj;
+ if (obj instanceof RepositoryElem) {
+ RepositoryElem rpNode = (RepositoryElem) obj;
if (!rpNode.isConnected()) {
rpNode.login();
nodeViewer.refresh(obj);
}
// else do nothing
- } else if (obj instanceof WorkspaceNode) {
- WorkspaceNode wn = (WorkspaceNode) 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 SingleJcrNode) {
- SingleJcrNode sjn = (SingleJcrNode) obj;
+ } else if (obj instanceof SingleJcrNodeElem) {
+ SingleJcrNodeElem sjn = (SingleJcrNodeElem) obj;
Node node = sjn.getNode();
try {
if (node.isNodeType(NodeType.NT_FILE)) {
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.jcr.ui.explorer.model.RepositoriesNode;
-import org.argeo.jcr.ui.explorer.model.RepositoryNode;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
-import org.argeo.jcr.ui.explorer.model.WorkspaceNode;
+import org.argeo.jcr.ui.explorer.model.RepositoriesElem;
+import org.argeo.jcr.ui.explorer.model.RepositoryElem;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
+import org.argeo.jcr.ui.explorer.model.WorkspaceElem;
/** Centralizes some useful methods to build UIs with JCR */
public class JcrUiUtils {
boolean doRefresh = false;
try {
- if (element instanceof SingleJcrNode) {
- curNode = ((SingleJcrNode) element).getNode();
- } else if (element instanceof WorkspaceNode) {
- curNode = ((WorkspaceNode) element).getRootNode();
+ 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 RepositoryNode) {
- RepositoryNode rn = (RepositoryNode) element;
+ 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 RepositoriesNode) {
- RepositoriesNode rn = (RepositoriesNode) element;
+ } else if (element instanceof RepositoriesElem) {
+ RepositoriesElem rn = (RepositoriesElem) element;
if (element.getChildren().length != rn.getRepositoryRegister()
.getRepositories().size())
doRefresh = true;
import org.argeo.jcr.ui.explorer.browser.NodeContentProvider;
import org.argeo.jcr.ui.explorer.browser.NodeLabelProvider;
import org.argeo.jcr.ui.explorer.browser.PropertiesContentProvider;
-import org.argeo.jcr.ui.explorer.model.SingleJcrNode;
+import org.argeo.jcr.ui.explorer.model.SingleJcrNodeElem;
import org.argeo.jcr.ui.explorer.utils.GenericNodeDoubleClickListener;
import org.argeo.jcr.ui.explorer.utils.JcrUiUtils;
import org.argeo.util.security.Keyring;
IStructuredSelection sel = (IStructuredSelection) event
.getSelection();
Object firstItem = sel.getFirstElement();
- if (firstItem instanceof SingleJcrNode)
+ if (firstItem instanceof SingleJcrNodeElem)
propertiesViewer
- .setInput(((SingleJcrNode) firstItem)
+ .setInput(((SingleJcrNodeElem) firstItem)
.getNode());
} else {
propertiesViewer.setInput(getViewSite());