import org.argeo.eclipse.ui.EclipseUiException;
import org.argeo.eclipse.ui.specific.OpenFile;
import org.argeo.eclipse.ui.specific.SingleSourcingException;
+import org.argeo.jcr.JcrUtils;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
Object obj = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (obj instanceof RepositoryElem) {
RepositoryElem rpNode = (RepositoryElem) obj;
- if (!rpNode.isConnected()) {
+ if (rpNode.isConnected()) {
+ rpNode.logout();
+ } else {
rpNode.login();
- nodeViewer.refresh(obj);
}
+ nodeViewer.refresh(obj);
} else if (obj instanceof WorkspaceElem) {
WorkspaceElem wn = (WorkspaceElem) obj;
if (wn.isConnected())
// we copy the node to a tmp file to be opened as a dirty
// workaround
File tmpFile = null;
- OutputStream os = null;
- InputStream is = null;
+ // OutputStream os = null;
+ // InputStream is = null;
int i = name.lastIndexOf('.');
String prefix, suffix;
if (i == -1) {
prefix = name.substring(0, i);
suffix = name.substring(i);
}
- try {
+ Binary binary = null;
+ try (OutputStream os = new FileOutputStream(tmpFile)) {
tmpFile = File.createTempFile(prefix, suffix);
tmpFile.deleteOnExit();
- os = new FileOutputStream(tmpFile);
- Binary binary = node.getNode(JCR_CONTENT).getProperty(JCR_DATA).getBinary();
- is = binary.getStream();
- IOUtils.copy(is, os);
+ binary = node.getNode(JCR_CONTENT).getProperty(JCR_DATA).getBinary();
+ try (InputStream is = binary.getStream();) {
+ IOUtils.copy(is, os);
+ }
} catch (IOException e) {
throw new SingleSourcingException("Cannot open file " + prefix + "." + suffix, e);
} finally {
- IOUtils.closeQuietly(is);
- IOUtils.closeQuietly(os);
+ // IOUtils.closeQuietly(is);
+ // IOUtils.closeQuietly(os);
+ JcrUtils.closeQuietly(binary);
}
Path path = Paths.get(tmpFile.getAbsolutePath());
String uri = path.toUri().toString();
*/
package org.argeo.cms.ui.workbench.internal.jcr;
+import javax.jcr.NamespaceException;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.NodeType;
import org.argeo.cms.ui.workbench.internal.jcr.model.WorkspaceElem;
import org.argeo.cms.ui.workbench.jcr.JcrImages;
import org.argeo.eclipse.ui.EclipseUiException;
+import org.argeo.naming.LdapAttrs;
import org.argeo.node.NodeTypes;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.swt.graphics.Image;
} else
return super.getText(element);
} catch (RepositoryException e) {
- throw new EclipseUiException(
- "Unexpected JCR error while getting node name.");
+ throw new EclipseUiException("Unexpected JCR error while getting node name.");
}
}
for (NodeType type : node.getMixinNodeTypes())
mixins.append(' ').append(type.getName());
- return label + " [" + node.getPrimaryNodeType().getName() + mixins
- + "]";
+ return label + " [" + node.getPrimaryNodeType().getName() + mixins + "]";
}
@Override
return JcrImages.FOLDER;
else if (node.getPrimaryNodeType().isNodeType(NodeType.NT_RESOURCE))
return JcrImages.BINARY;
- else if (node.isNodeType(NodeTypes.NODE_USER_HOME))
- return JcrImages.HOME;
- else
- return JcrImages.NODE;
+ try {
+ // optimizes
+ if (node.hasProperty(LdapAttrs.uid.property()) && node.isNodeType(NodeTypes.NODE_USER_HOME))
+ return JcrImages.HOME;
+ } catch (NamespaceException e) {
+ // node namespace is not registered in this repo
+ }
+ return JcrImages.NODE;
} catch (RepositoryException e) {
- log.warn("Error while retrieving type for " + node
- + " in order to display corresponding image");
+ log.warn("Error while retrieving type for " + node + " in order to display corresponding image");
e.printStackTrace();
return null;
}
import org.argeo.eclipse.ui.EclipseUiException;
import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.jcr.JcrUtils;
/**
- * UI Tree component that wraps a JCR {@link Repository}. It also keeps a reference
- * to its parent Tree Ui component; typically the unique {@link RepositoriesElem}
- * object of the current view to enable bi-directionnal browsing in the tree.
+ * UI Tree component that wraps a JCR {@link Repository}. It also keeps a
+ * reference to its parent Tree Ui component; typically the unique
+ * {@link RepositoriesElem} object of the current view to enable bi-directionnal
+ * browsing in the tree.
*/
public class RepositoryElem extends TreeParent {
public void login() {
try {
defaultSession = repositoryLogin("main");
- String[] wkpNames = defaultSession.getWorkspace()
- .getAccessibleWorkspaceNames();
+ String[] wkpNames = defaultSession.getWorkspace().getAccessibleWorkspaceNames();
for (String wkpName : wkpNames) {
if (wkpName.equals(defaultSession.getWorkspace().getName()))
addChild(new WorkspaceElem(this, wkpName, defaultSession));
}
}
+ public synchronized void logout() {
+ for (Object child : getChildren()) {
+ if (child instanceof WorkspaceElem)
+ ((WorkspaceElem) child).logout();
+ }
+ clearChildren();
+ JcrUtils.logoutQuietly(defaultSession);
+ defaultSession = null;
+ }
+
/**
- * Actual call to the
- * {@link Repository#login(javax.jcr.Credentials, String)} method. To be
- * overridden.
+ * Actual call to the {@link Repository#login(javax.jcr.Credentials, String)}
+ * method. To be overridden.
*/
- protected Session repositoryLogin(String workspaceName)
- throws RepositoryException {
+ protected Session repositoryLogin(String workspaceName) throws RepositoryException {
return repository.login(workspaceName);
}