#spring.security.strategy=MODE_INHERITABLETHREADLOCAL
+# anonymous url: http://localhost:7070/ui/public
+# authenticated url: http://localhost:7070/ui/node
+
# LDAP (Apache DS)
#argeo.ads.init.ldif=osgibundle:init-argeo.ldif
<property name="keyring" ref="keyring" />
</bean>
-</beans>
+ <!-- WORKSPACE CRUD -->
+ <bean id="createWorkspace" class="org.argeo.slc.client.ui.dist.commands.CreateWorkspace">
+ <property name="repositoryFactory" ref="repositoryFactory" />
+ <property name="nodeRepository" ref="nodeRepository" />
+ <property name="keyring" ref="keyring" />
+ </bean>
+ <bean id="copyWorkspace" class="org.argeo.slc.client.ui.dist.commands.CopyWorkspace">
+ <property name="repositoryFactory" ref="repositoryFactory" />
+ <property name="nodeRepository" ref="nodeRepository" />
+ <property name="keyring" ref="keyring" />
+ </bean>
+ <bean id="mergeWorkspaces" class="org.argeo.slc.client.ui.dist.commands.MergeWorkspaces">
+ <property name="repositoryFactory" ref="repositoryFactory" />
+ <property name="nodeRepository" ref="nodeRepository" />
+ <property name="keyring" ref="keyring" />
+ </bean>
+ <bean id="deleteWorkspace" class="org.argeo.slc.client.ui.dist.commands.DeleteWorkspace">
+ <property name="repositoryFactory" ref="repositoryFactory" />
+ <property name="nodeRepository" ref="nodeRepository" />
+ <property name="keyring" ref="keyring" />
+ </bean>
+ <bean id="publishWorkspace" class="org.argeo.slc.client.ui.dist.commands.PublishWorkspace">
+ <property name="repositoryFactory" ref="repositoryFactory" />
+ <property name="nodeRepository" ref="nodeRepository" />
+ <property name="keyring" ref="keyring" />
+ </bean>
+ <bean id="normalizeDistribution"
+ class="org.argeo.slc.client.ui.dist.commands.NormalizeDistribution">
+ <property name="repositoryFactory" ref="repositoryFactory" />
+ <property name="nodeRepository" ref="nodeRepository" />
+ <property name="keyring" ref="keyring" />
+ </bean>
+</beans>
\ No newline at end of file
<!-- Corresponding content provider -->
<bean id="distTreeContentProvider"
- class="org.argeo.slc.client.ui.dist.providers.DistTreeContentProvider"
+ class="org.argeo.slc.client.ui.dist.controllers.DistTreeContentProvider"
scope="prototype">
<property name="repositoryFactory" ref="repositoryFactory" />
<property name="keyring" ref="keyring" />
</bean>
+ <!-- ANONYMOUS DISTRIBUTION VIEW -->
+ <bean id="anonymousDistributionsView"
+ class="org.argeo.slc.client.ui.dist.views.AnonymousDistributionsView"
+ scope="prototype">
+ <property name="treeContentProvider" ref="anonymousDistTreeContentProvider" />
+ </bean>
+
+ <!-- Corresponding content provider -->
+ <bean id="anonymousDistTreeContentProvider"
+ class="org.argeo.slc.client.ui.dist.controllers.AnonymousDistTreeContentProvider"
+ scope="prototype">
+ <property name="repositoryFactory" ref="repositoryFactory" />
+ </bean>
+
<!-- <bean id="distributionPerspective" class="org.argeo.slc.client.ui.dist.DistributionPerspective"
scope="prototype"> <property name="repositoryFactory" ref="repositoryFactory"
/> <property name="nodeRepository" ref="nodeRepository" /> </bean> -->
<!-- Views -->
<extension
point="org.eclipse.ui.views">
+ <view
+ class="org.argeo.eclipse.spring.SpringExtensionFactory"
+ id="org.argeo.slc.client.ui.dist.distributionsView"
+ icon="icons/search.gif"
+ name="Distributions">
+ </view>
+ <view
+ class="org.argeo.eclipse.spring.SpringExtensionFactory"
+ id="org.argeo.slc.client.ui.dist.anonymousDistributionsView"
+ icon="icons/search.gif"
+ name="Public Repository">
+ </view>
+ <view
+ class="org.argeo.slc.client.ui.dist.views.HelpView"
+ id="org.argeo.slc.client.ui.dist.helpView"
+ icon="icons/help.gif"
+ name="Infos">
+ </view>
<view
class="org.argeo.eclipse.spring.SpringExtensionFactory"
id="org.argeo.slc.client.ui.dist.artifactsBrowser"
icon="icons/search.gif"
name="Query builder">
</view>
- <view
- class="org.argeo.eclipse.spring.SpringExtensionFactory"
- id="org.argeo.slc.client.ui.dist.distributionsView"
- icon="icons/search.gif"
- name="Distributions">
- </view>
- <view
+ <view
name="Progress View"
icon="icons/pview.gif"
category="org.eclipse.ui"
defaultHandler="org.argeo.slc.client.ui.dist.commands.DisplayRepoInformation"
id="org.argeo.slc.client.ui.dist.displayRepoInformation"
name="Display repo info">
- </command>
- <!-- Workspaces CRUD -->
- <command
- defaultHandler="org.argeo.slc.client.ui.dist.commands.PublishWorkspace"
- id="org.argeo.slc.client.ui.dist.publishWorkspace"
- name="Publish selected workspace">
</command>
<command
- id="org.argeo.slc.client.ui.dist.createWorkspace"
- defaultHandler="org.argeo.slc.client.ui.dist.commands.CreateWorkspace"
- name="Create Workspace">
- </command>
- <command
- id="org.argeo.slc.client.ui.dist.deleteWorkspace"
- defaultHandler="org.argeo.slc.client.ui.dist.commands.DeleteWorkspace"
- name="Delete chosen Workspace">
- </command>
- <command
- id="org.argeo.slc.client.ui.dist.normalizeDistribution"
- defaultHandler="org.argeo.slc.client.ui.dist.commands.NormalizeDistribution"
- name="Normalize Distribution">
- </command>
- <command
- id="org.argeo.slc.client.ui.dist.copyWorkspace"
- defaultHandler="org.argeo.slc.client.ui.dist.commands.CopyWorkspace"
- name="Copy chosen Workspace">
- </command>
-
- <command
defaultHandler="org.argeo.slc.client.ui.dist.commands.ShowSizeColumn"
id="org.argeo.slc.client.ui.dist.showSizeColumn"
name="Show size column">
</state>
</command>
-
-
<!-- Command with Spring dependency injection -->
<command
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
name="Fetch repository">
<commandParameter
id="targetRepoPath"
- name="Target repo path">
+ name="Target repo uri">
</commandParameter>
</command>
<!-- TO MANIPULATE WORKSPACES -->
+ <!-- Workspaces CRUD -->
+ <command
+ id="org.argeo.slc.client.ui.dist.createWorkspace"
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ name="Create Workspace">
+ <commandParameter
+ id="workspacePrefix"
+ name="Workspace prefix">
+ </commandParameter>
+ <commandParameter
+ id="targetRepoPath"
+ name="Target repo node path">
+ </commandParameter>
+ </command>
+ <command
+ id="org.argeo.slc.client.ui.dist.deleteWorkspace"
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ name="Delete chosen Workspace">
+ <commandParameter
+ id="workspaceName"
+ name="Workspace name">
+ </commandParameter>
+ <commandParameter
+ id="targetRepoPath"
+ name="Target repo node path">
+ </commandParameter>
+ </command>
+ <command
+ id="org.argeo.slc.client.ui.dist.publishWorkspace"
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ name="Publish selected workspace">
+ <commandParameter
+ id="workspaceName"
+ name="Workspace name">
+ </commandParameter>
+ <commandParameter
+ id="targetRepoPath"
+ name="Target repo node path">
+ </commandParameter>
+ </command>
+ <command
+ id="org.argeo.slc.client.ui.dist.normalizeDistribution"
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ name="Normalize Distribution">
+ <commandParameter
+ id="workspaceName"
+ name="Workspace name">
+ </commandParameter>
+ <commandParameter
+ id="targetRepoPath"
+ name="Target repo node path">
+ </commandParameter>
+ </command>
+ <command
+ id="org.argeo.slc.client.ui.dist.copyWorkspace"
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ name="Copy chosen Workspace">
+ <commandParameter
+ id="srcWkspName"
+ name="Source Workspace Name">
+ </commandParameter>
+ <commandParameter
+ id="targetRepoPath"
+ name="Target repo node path">
+ </commandParameter>
+ </command>
+ <command
+ id="org.argeo.slc.client.ui.dist.mergeWorkspaces"
+ defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
+ name="Copy chosen Workspace">
+ <commandParameter
+ id="srcWkspName"
+ name="Source Workspace Name">
+ </commandParameter>
+ <commandParameter
+ id="srcRepoPath"
+ name="Source Repo Node path ">
+ </commandParameter>
+ <commandParameter
+ id="targetWkspName"
+ name="Target Workspace Name">
+ </commandParameter>
+ <commandParameter
+ id="targetRepoPath"
+ name="Target repo node path">
+ </commandParameter>
+ </command>
<command
id="org.argeo.slc.client.ui.dist.manageWorkspaceAuth"
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
*/
package org.argeo.slc.client.ui.dist;
-import org.argeo.slc.client.ui.dist.views.DistributionsView;
+import org.argeo.slc.client.ui.dist.views.AnonymousDistributionsView;
+import org.argeo.slc.client.ui.dist.views.HelpView;
import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
public class AnonymousDistributionPerspective implements IPerspectiveFactory {
- public final static String ID = DistPlugin.ID + ".distributionPerspective";
+ public final static String ID = DistPlugin.ID
+ + ".anonymousDistributionPerspective";
public void createInitialLayout(IPageLayout layout) {
String editorArea = layout.getEditorArea();
layout.setFixed(false);
IFolderLayout main = layout.createFolder("main", IPageLayout.LEFT,
- 0.5f, editorArea);
- main.addView(DistributionsView.ID);
+ 0.3f, editorArea);
+ main.addView(AnonymousDistributionsView.ID);
+ main.addView(HelpView.ID);
}
}
+ "Bundle-License";
public final static String SLC_BUNDLE_VENDOR = SlcNames.SLC_
+ Constants.BUNDLE_VENDOR;
+
+ public final String DEFAULT_PUBLIC_REPOSITORY_URI = "vm:///java";
}
layout.setFixed(false);
IFolderLayout main = layout.createFolder("main", IPageLayout.LEFT,
- 0.5f, editorArea);
+ 0.3f, editorArea);
main.addView(DistributionsView.ID);
main.addView("org.eclipse.ui.views.ProgressView");
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
import javax.jcr.Session;
import javax.jcr.security.Privilege;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.client.ui.dist.DistPlugin;
import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
-import org.argeo.slc.client.ui.dist.views.DistributionsView;
-import org.argeo.slc.client.ui.dist.views.DistributionsView.DistributionViewSelectedElement;
import org.argeo.slc.repo.RepoUtils;
+import org.argeo.util.security.Keyring;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
/**
* Create a copy of the chosen workspace in the current repository.
// private static final Log log = LogFactory.getLog(CopyWorkspace.class);
public final static String ID = DistPlugin.ID + ".copyWorkspace";
public final static String DEFAULT_LABEL = "Duplicate";
+ public final static String PARAM_SOURCE_WORKSPACE_NAME = "srcWkspName";
+ public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
public final static String DEFAULT_ICON_PATH = "icons/addItem.gif";
- private Repository repository;
- private Credentials credentials;
- private String wkspName;
+ // DEPENDENCY INJECTION
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+ private Repository nodeRepository;
+
private String slcRole = "ROLE_SLC";
public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow();
- IWorkbenchPart view = iww.getActivePage().getActivePart();
- if (view instanceof DistributionsView) {
- DistributionViewSelectedElement dvse = ((DistributionsView) view)
- .getSelectedElement();
- if (dvse != null && (dvse.isWorkspace)) {
- repository = dvse.repository;
- credentials = dvse.credentials;
- wkspName = dvse.wkspName;
- }
- }
- if (repository == null || wkspName == null)
- return null;
- InputDialog inputDialog = new InputDialog(iww.getShell(),
- "New copy of workspace " + wkspName,
- "Choose a name for the workspace to create", "", null);
- inputDialog.open();
- String newWorkspaceName = inputDialog.getValue();
+ String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
+ String wkspName = event.getParameter(PARAM_SOURCE_WORKSPACE_NAME);
+
+ Session nodeSession = null;
Session srcSession = null;
Session newSession = null;
try {
+ nodeSession = nodeRepository.login();
+ Node repoNode = nodeSession.getNode(targetRepoPath);
+ Repository repository = RepoUtils.getRepository(repositoryFactory,
+ keyring, repoNode);
+ Credentials credentials = RepoUtils.getRepositoryCredentials(
+ keyring, repoNode);
+
+ InputDialog inputDialog = new InputDialog(HandlerUtil
+ .getActiveWorkbenchWindow(event).getShell(),
+ "New copy of workspace " + wkspName,
+ "Choose a name for the workspace to create", "", null);
+ inputDialog.open();
+ String newWorkspaceName = inputDialog.getValue();
srcSession = repository.login(credentials, wkspName);
// Create the workspace
throw new ArgeoException(
"Unexpected error while creating the new workspace.", re);
} finally {
- if (srcSession != null)
- srcSession.logout();
- if (newSession != null)
- newSession.logout();
+ JcrUtils.logoutQuietly(newSession);
+ JcrUtils.logoutQuietly(srcSession);
+ JcrUtils.logoutQuietly(nodeSession);
}
return null;
}
/* DEPENDENCY INJECTION */
- public void setRepository(Repository repository) {
- this.repository = repository;
+ public void setNodeRepository(Repository nodeRepository) {
+ this.nodeRepository = nodeRepository;
+ }
+
+ public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+ this.repositoryFactory = repositoryFactory;
+ }
+
+ public void setKeyring(Keyring keyring) {
+ this.keyring = keyring;
}
-}
+}
\ No newline at end of file
package org.argeo.slc.client.ui.dist.commands;
import javax.jcr.Credentials;
+import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
import javax.jcr.Session;
import javax.jcr.security.Privilege;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.client.ui.dist.DistPlugin;
import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
-import org.argeo.slc.client.ui.dist.views.DistributionsView;
-import org.argeo.slc.client.ui.dist.views.DistributionsView.DistributionViewSelectedElement;
+import org.argeo.slc.repo.RepoUtils;
+import org.argeo.util.security.Keyring;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
/**
* Create a new empty workspace in the current repository.
public class CreateWorkspace extends AbstractHandler {
private static final Log log = LogFactory.getLog(CreateWorkspace.class);
public final static String ID = DistPlugin.ID + ".createWorkspace";
- public final static String DEFAULT_LABEL = "Create new workspace...";
+ public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
+ public final static String PARAM_WORKSPACE_PREFIX = "workspacePrefix";
+ public final static String DEFAULT_LABEL = "Create workspace...";
public final static String DEFAULT_ICON_PATH = "icons/addItem.gif";
private String slcRole = "ROLE_SLC";
- private Repository repository;
- private Credentials credentials;
+ // DEPENDENCY INJECTION
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+ private Repository nodeRepository;
public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow();
- String prefix = "";
-
- IWorkbenchPart view = iww.getActivePage().getActivePart();
- if (view instanceof DistributionsView) {
- DistributionViewSelectedElement dvse = ((DistributionsView) view)
- .getSelectedElement();
- if (dvse != null && (dvse.isRepository || dvse.isWorkspaceGroup)) {
- repository = dvse.repository;
- credentials = dvse.credentials;
- prefix = dvse.wkspPrefix;
- }
- }
- if (repository != null) {
+ String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
+ String prefix = event.getParameter(PARAM_WORKSPACE_PREFIX);
+
+ Session nodeSession = null;
+ Session session = null;
+ try {
+ nodeSession = nodeRepository.login();
+ Node repoNode = nodeSession.getNode(targetRepoPath);
+ Repository repository = RepoUtils.getRepository(repositoryFactory,
+ keyring, repoNode);
+ Credentials credentials = RepoUtils.getRepositoryCredentials(
+ keyring, repoNode);
+
// TODO : add an input validator
- InputDialog inputDialog = new InputDialog(iww.getShell(),
+ InputDialog inputDialog = new InputDialog(HandlerUtil
+ .getActiveWorkbenchWindow(event).getShell(),
"Workspace name?",
- "Choose a name for the workspace to create", prefix + "-",
- null);
+ "Choose a name for the workspace to create",
+ prefix == null ? "" : prefix + "-", null);
int result = inputDialog.open();
String workspaceName = inputDialog.getValue();
|| "".equals(workspaceName.trim()))
return null;
- Session session = null;
- try {
- session = repository.login(credentials);
- session.getWorkspace().createWorkspace(workspaceName);
- JcrUtils.logoutQuietly(session);
- // init new workspace
- session = repository.login(workspaceName);
- JcrUtils.addPrivilege(session, "/", slcRole, Privilege.JCR_ALL);
- CommandHelpers.callCommand(RefreshDistributionsView.ID);
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while creating the new workspace.",
- re);
- } finally {
- JcrUtils.logoutQuietly(session);
- }
+ session = repository.login(credentials);
+ session.getWorkspace().createWorkspace(workspaceName);
+ JcrUtils.logoutQuietly(session);
+ // init new workspace
+ session = repository.login(credentials, workspaceName);
+ JcrUtils.addPrivilege(session, "/", slcRole, Privilege.JCR_ALL);
+ CommandHelpers.callCommand(RefreshDistributionsView.ID);
if (log.isTraceEnabled())
log.trace("WORKSPACE " + workspaceName + " CREATED");
+
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while creating the new workspace.", re);
+ } finally {
+ JcrUtils.logoutQuietly(session);
+ JcrUtils.logoutQuietly(nodeSession);
}
return null;
}
- public void setRepository(Repository repository) {
- this.repository = repository;
+ /* DEPENDENCY INJECTION */
+ public void setNodeRepository(Repository nodeRepository) {
+ this.nodeRepository = nodeRepository;
}
- public void setCredentials(Credentials credentials) {
- this.credentials = credentials;
+ public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+ this.repositoryFactory = repositoryFactory;
}
- public void setSlcRole(String slcRole) {
- this.slcRole = slcRole;
+ public void setKeyring(Keyring keyring) {
+ this.keyring = keyring;
}
}
\ No newline at end of file
import javax.jcr.NodeIterator;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
import org.argeo.slc.SlcException;
import org.argeo.slc.client.ui.dist.DistPlugin;
import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
-import org.argeo.slc.client.ui.dist.views.DistributionsView;
-import org.argeo.slc.client.ui.dist.views.DistributionsView.DistributionViewSelectedElement;
+import org.argeo.slc.repo.RepoUtils;
+import org.argeo.util.security.Keyring;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
/**
* Delete chosen workspace in the current repository.
+ *
+ * Due to current version of JackRabbit, it only cleans it for the time being,
+ * removing all nodes of type {@code NodeType.NT_FOLDER} and
+ * {@code NodeType.NT_UNSTRUCTURED}
*/
public class DeleteWorkspace extends AbstractHandler {
public final static String ID = DistPlugin.ID + ".deleteWorkspace";
public final static String DEFAULT_LABEL = "Clear";
public final static String DEFAULT_ICON_PATH = "icons/removeItem.gif";
+ public final static String PARAM_WORKSPACE_NAME = "workspaceName";
+ public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
- private Repository repository;
- private Credentials credentials;
+ // DEPENDENCY INJECTION
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+ private Repository nodeRepository;
public Object execute(ExecutionEvent event) throws ExecutionException {
- String workspaceName = "";
-
- IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow();
- IWorkbenchPart view = iww.getActivePage().getActivePart();
- if (view instanceof DistributionsView) {
- DistributionViewSelectedElement dvse = ((DistributionsView) view)
- .getSelectedElement();
- if (dvse != null && (dvse.isWorkspace)) {
- repository = dvse.repository;
- credentials = dvse.credentials;
- workspaceName = dvse.wkspName;
- }
- }
+ String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
+ String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
+
+ Session nodeSession = null;
+ Session session = null;
+
+ try {
+ nodeSession = nodeRepository.login();
+ Node repoNode = nodeSession.getNode(targetRepoPath);
+ Repository repository = RepoUtils.getRepository(repositoryFactory,
+ keyring, repoNode);
+ Credentials credentials = RepoUtils.getRepositoryCredentials(
+ keyring, repoNode);
- if (repository == null)
- return null;
-
- String msg = "Your are about to completely delete workspace ["
- + workspaceName + "].\n Do you really want to proceed ?";
- boolean result = MessageDialog.openConfirm(DistPlugin.getDefault()
- .getWorkbench().getDisplay().getActiveShell(),
- "Confirm workspace deletion", msg);
-
- if (result) {
- // msg =
- // "There is no possible turning back, are your REALLY sure you want to proceed ?";
- msg = "WARNING: \nCurrent Jackrabbit version used does "
- + "not support workspace management.\n"
- + "Thus, the workspace will only be cleaned so "
- + "that you can launch fetch process again.\n\n"
- + "Do you still want to proceed ?";
- result = MessageDialog.openConfirm(DistPlugin.getDefault()
+ String msg = "Your are about to completely delete workspace ["
+ + workspaceName + "].\n Do you really want to proceed ?";
+ boolean result = MessageDialog.openConfirm(DistPlugin.getDefault()
.getWorkbench().getDisplay().getActiveShell(),
"Confirm workspace deletion", msg);
- }
- if (result) {
- Session session = null;
- try {
+ if (result) {
+ // msg =
+ // "There is no possible turning back, are your REALLY sure you want to proceed ?";
+ msg = "WARNING: \nCurrent Jackrabbit version used does "
+ + "not support workspace management.\n"
+ + "Thus, the workspace will only be cleaned so "
+ + "that you can launch fetch process again.\n\n"
+ + "Do you still want to proceed ?";
+ result = MessageDialog.openConfirm(DistPlugin.getDefault()
+ .getWorkbench().getDisplay().getActiveShell(),
+ "Confirm workspace deletion", msg);
+ }
+
+ if (result) {
session = repository.login(credentials, workspaceName);
+
// TODO use this with a newer version of Jackrabbit
// Workspace wsp = session.getWorkspace();
// wsp.deleteWorkspace(workspaceName);
}
}
CommandHelpers.callCommand(RefreshDistributionsView.ID);
- } catch (RepositoryException re) {
- throw new SlcException(
- "Unexpected error while deleting workspace ["
- + workspaceName + "].", re);
- } finally {
- JcrUtils.logoutQuietly(session);
}
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while deleting workspace ["
+ + workspaceName + "].", re);
+ } finally {
+ JcrUtils.logoutQuietly(session);
+ JcrUtils.logoutQuietly(nodeSession);
}
return null;
}
+
+ /* DEPENDENCY INJECTION */
+ public void setNodeRepository(Repository nodeRepository) {
+ this.nodeRepository = nodeRepository;
+ }
+
+ public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+ this.repositoryFactory = repositoryFactory;
+ }
+
+ public void setKeyring(Keyring keyring) {
+ this.keyring = keyring;
+ }
}
\ No newline at end of file
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import org.argeo.jcr.ArgeoNames;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.SlcException;
import org.argeo.slc.client.ui.dist.DistPlugin;
-import org.argeo.slc.client.ui.dist.views.DistributionsView;
-import org.argeo.slc.client.ui.dist.views.DistributionsView.DistributionViewSelectedElement;
+import org.argeo.slc.client.ui.dist.model.RepoElem;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
/**
* Create a new empty workspace in the current repository.
public final static String DEFAULT_ICON_PATH = "icons/help.gif";
public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow();
- IWorkbenchPart view = iww.getActivePage().getActivePart();
- if (view instanceof DistributionsView) {
- DistributionViewSelectedElement dvse = ((DistributionsView) view)
- .getSelectedElement();
- if (dvse != null && (dvse.isRepository)) {
- InformationDialog inputDialog = new InformationDialog(
- iww.getShell());
- inputDialog.create();
- Session session = null;
- try {
- session = dvse.repository.login(dvse.credentials);
- inputDialog.loginTxt.setText(session.getUserID());
-
- inputDialog.nameTxt.setText(dvse.repoNode.getName());
- inputDialog.uriTxt.setText(JcrUtils.get(dvse.repoNode,
- ArgeoNames.ARGEO_URI));
- inputDialog.readOnlyBtn.setSelection(dvse.isReadOnly);
-
- } catch (RepositoryException e) {
- throw new SlcException("Unexpected error while "
- + "getting repository infos.", e);
- } finally {
- JcrUtils.logoutQuietly(session);
- }
- inputDialog.open();
+
+ IStructuredSelection iss = (IStructuredSelection) HandlerUtil
+ .getActiveSite(event).getSelectionProvider().getSelection();
+
+ if (iss.getFirstElement() instanceof RepoElem) {
+ RepoElem re = (RepoElem) iss.getFirstElement();
+ InformationDialog inputDialog = new InformationDialog(HandlerUtil
+ .getActiveSite(event).getShell());
+ inputDialog.create();
+ Session session = null;
+ try {
+ session = re.getRepository().login(re.getCredentials());
+ inputDialog.loginTxt.setText(session.getUserID());
+ inputDialog.nameTxt.setText(re.getLabel());
+ inputDialog.uriTxt.setText(re.getUri());
+ inputDialog.readOnlyBtn.setSelection(re.isReadOnly());
+ } catch (RepositoryException e) {
+ throw new SlcException("Unexpected error while "
+ + "getting repository infos.", e);
+ } finally {
+ JcrUtils.logoutQuietly(session);
}
+ inputDialog.open();
}
return null;
}
// private final static Log log = LogFactory.getLog(Fetch.class);
public final static String ID = DistPlugin.ID + ".fetch";
- public final static String PARAM_TARGET_REPO = "targetRepoPath";
+ public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
public final static String DEFAULT_LABEL = "Fetch...";
public final static String DEFAULT_ICON_PATH = "icons/fetchRepo.png";
Session currSession = null;
try {
// Target Repository
- String targetRepoPath = event.getParameter(PARAM_TARGET_REPO);
+ String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
currSession = nodeRepository.login();
Node targetRepoNode = currSession.getNode(targetRepoPath);
--- /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.slc.client.ui.dist.commands;
+
+import javax.jcr.Credentials;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoMonitor;
+import org.argeo.eclipse.ui.EclipseArgeoMonitor;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.repo.RepoUtils;
+import org.argeo.util.security.Keyring;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+
+/**
+ * Merge two workspaces
+ */
+
+public class MergeWorkspaces extends AbstractHandler {
+ private final static Log log = LogFactory.getLog(MergeWorkspaces.class);
+
+ public final static String ID = DistPlugin.ID + ".mergeWorkspaces";
+ public final static String DEFAULT_LABEL = "Merge";
+ public final static String PARAM_SOURCE_WORKSPACE_NAME = "srcWkspName";
+ public final static String PARAM_SOURCE_REPO_PATH = "srcRepoPath";
+ public final static String PARAM_TARGET_WORKSPACE_NAME = "targetWkspName";
+ public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
+
+ // DEPENDENCY INJECTION
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+ private Repository nodeRepository;
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
+ String targetWkspName = event.getParameter(PARAM_TARGET_WORKSPACE_NAME);
+ String sourceRepoPath = event.getParameter(PARAM_SOURCE_REPO_PATH);
+ String sourceWkspName = event.getParameter(PARAM_SOURCE_WORKSPACE_NAME);
+
+ Session nodeSession = null;
+ try {
+ nodeSession = nodeRepository.login();
+ Node srcRepoNode = nodeSession.getNode(sourceRepoPath);
+ Repository srcRepository = RepoUtils.getRepository(
+ repositoryFactory, keyring, srcRepoNode);
+ Credentials srcCredentials = RepoUtils.getRepositoryCredentials(
+ keyring, srcRepoNode);
+
+ Node targetRepoNode = nodeSession.getNode(targetRepoPath);
+ Repository targetRepository = RepoUtils.getRepository(
+ repositoryFactory, keyring, targetRepoNode);
+ Credentials targetCredentials = RepoUtils.getRepositoryCredentials(
+ keyring, targetRepoNode);
+
+ // String msg = "Are you sure you want to merge distribution ["
+ // + sourceWkspName + "] in distribution [" + targetWkspName
+ // + "] ?";
+ //
+ // boolean result = MessageDialog.openConfirm(
+ // HandlerUtil.getActiveShell(event), "Confirm Merge", msg);
+
+ // if (result) {
+ // Open sessions here since the background thread
+ // won't necessarily be authenticated.
+ // Job should close the sessions.
+ Session sourceSession = srcRepository.login(srcCredentials,
+ sourceWkspName);
+ Session targetSession;
+ try {
+ targetSession = targetRepository.login(targetCredentials,
+ targetWkspName);
+ } catch (NoSuchWorkspaceException e) {
+ Session defaultSession = targetRepository
+ .login(targetCredentials);
+ try {
+ defaultSession.getWorkspace().createWorkspace(
+ targetWkspName);
+ } catch (Exception e1) {
+ throw new SlcException("Cannot create new workspace "
+ + targetWkspName, e);
+ } finally {
+ JcrUtils.logoutQuietly(defaultSession);
+ }
+ targetSession = targetRepository.login(targetCredentials,
+ targetWkspName);
+ }
+
+ Job workspaceMergeJob = new WorkspaceMergeJob(sourceSession,
+ targetSession);
+ workspaceMergeJob.setUser(true);
+ workspaceMergeJob.schedule();
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while merging workspaces.", re);
+ } finally {
+ JcrUtils.logoutQuietly(nodeSession);
+ }
+ return null;
+ }
+
+ private static class WorkspaceMergeJob extends Job {
+ private Session sourceSession;
+ private Session targetSession;
+
+ public WorkspaceMergeJob(Session sourceSession, Session targetSession) {
+ super("Workspace merge");
+ this.sourceSession = sourceSession;
+ this.targetSession = targetSession;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor eclipseMonitor) {
+ long begin = System.currentTimeMillis();
+ try {
+ Query countQuery = sourceSession
+ .getWorkspace()
+ .getQueryManager()
+ .createQuery("select file from [nt:file] as file",
+ Query.JCR_SQL2);
+ QueryResult result = countQuery.execute();
+ Long expectedCount = result.getNodes().getSize();
+ if (log.isDebugEnabled())
+ log.debug("Will copy " + expectedCount + " files...");
+
+ ArgeoMonitor monitor = new EclipseArgeoMonitor(eclipseMonitor);
+ eclipseMonitor
+ .beginTask("Copy files", expectedCount.intValue());
+
+ Long count = JcrUtils.copyFiles(sourceSession.getRootNode(),
+ targetSession.getRootNode(), true, monitor);
+
+ monitor.done();
+ long duration = (System.currentTimeMillis() - begin) / 1000;// in
+ // s
+ if (log.isDebugEnabled())
+ log.debug("Copied " + count + " files in "
+ + (duration / 60) + "min " + (duration % 60) + "s");
+
+ return Status.OK_STATUS;
+ } catch (RepositoryException e) {
+ return new Status(IStatus.ERROR, DistPlugin.ID, "Cannot merge",
+ e);
+ } finally {
+ JcrUtils.logoutQuietly(sourceSession);
+ JcrUtils.logoutQuietly(targetSession);
+ }
+ }
+ }
+
+ /* DEPENDENCY INJECTION */
+ public void setNodeRepository(Repository nodeRepository) {
+ this.nodeRepository = nodeRepository;
+ }
+
+ public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+ this.repositoryFactory = repositoryFactory;
+ }
+
+ public void setKeyring(Keyring keyring) {
+ this.keyring = keyring;
+ }
+}
\ No newline at end of file
import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
import javax.jcr.query.Query;
import org.argeo.slc.SlcException;
import org.argeo.slc.aether.AetherUtils;
import org.argeo.slc.client.ui.dist.DistPlugin;
-import org.argeo.slc.client.ui.dist.views.DistributionsView;
-import org.argeo.slc.client.ui.dist.views.DistributionsView.DistributionViewSelectedElement;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
import org.argeo.slc.repo.ArtifactIndexer;
import org.argeo.slc.repo.RepoUtils;
import org.argeo.slc.repo.maven.MavenConventionsUtils;
import org.argeo.slc.repo.osgi.NormalizeGroup;
+import org.argeo.util.security.Keyring;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.util.artifact.DefaultArtifact;
public final static String ID = DistPlugin.ID + ".normalizeDistribution";
public final static String DEFAULT_LABEL = "Normalize...";
public final static String DEFAULT_ICON_PATH = "icons/normalize.gif";
+ public final static String PARAM_WORKSPACE_NAME = "workspaceName";
+ public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
private final static Log log = LogFactory
.getLog(NormalizeDistribution.class);
- private Repository repository;
- private Credentials credentials;
- private String wkspName;
private String artifactBasePath = "/";
private ArtifactIndexer artifactIndexer = new ArtifactIndexer();
private JarFileIndexer jarFileIndexer = new JarFileIndexer();
- public Object execute(ExecutionEvent event) throws ExecutionException {
+ // DEPENDENCY INJECTION
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+ private Repository nodeRepository;
- IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow();
- IWorkbenchPart view = iww.getActivePage().getActivePart();
- if (view instanceof DistributionsView) {
- DistributionViewSelectedElement dvse = ((DistributionsView) view)
- .getSelectedElement();
- if (dvse != null && (dvse.isWorkspace)) {
- repository = dvse.repository;
- credentials = dvse.credentials;
- wkspName = dvse.wkspName;
- }
- }
- if (repository == null || wkspName == null)
- return null;
-
- NormalizationDialog dialog = new NormalizationDialog(
- HandlerUtil.getActiveShell(event));
- if (dialog.open() != Dialog.OK)
- return null;
+ public Object execute(ExecutionEvent event) throws ExecutionException {
- String version = dialog.getVersion();
- Boolean overridePoms = dialog.getOverridePoms();
+ String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
+ String wkspName = event.getParameter(PARAM_WORKSPACE_NAME);
+ Session nodeSession = null;
NormalizeJob job;
try {
+
+ NormalizationDialog dialog = new NormalizationDialog(
+ HandlerUtil.getActiveShell(event));
+ if (dialog.open() != Dialog.OK)
+ return null;
+
+ nodeSession = nodeRepository.login();
+ Node repoNode = nodeSession.getNode(targetRepoPath);
+ Repository repository = RepoUtils.getRepository(repositoryFactory,
+ keyring, repoNode);
+ Credentials credentials = RepoUtils.getRepositoryCredentials(
+ keyring, repoNode);
+
+ String version = dialog.getVersion();
+ Boolean overridePoms = dialog.getOverridePoms();
+
job = new NormalizeJob(repository.login(credentials, wkspName),
version, overridePoms);
+ job.setUser(true);
+ job.schedule();
} catch (RepositoryException e) {
throw new SlcException("Cannot normalize " + wkspName, e);
+ } finally {
+ JcrUtils.logoutQuietly(nodeSession);
}
- job.setUser(true);
- job.schedule();
return null;
}
}
- public void setRepository(Repository repository) {
- this.repository = repository;
- }
-
private class NormalizeJob extends Job {
private Session session;
private String version;
}
}
+
+ /* DEPENDENCY INJECTION */
+ public void setNodeRepository(Repository nodeRepository) {
+ this.nodeRepository = nodeRepository;
+ }
+
+ public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+ this.repositoryFactory = repositoryFactory;
+ }
+
+ public void setKeyring(Keyring keyring) {
+ this.keyring = keyring;
+ }
}
\ No newline at end of file
package org.argeo.slc.client.ui.dist.commands;
import javax.jcr.Credentials;
+import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
import javax.jcr.Session;
import javax.jcr.security.Privilege;
import org.argeo.ArgeoException;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.client.ui.dist.DistPlugin;
-import org.argeo.slc.client.ui.dist.views.DistributionsView;
-import org.argeo.slc.client.ui.dist.views.DistributionsView.DistributionViewSelectedElement;
+import org.argeo.slc.repo.RepoUtils;
+import org.argeo.util.security.Keyring;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
/**
* Publish the current workspace by giving REOD_ONLY rights to anonymous.
public final static String ID = DistPlugin.ID + ".publishWorkspace";
public final static String DEFAULT_LABEL = "Publish workspace";
public final static String DEFAULT_ICON_PATH = "icons/publish.gif";
+ public final static String PARAM_WORKSPACE_NAME = "workspaceName";
+ public final static String PARAM_TARGET_REPO_PATH = "targetRepoPath";
- private String publicRole = "anonymous";
+ // DEPENDENCY INJECTION
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+ private Repository nodeRepository;
- private String workspaceName;
- private Repository repository;
- private Credentials credentials;
+ private String publicRole = "anonymous";
public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow();
- IWorkbenchPart view = iww.getActivePage().getActivePart();
- if (view instanceof DistributionsView) {
- DistributionViewSelectedElement dvse = ((DistributionsView) view)
- .getSelectedElement();
- if (dvse != null && dvse.isWorkspace) {
- repository = dvse.repository;
- credentials = dvse.credentials;
- workspaceName = dvse.wkspName;
- }
- }
+ String targetRepoPath = event.getParameter(PARAM_TARGET_REPO_PATH);
+ String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
+
+ Session nodeSession = null;
+ Session session = null;
+
+ try {
+ nodeSession = nodeRepository.login();
+ Node repoNode = nodeSession.getNode(targetRepoPath);
+ Repository repository = RepoUtils.getRepository(repositoryFactory,
+ keyring, repoNode);
+ Credentials credentials = RepoUtils.getRepositoryCredentials(
+ keyring, repoNode);
- if (repository != null && workspaceName != null) {
String msg = "Are you sure you want to publish this distribution: "
+ workspaceName + " ?";
boolean result = MessageDialog.openConfirm(DistPlugin.getDefault()
if (result) {
- Session session = null;
- try {
- session = repository.login(credentials, workspaceName);
- JcrUtils.addPrivilege(session, "/", publicRole,
- Privilege.JCR_READ);
- JcrUtils.logoutQuietly(session);
- // CommandHelpers.callCommand(RefreshDistributionsView.ID);
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while publishing workspace "
- + workspaceName, re);
- } finally {
- JcrUtils.logoutQuietly(session);
- }
+ session = repository.login(credentials, workspaceName);
+ JcrUtils.addPrivilege(session, "/", publicRole,
+ Privilege.JCR_READ);
+ session.save();
+ JcrUtils.logoutQuietly(session);
+ // CommandHelpers.callCommand(RefreshDistributionsView.ID);
}
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while publishing workspace "
+ + workspaceName, re);
+ } finally {
+ JcrUtils.logoutQuietly(session);
+ JcrUtils.logoutQuietly(nodeSession);
}
return null;
}
- public void setRepository(Repository repository) {
- this.repository = repository;
+ /* DEPENDENCY INJECTION */
+ public void setNodeRepository(Repository nodeRepository) {
+ this.nodeRepository = nodeRepository;
+ }
+
+ public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+ this.repositoryFactory = repositoryFactory;
}
- public void setWorkspaceName(String workspaceName) {
- this.workspaceName = workspaceName;
+ public void setKeyring(Keyring keyring) {
+ this.keyring = keyring;
}
}
\ No newline at end of file
*/
public class RefreshDistributionsView extends AbstractHandler {
- // private static final Log log = LogFactory
- // .getLog(RefreshDistributionsView.class);
public final static String ID = DistPlugin.ID + ".refreshDistributionsView";
public final static String DEFAULT_LABEL = "Refresh the distribution view";
public final static String DEFAULT_ICON_PATH = "icons/refresh.png";
--- /dev/null
+package org.argeo.slc.client.ui.dist.controllers;
+
+import javax.jcr.RepositoryFactory;
+
+import org.argeo.slc.client.ui.dist.model.DistParentElem;
+import org.argeo.slc.client.ui.dist.model.RepoElem;
+import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Enables browsing in local public slc distribution repositories. For the time
+ * being, it supports only one repository at a time. Repository factory must be
+ * injected
+ */
+
+public class AnonymousDistTreeContentProvider implements ITreeContentProvider {
+
+ // List<RepoElem> repositories = new ArrayList<RepoElem>();
+ private RepoElem publicRepo;
+
+ private RepositoryFactory repositoryFactory;
+
+ /**
+ * @param input
+ * the URI to the public repository to browse
+ */
+ public Object[] getElements(Object input) {
+ String uri = (String) input;
+ publicRepo = new RepoElem(repositoryFactory, uri,
+ "Argeo Public Repository");
+ return publicRepo.getChildren();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof DistParentElem) {
+ return ((DistParentElem) parentElement).getChildren();
+ } else
+ return null;
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element instanceof WorkspaceElem)
+ return false;
+ else if (element instanceof DistParentElem)
+ return true;
+ else
+ return false;
+ }
+
+ public void dispose() {
+ publicRepo.dispose();
+ }
+
+ /*
+ * DEPENDENCY INJECTION
+ */
+ public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+ this.repositoryFactory = repositoryFactory;
+ }
+}
\ 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.slc.client.ui.dist.controllers;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.client.ui.dist.DistConstants;
+import org.argeo.slc.client.ui.dist.DistImages;
+import org.argeo.slc.jcr.SlcTypes;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.swt.graphics.Image;
+
+public class ArtifactLabelProvider extends ColumnLabelProvider implements
+ DistConstants, SlcTypes {
+
+ // To be able to change column order easily
+ public static final int COLUMN_TREE = 0;
+ public static final int COLUMN_DATE = 1;
+ public static final int COLUMN_SIZE = 2;
+
+ // Utils
+ protected static DateFormat timeFormatter = new SimpleDateFormat(
+ DATE_TIME_FORMAT);
+
+ public void update(ViewerCell cell) {
+ int colIndex = cell.getColumnIndex();
+ Object element = cell.getElement();
+ cell.setText(getColumnText(element, colIndex));
+ if (element instanceof Node && colIndex == 0) {
+ Node node = (Node) element;
+ try {
+ if (node.isNodeType(SLC_ARTIFACT_BASE))
+ cell.setImage(DistImages.IMG_ARTIFACT_BASE);
+ else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE))
+ cell.setImage(DistImages.IMG_ARTIFACT_VERSION_BASE);
+ } catch (RepositoryException e) {
+ // Silent
+ }
+ }
+ }
+
+ @Override
+ public Image getImage(Object element) {
+
+ if (element instanceof Node) {
+ Node node = (Node) element;
+ try {
+ if (node.isNodeType(SLC_ARTIFACT_BASE)) {
+ return DistImages.IMG_ARTIFACT_BASE;
+ } else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE)) {
+ return DistImages.IMG_ARTIFACT_VERSION_BASE;
+ }
+ } catch (RepositoryException e) {
+ // Silent
+ }
+ }
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ try {
+ if (element instanceof Node) {
+ Node node = (Node) element;
+ switch (columnIndex) {
+ case COLUMN_TREE:
+ return node.getName();
+ case COLUMN_SIZE:
+ long size = JcrUtils.getNodeApproxSize(node) / 1024;
+ if (size > 1024)
+ return size / 1024 + " MB";
+ else
+ return size + " KB";
+ case COLUMN_DATE:
+ if (node.hasProperty(Property.JCR_LAST_MODIFIED))
+ return timeFormatter.format(node
+ .getProperty(Property.JCR_LAST_MODIFIED)
+ .getDate().getTime());
+ else
+ return null;
+ }
+ }
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexepected error while getting property values", re);
+ }
+ 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.slc.client.ui.dist.controllers;
+
+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.argeo.slc.jcr.SlcTypes;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+public class ArtifactsTreeContentProvider implements ITreeContentProvider,
+ SlcTypes {
+
+ // Utils
+ private boolean sortChildren = true;
+ private JcrItemsComparator itemComparator = new JcrItemsComparator();
+
+ public Object[] getElements(Object parent) {
+ return getChildren(parent);
+ }
+
+ public Object getParent(Object child) {
+ return null;
+ }
+
+ public Object[] getChildren(Object parent) {
+ Object[] elements = null;
+ try {
+ if (parent instanceof Node) {
+ Node node = (Node) parent;
+ NodeIterator ni = node.getNodes();
+ List<Node> nodesList = new ArrayList<Node>();
+ while (ni.hasNext()) {
+ nodesList.add(ni.nextNode());
+ }
+ if (sortChildren) {
+ Node[] arr = (Node[]) nodesList.toArray(new Node[nodesList
+ .size()]);
+ Arrays.sort(arr, itemComparator);
+ return arr;
+ } else
+ return nodesList.toArray();
+
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception while listing node properties", e);
+ }
+ return elements;
+ }
+
+ public boolean hasChildren(Object parent) {
+ try {
+ if (parent instanceof Node) {
+ Node curNode = (Node) parent;
+ // We manually stop digging at this level
+ if (curNode.isNodeType(SLC_ARTIFACT_VERSION_BASE))
+ return false;
+ else if (curNode.hasNodes())
+ return true;
+ }
+ } catch (RepositoryException e) {
+ throw new ArgeoException(
+ "Unexpected exception while checking if property is multiple",
+ e);
+ }
+ return false;
+ }
+
+ public void setSortChildren(boolean sortChildren) {
+ this.sortChildren = sortChildren;
+ }
+
+ public boolean getSortChildren() {
+ return sortChildren;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.client.ui.dist.controllers;
+
+import javax.jcr.Credentials;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
+
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.repo.RepoUtils;
+import org.argeo.util.security.Keyring;
+
+/**
+ * Provides shortcut to retrieve sessions, repositories and workspaces that are
+ * persisted in the current user node using path only.
+ */
+public class DistSessionFactory {
+
+ /* DEPENDENCY INJECTION */
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+ private Repository nodeRepository;
+
+ /**
+ * Returns a new session on the given workspace. This session *must* be
+ * disposed by the caller. If the workspace does not exist and
+ * createIfNeeded==true, tries to create it
+ *
+ * */
+ public Session getSessionFromWorkspacePath(String path,
+ boolean createIfNeeded) {
+ Session nodeSession = null;
+ try {
+ nodeSession = nodeRepository.login();
+ Node localWksp = nodeSession.getNode(path);
+ Repository repository = RepoUtils.getRepository(repositoryFactory,
+ keyring, localWksp.getParent());
+ Credentials credentials = RepoUtils.getRepositoryCredentials(
+ keyring, localWksp.getParent());
+
+ String wkspName = JcrUtils.lastPathElement(path);
+ Session session = null;
+ try {
+ session = repository.login(credentials, wkspName);
+ } catch (NoSuchWorkspaceException e) {
+ if (createIfNeeded) {
+ Session defaultSession = repository.login(credentials);
+ try {
+ defaultSession.getWorkspace().createWorkspace(wkspName);
+ } catch (Exception e1) {
+ throw new SlcException("Cannot create new workspace "
+ + wkspName, e);
+ } finally {
+ JcrUtils.logoutQuietly(defaultSession);
+ }
+ session = repository.login(credentials, wkspName);
+ } else
+ throw new SlcException("Workspace" + wkspName
+ + "does not exists and should not be created", e);
+ }
+ return session;
+ } catch (RepositoryException e) {
+ throw new SlcException("cannot create session" + " for workspace "
+ + path, e);
+ } finally {
+ JcrUtils.logoutQuietly(nodeSession);
+ }
+ }
+
+ /*
+ * DEPENDENCY INJECTION
+ */
+ public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+ this.repositoryFactory = repositoryFactory;
+ }
+
+ public void setKeyring(Keyring keyring) {
+ this.keyring = keyring;
+ }
+
+ public void setRepository(Repository nodeRepository) {
+ this.nodeRepository = nodeRepository;
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.client.ui.dist.controllers;
+
+import org.argeo.slc.client.ui.dist.model.DistParentElem;
+import org.argeo.slc.client.ui.dist.model.GroupElem;
+import org.argeo.slc.client.ui.dist.model.RepoElem;
+import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+
+/** Specific behaviour to enhence Distribution tree browsers */
+public class DistTreeComparator extends ViewerComparator {
+
+ public int category(Object element) {
+ if (element instanceof RepoElem)
+ if (((RepoElem) element).inHome())
+ // Home repository always first
+ return 2;
+ else
+ return 5;
+ else if (element instanceof GroupElem)
+ return 10;
+ else if (element instanceof WorkspaceElem)
+ return 15;
+ else
+ return 20;
+ }
+
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ int cat1 = category(e1);
+ int cat2 = category(e2);
+
+ if (cat1 != cat2) {
+ return cat1 - cat2;
+ }
+
+ String s1, s2;
+
+ if (e1 instanceof DistParentElem) {
+ s1 = ((DistParentElem) e1).getLabel();
+ s2 = ((DistParentElem) e2).getLabel();
+ } else {
+ s1 = e1.toString();
+ s2 = e2.toString();
+ }
+
+ if (e1 instanceof WorkspaceElem)
+ // Reverse order for versions
+ return s2.compareTo(s1);
+ else
+ return s1.compareTo(s2);
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.client.ui.dist.controllers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+
+import org.argeo.jcr.ArgeoJcrUtils;
+import org.argeo.jcr.ArgeoNames;
+import org.argeo.jcr.ArgeoTypes;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.jcr.UserJcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.client.ui.dist.model.DistParentElem;
+import org.argeo.slc.client.ui.dist.model.RepoElem;
+import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
+import org.argeo.slc.repo.RepoConstants;
+import org.argeo.util.security.Keyring;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Enables browsing in local and remote slc distribution repositories. Keyring
+ * and repository factory must be injected
+ */
+public class DistTreeContentProvider implements ITreeContentProvider {
+ private Session nodeSession;
+ List<RepoElem> repositories = new ArrayList<RepoElem>();
+
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+
+ public Object[] getElements(Object input) {
+ Repository nodeRepository = (Repository) input;
+ try {
+ if (nodeSession != null)
+ dispose();
+ nodeSession = nodeRepository.login();
+
+ String reposPath = UserJcrUtils.getUserHome(nodeSession).getPath()
+ + RepoConstants.REPOSITORIES_BASE_PATH;
+
+ if (!nodeSession.itemExists(reposPath))
+ initializeModel(nodeSession);
+
+ NodeIterator repos = nodeSession.getNode(reposPath).getNodes();
+ while (repos.hasNext()) {
+ Node repoNode = repos.nextNode();
+ if (repoNode.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY))
+ repositories.add(new RepoElem(repoNode, repositoryFactory,
+ keyring));
+ }
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot get base elements", e);
+ }
+ return repositories.toArray();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof DistParentElem) {
+ return ((DistParentElem) parentElement).getChildren();
+ } else if (parentElement instanceof WorkspaceElem) {
+ return ((WorkspaceElem) parentElement).getChildren();
+ }
+ return null;
+ }
+
+ public Object getParent(Object element) {
+ // TODO register repo elem in distribution elem?
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element instanceof WorkspaceElem)
+ return false;
+ else if (element instanceof DistParentElem)
+ return true;
+ else
+ return false;
+ }
+
+ public void dispose() {
+ for (RepoElem repoElem : repositories)
+ repoElem.dispose();
+ repositories = new ArrayList<RepoElem>();
+ JcrUtils.logoutQuietly(nodeSession);
+ }
+
+ private void initializeModel(Session nodeSession) {
+ try {
+
+ Node homeNode = UserJcrUtils.getUserHome(nodeSession);
+ if (homeNode == null) // anonymous
+ throw new SlcException("User must be authenticated.");
+
+ // make sure base directory is available
+ Node repos = JcrUtils.mkdirs(nodeSession, homeNode.getPath()
+ + RepoConstants.REPOSITORIES_BASE_PATH);
+ nodeSession.save();
+
+ // register default local java repository
+ String alias = RepoConstants.DEFAULT_JAVA_REPOSITORY_ALIAS;
+ Repository javaRepository = ArgeoJcrUtils.getRepositoryByAlias(
+ repositoryFactory, alias);
+ if (javaRepository != null) {
+ if (!repos.hasNode(alias)) {
+ Node repoNode = repos.addNode(alias,
+ ArgeoTypes.ARGEO_REMOTE_REPOSITORY);
+ repoNode.setProperty(ArgeoNames.ARGEO_URI, "vm:///" + alias);
+ repoNode.addMixin(NodeType.MIX_TITLE);
+ repoNode.setProperty(Property.JCR_TITLE,
+ RepoConstants.DEFAULT_JAVA_REPOSITORY_LABEL);
+ nodeSession.save();
+ }
+ }
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot initialize model", e);
+ }
+ }
+
+ /*
+ * DEPENDENCY INJECTION
+ */
+ public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
+ this.repositoryFactory = repositoryFactory;
+ }
+
+ public void setKeyring(Keyring keyring) {
+ this.keyring = keyring;
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.client.ui.dist.controllers;
+
+import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.editors.DistributionEditor;
+import org.argeo.slc.client.ui.dist.editors.DistributionEditorInput;
+import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.PartInitException;
+
+/** Listen to double-clicks */
+public class DistTreeDoubleClickListener implements IDoubleClickListener {
+
+ public void doubleClick(DoubleClickEvent event) {
+ if (event.getSelection() == null || event.getSelection().isEmpty())
+ return;
+ Object obj = ((IStructuredSelection) event.getSelection())
+ .getFirstElement();
+ if (obj instanceof WorkspaceElem) {
+ WorkspaceElem we = (WorkspaceElem) obj;
+ DistributionEditorInput dei = new DistributionEditorInput(we
+ .getRepoElem().getRepository(), we.getRepoElem()
+ .getCredentials(), we.getRepoElem().getLabel(), we
+ .getRepoElem().getDescription(), we.getWorkspaceName());
+ try {
+ DistPlugin.getDefault().getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage()
+ .openEditor(dei, DistributionEditor.ID);
+ } catch (PartInitException e) {
+ ErrorFeedback.show(
+ "Cannot open editor for " + we.getWorkspaceName(), e);
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.client.ui.dist.controllers;
+
+import org.argeo.slc.client.ui.dist.DistImages;
+import org.argeo.slc.client.ui.dist.model.DistParentElem;
+import org.argeo.slc.client.ui.dist.model.GroupElem;
+import org.argeo.slc.client.ui.dist.model.RepoElem;
+import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Manages icons and labels for the distributions browser
+ */
+public class DistTreeLabelProvider extends ColumnLabelProvider {
+ @Override
+ public String getText(Object element) {
+ if (element instanceof DistParentElem)
+ return ((DistParentElem) element).getLabel();
+ else
+ return element.toString();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof DistParentElem) {
+ DistParentElem bElement = (DistParentElem) element;
+ if (bElement instanceof RepoElem)
+ if (bElement.inHome())
+ return DistImages.IMG_HOME_REPO;
+ else if (bElement.isReadOnly())
+ return DistImages.IMG_REPO_READONLY;
+ else
+ return DistImages.IMG_REPO;
+ else if (bElement instanceof GroupElem)
+ return DistImages.IMG_WKSP;
+ else if (element instanceof WorkspaceElem)
+ if (((WorkspaceElem) element).isReadOnly())
+ return DistImages.IMG_DISTGRP_READONLY;
+ else
+ return DistImages.IMG_DISTGRP;
+ }
+ return null;
+ }
+}
\ No newline at end of file
*/
package org.argeo.slc.client.ui.dist.editors;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
import javax.jcr.Node;
-import javax.jcr.Property;
+import javax.jcr.NodeIterator;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.qom.Ordering;
+import javax.jcr.query.qom.QueryObjectModel;
+import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.Selector;
import org.argeo.ArgeoException;
import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
import org.argeo.slc.client.ui.dist.DistConstants;
import org.argeo.slc.client.ui.dist.DistImages;
-import org.argeo.slc.client.ui.dist.providers.ArtifactsTreeContentProvider;
-import org.argeo.slc.client.ui.dist.utils.GenericDoubleClickListener;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
import org.argeo.slc.repo.RepoConstants;
import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.ViewerCell;
+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.Tree;
import org.eclipse.swt.widgets.TreeColumn;
+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;
/**
- * Basic View to browse a maven based repository.
- *
- * By Default size of the various bundles is not computed but it can be
- * activated the view command.
+ * Exposes the various group id of a distribution as a tree.
*/
public class ArtifactsBrowserPage extends FormPage implements DistConstants,
RepoConstants {
+
final static String PAGE_ID = "artifactsBrowserPage";
// private final static Log log = LogFactory
// .getLog(ArtifactsBrowserPage.class);
- /* DEPENDENCY INJECTION */
- private Session jcrSession;
-
- // Business objects
- private Node rootNode;
+ // Business object
+ private Session session;
// This page widgets
private TreeViewer artifactTreeViewer;
- private boolean isSizeVisible = false;
-
- // To be able to configure columns easily
- public static final int COLUMN_TREE = 0;
- public static final int COLUMN_DATE = 1;
- public static final int COLUMN_SIZE = 2;
- private static final int SIZE_COL_WIDTH = 55;
public ArtifactsBrowserPage(FormEditor editor, String title, Session session) {
super(editor, PAGE_ID, title);
- this.jcrSession = session;
+ this.session = session;
}
@Override
protected void createFormContent(IManagedForm managedForm) {
- ScrolledForm form = managedForm.getForm();
- Composite parent = form.getBody();
- // Enable the different parts to fill the whole page when the tab is
- // maximized
- parent.setLayout(new FillLayout());
- artifactTreeViewer = createArtifactsTreeViewer(parent);
-
- // context menu : it is completely defined in the plugin.xml file.
- // Nothing in the context menu for the time being
- // MenuManager menuManager = new MenuManager();
- // Menu menu =
- // menuManager.createContextMenu(artifactTreeViewer.getTree());
- // artifactTreeViewer.getTree().setMenu(menu);
- // getSite().registerContextMenu(menuManager, artifactTreeViewer);
-
- getEditor().getSite().setSelectionProvider(artifactTreeViewer);
-
- // packagesViewer.setComparer(new NodeViewerComparer());
-
- // Model initialisation
- if (jcrSession != null) {
- try {
- DistributionEditorInput dei = (DistributionEditorInput) getEditorInput();
- if (dei.getArtifactsBase().equals(DEFAULT_ARTIFACTS_BASE_PATH)) {
- rootNode = jcrSession.getRootNode();
- } else {
- rootNode = jcrSession.getNode(dei.getArtifactsBase());
- }
- artifactTreeViewer.setInput(rootNode);
- } catch (RepositoryException e) {
- throw new ArgeoException("Cannot load base artifact nodes", e);
- }
+ try {
+ ScrolledForm form = managedForm.getForm();
+ Composite parent = form.getBody();
+ // Enable the different parts to fill the whole page when the tab is
+ // maximized
+ parent.setLayout(new FillLayout());
+ createExportPackageSection(parent);
+ getEditor().getSite().setSelectionProvider(artifactTreeViewer);
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot create artifact browser page", e);
}
}
- protected TreeViewer createArtifactsTreeViewer(Composite parent) {
- int style = SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION;
- Tree tree = new Tree(parent, style);
- createColumn(tree, "Artifacts", SWT.LEFT, 300);
- createColumn(tree, "Date created", SWT.LEFT, 105);
- createColumn(tree, "Size", SWT.RIGHT, 0);
- tree.setLinesVisible(true);
- tree.setHeaderVisible(true);
+ private NodeIterator listNodes(String nodeType, String orderBy)
+ throws RepositoryException {
+ QueryManager queryManager = session.getWorkspace().getQueryManager();
+ QueryObjectModelFactory factory = queryManager.getQOMFactory();
- TreeViewer viewer = new TreeViewer(tree);
+ final String nodeSelector = "nodes";
+ Selector source = factory.selector(nodeType, nodeSelector);
- viewer.setContentProvider(new ArtifactsTreeContentProvider());
- viewer.setLabelProvider(new ArtifactLabelProvider());
- viewer.addSelectionChangedListener(new ArtifactTreeSelectionListener());
- viewer.addDoubleClickListener(new GenericDoubleClickListener());
- viewer.setInput(rootNode);
+ Ordering order = factory.ascending(factory.propertyValue(nodeSelector,
+ orderBy));
+ Ordering[] orderings = { order };
- return viewer;
- }
+ QueryObjectModel query = factory.createQuery(source, null, orderings,
+ null);
- private static TreeColumn createColumn(Tree parent, String name, int style,
- int width) {
- TreeColumn result = new TreeColumn(parent, style);
- result.setText(name);
- result.setWidth(width);
- result.setMoveable(true);
- result.setResizable(true);
- return result;
- }
+ QueryResult result = query.execute();
- protected TreeViewer getArtifactTreeViewer() {
- return artifactTreeViewer;
+ return result.getNodes();
}
- /**
- * Refresh the given element of the tree browser. If null is passed as a
- * parameter, it refreshes the whole tree
- */
- public void refresh(Object element) {
- if (element == null) {
- artifactTreeViewer.refresh(rootNode);
- } else
- artifactTreeViewer.refresh(element);
- }
+ /** Export Package Section */
+ private void createExportPackageSection(Composite parent)
+ throws RepositoryException {
- /** Returns wether size column is visible or not */
- public boolean isSizeVisible() {
- return isSizeVisible;
- }
-
- /** Sets the visibility of the size column */
- public void setSizeVisible(boolean visible) {
- if (isSizeVisible == visible)
- return; // nothing has changed
- else
- isSizeVisible = visible;
-
- if (visible) {
- artifactTreeViewer.getTree().getColumn(COLUMN_SIZE)
- .setWidth(SIZE_COL_WIDTH);
- } else {
- // we just hide the column, we don't refresh the whole tree.
- artifactTreeViewer.getTree().getColumn(COLUMN_SIZE).setWidth(0);
- }
- }
-
- private class ArtifactLabelProvider extends ColumnLabelProvider implements
- DistConstants, SlcTypes {
-
- // Utils
- protected DateFormat timeFormatter = new SimpleDateFormat(
- DATE_TIME_FORMAT);
+ int style = SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL
+ | SWT.FULL_SELECTION | SWT.BORDER;
+ Tree tree = new Tree(parent, style);
+ createColumn(tree, "Artifacts", SWT.LEFT, 300);
+ tree.setLinesVisible(true);
+ tree.setHeaderVisible(true);
- public void update(ViewerCell cell) {
- int colIndex = cell.getColumnIndex();
- Object element = cell.getElement();
- cell.setText(getColumnText(element, colIndex));
+ artifactTreeViewer = new TreeViewer(tree);
- if (element instanceof Node && colIndex == 0) {
+ artifactTreeViewer.setLabelProvider(new ColumnLabelProvider() {
+ @Override
+ public String getText(Object element) {
Node node = (Node) element;
try {
- if (node.isNodeType(SLC_ARTIFACT_BASE))
- cell.setImage(DistImages.IMG_ARTIFACT_BASE);
- else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE))
- cell.setImage(DistImages.IMG_ARTIFACT_VERSION_BASE);
+ if (node.isNodeType(SlcTypes.SLC_GROUP_BASE))
+ return JcrUtils.get((Node) element,
+ SlcNames.SLC_GROUP_BASE_ID);
+ else if (node.isNodeType(SlcTypes.SLC_ARTIFACT_BASE))
+ return JcrUtils.get((Node) element,
+ SlcNames.SLC_ARTIFACT_ID);
+ else
+ return node.getName();
} catch (RepositoryException e) {
- // Silent
+ throw new SlcException("Cannot browse artifacts", e);
}
}
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof Node) {
+ @Override
+ public Image getImage(Object element) {
Node node = (Node) element;
try {
- if (node.isNodeType(SLC_ARTIFACT_BASE)) {
+
+ if (node.isNodeType(SlcTypes.SLC_GROUP_BASE))
+ return DistImages.IMG_WKSP;
+ else if (node.isNodeType(SlcTypes.SLC_ARTIFACT_BASE))
return DistImages.IMG_ARTIFACT_BASE;
- } else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE)) {
+ else if (node
+ .isNodeType(SlcTypes.SLC_ARTIFACT_VERSION_BASE))
return DistImages.IMG_ARTIFACT_VERSION_BASE;
- }
+ else
+ return null;
} catch (RepositoryException e) {
- // Silent
+ throw new SlcException("Cannot get images for artifacts", e);
}
}
- return null;
- }
+ });
- public String getColumnText(Object element, int columnIndex) {
- try {
- if (element instanceof Node) {
- Node node = (Node) element;
- switch (columnIndex) {
- case COLUMN_TREE:
- return node.getName();
- case COLUMN_SIZE:
- if (isSizeVisible) {
- long size = JcrUtils.getNodeApproxSize(node) / 1024;
- if (size > 1024)
- return size / 1024 + " MB";
- else
- return size + " KB";
- } else
- return "";
- case COLUMN_DATE:
- if (node.hasProperty(Property.JCR_CREATED))
- return timeFormatter.format(node
- .getProperty(Property.JCR_CREATED)
- .getDate().getTime());
- else
- return null;
+ artifactTreeViewer.setContentProvider(new ITreeContentProvider() {
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput,
+ Object newInput) {
+ }
+
+ public Object[] getElements(Object inputElement) {
+ try {
+ List<Node> nodes = JcrUtils.nodeIteratorToList(listNodes(
+ SlcTypes.SLC_GROUP_BASE, SlcNames.SLC_NAME));
+ return nodes.toArray();
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot list children Nodes", e);
+ }
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ // Only 3 levels for the time being
+ try {
+ Node pNode = (Node) parentElement;
+ if (pNode.isNodeType(SlcTypes.SLC_GROUP_BASE)) {
+ return getArtifactBase(pNode,
+ SlcTypes.SLC_ARTIFACT_BASE);
+ } else if (pNode.isNodeType(SlcTypes.SLC_ARTIFACT_BASE)) {
+ return getArtifactBase(pNode,
+ SlcTypes.SLC_ARTIFACT_VERSION_BASE);
}
+ return null;
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot list children Nodes", e);
}
- } 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);
- // }
- // }
- }
+ // Helper to get children because current version of Jackrabbit is
+ // buggy in remote
+ private Object[] getArtifactBase(Node parent, String nodeType)
+ throws RepositoryException {
+ List<Node> nodes = new ArrayList<Node>();
+ NodeIterator ni = parent.getNodes();
+ while (ni.hasNext()) {
+ Node node = ni.nextNode();
+ if (node.isNodeType(nodeType))
+ nodes.add(node);
+ }
+ return nodes.toArray();
+ }
- private class ArtifactTreeSelectionListener implements
- ISelectionChangedListener {
+ public Object getParent(Object element) {
+ return null;
+ }
- public void selectionChanged(SelectionChangedEvent event) {
- ISelection selection = event.getSelection();
- if (selection != null && selection instanceof IStructuredSelection) {
- IStructuredSelection iss = (IStructuredSelection) selection;
- if (iss.size() == 1) {
- artifactTreeViewer.refresh(iss.getFirstElement());
+ public boolean hasChildren(Object element) {
+ try {
+ Node pNode = (Node) element;
+ if (pNode.isNodeType(SlcTypes.SLC_GROUP_BASE)
+ || pNode.isNodeType(SlcTypes.SLC_ARTIFACT_BASE)) {
+ // might return true even if there is no "valid" child
+ return pNode.hasNodes();
+ } else
+ return false;
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot check children Nodes", e);
}
}
+ });
+
+ artifactTreeViewer.addDoubleClickListener(new DoubleClickListener());
+ artifactTreeViewer.setInput("Initialize");
+ }
+
+ private class DoubleClickListener implements IDoubleClickListener {
+
+ public void doubleClick(DoubleClickEvent event) {
+ Object obj = ((IStructuredSelection) event.getSelection())
+ .getFirstElement();
+ try {
+ if (obj instanceof Node) {
+ Node node = (Node) obj;
+ if (node.isNodeType(SlcTypes.SLC_ARTIFACT_VERSION_BASE)) {
+ // TODO fix using QOM after jcr upgrade
+ NodeIterator ni = node.getNodes();
+ while (ni.hasNext()) {
+ Node curr = ni.nextNode();
+ if (curr.isNodeType(SlcTypes.SLC_BUNDLE_ARTIFACT)) {
+ GenericBundleEditorInput gaei = new GenericBundleEditorInput(
+ curr);
+ DistPlugin
+ .getDefault()
+ .getWorkbench()
+ .getActiveWorkbenchWindow()
+ .getActivePage()
+ .openEditor(gaei,
+ GenericBundleEditor.ID);
+ }
+ }
+ }
+ }
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Repository error while getting node info", re);
+ } catch (PartInitException pie) {
+ throw new ArgeoException(
+ "Unexepected exception while opening artifact editor",
+ pie);
+ }
}
+ }
+ private static TreeColumn createColumn(Tree parent, String name, int style,
+ int width) {
+ TreeColumn result = new TreeColumn(parent, style);
+ result.setText(name);
+ result.setWidth(width);
+ result.setMoveable(true);
+ result.setResizable(true);
+ return result;
}
+
}
tree.setLayoutData(gd);
TreeViewerColumn col = new TreeViewerColumn(viewer, SWT.FILL);
- col.getColumn().setWidth(200);
+ col.getColumn().setWidth(400);
col.setLabelProvider(new ColumnLabelProvider() {
@Override
headerSection.setClient(tree);
viewer.setInput("Initialize");
+ // work around a display problem : the tree table has only a few lines
+ // when the tree is not expended
+ viewer.expandToLevel(2);
}
/** Import Package Section */
// Name
TableViewerColumn col = new TableViewerColumn(viewer, SWT.NONE);
- col.getColumn().setWidth(300);
+ col.getColumn().setWidth(350);
col.getColumn().setText("Name");
col.setLabelProvider(new ColumnLabelProvider() {
@Override
import org.argeo.ArgeoException;
import org.argeo.slc.client.ui.dist.DistImages;
import org.argeo.slc.client.ui.dist.utils.DistUiHelpers;
-import org.argeo.slc.client.ui.dist.utils.GenericDoubleClickListener;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
import org.eclipse.jface.viewers.ColumnLabelProvider;
complexTree = new TreeViewer(tree);
// Configure
- complexTree.addDoubleClickListener(new GenericDoubleClickListener());
+ // complexTree.addDoubleClickListener(new GenericDoubleClickListener());
complexTree = new TreeViewer(tree);
complexTree.setContentProvider(new TreeContentProvider());
complexTree.setLabelProvider(new TreeLabelProvider());
elements.add(child);
}
}
+
+ // Properties
+ PropertyIterator pi = node.getProperties();
+ while (pi.hasNext()) {
+ Property curProp = pi.nextProperty();
+ if (!curProp.getName().startsWith("jcr:")
+ && !curProp.isMultiple())
+ elements.add(curProp);
+ }
+
} catch (RepositoryException e) {
throw new ArgeoException(
"Unexpected exception while listing node properties", e);
* */
public class DistributionEditorInput implements IEditorInput, SlcNames {
+ private Repository repository;
+ private Credentials credentials;
private String repositoryName;
private String repositoryDescription;
- private Repository repository;
private String workspaceName;
- private String artifactsBase = RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH;
- private Credentials credentials;
- public DistributionEditorInput(String repositoryName,
- String repositoryDescription, Repository repository,
- String workspaceName, String artifactsBase, Credentials credentials) {
+ private String artifactsBase;
+
+ public DistributionEditorInput(Repository repository,
+ Credentials credentials, String repositoryName,
+ String repositoryDescription, String workspaceName,
+ String artifactsBase) {
super();
this.repository = repository;
this.repositoryName = repositoryName;
this.credentials = credentials;
}
- public DistributionEditorInput(String repositoryName,
- String repositoryDescription, Repository repository,
- String workspaceName, Credentials credentials) {
- this(repositoryName, repositoryDescription, repository, workspaceName,
- RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH, credentials);
+ public DistributionEditorInput(Repository repository,
+ Credentials credentials, String repositoryName,
+ String repositoryDescription, String workspaceName) {
+ this(repository, credentials, repositoryName, repositoryDescription,
+ workspaceName, RepoConstants.DEFAULT_ARTIFACTS_BASE_PATH);
}
public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
import org.argeo.slc.client.ui.dist.DistConstants;
import org.argeo.slc.client.ui.dist.DistImages;
import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.PrivilegedJob;
import org.argeo.slc.client.ui.dist.commands.DeleteArtifacts;
import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
import org.argeo.slc.client.ui.dist.utils.NodeViewerComparator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Table;
}
private void asynchronousRefresh() {
- refreshFilteredList();
- // FIXME Does not work yet: how can the job set the viewer input ?
- // RefreshJob job = new RefreshJob(session, artifactTxt.getText());
- // job.setUser(true);
- // job.schedule();
- // viewer.setInput(nodes);
+ RefreshJob job = new RefreshJob(artifactTxt.getText(), viewer,
+ getSite().getShell().getDisplay());
+ job.setUser(true);
+ job.schedule();
}
- private class RefreshJob extends Job {
- private Session session;
- private List<Node> nodes;
+ private class RefreshJob extends PrivilegedJob {
+ private TableViewer viewer;
private String filter;
+ private Display display;
- public RefreshJob(Session session, String filter, List<Node> nodes) {
+ public RefreshJob(String filter, TableViewer viewer, Display display) {
super("Get bundle list");
- this.session = session;
+ this.filter = filter;
+ this.viewer = viewer;
+ this.display = display;
}
@Override
- protected IStatus run(IProgressMonitor progressMonitor) {
+ protected IStatus doRun(IProgressMonitor progressMonitor) {
try {
ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor);
monitor.beginTask("Getting bundle list", -1);
- List<Node> result = JcrUtils
+ final List<Node> result = JcrUtils
.nodeIteratorToList(listBundleArtifacts(session, filter));
- nodes.addAll(result);
+
+ display.asyncExec(new Runnable() {
+ public void run() {
+ viewer.setInput(result);
+ }
+ });
} catch (Exception e) {
return new Status(IStatus.ERROR, DistPlugin.ID,
"Cannot get bundle list", e);
package org.argeo.slc.client.ui.dist.model;
+/** Common super class for all dist tree elements */
public abstract class DistParentElem {
private boolean inHome = false;
private boolean isReadOnly = false;
public abstract Object[] getChildren();
+ public boolean hasChildren() {
+ return true;
+ }
+
public void dispose() {
}
+ public void setInHome(boolean inHome) {
+ this.inHome = inHome;
+ }
+
+ public void setReadOnly(boolean isReadOnly) {
+ this.isReadOnly = isReadOnly;
+ }
+
public boolean inHome() {
return inHome;
}
import java.util.ArrayList;
import java.util.List;
-import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
}
public Object[] getChildren() {
- repoElem.connect();
Session session = null;
try {
Repository repository = repoElem.getRepository();
- Node repoNode = repoElem.getRepoNode();
+ // Node repoNode = repoElem.getRepoNode();
session = repository.login(repoElem.getCredentials());
String[] workspaceNames = session.getWorkspace()
for (String workspaceName : workspaceNames) {
// filter technical workspaces
if (workspaceName.startsWith(name)) {
- Node workspaceNode = repoNode.hasNode(workspaceName) ? repoNode
- .getNode(workspaceName) : repoNode
- .addNode(workspaceName);
distributionElems.add(new WorkspaceElem(repoElem,
- workspaceNode));
- // FIXME remove deleted workspaces
+ workspaceName));
}
}
return distributionElems.toArray();
import javax.jcr.Session;
import javax.jcr.nodetype.NodeType;
+import org.argeo.jcr.ArgeoJcrUtils;
+import org.argeo.jcr.ArgeoNames;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.SlcException;
+import org.argeo.slc.repo.RepoConstants;
import org.argeo.slc.repo.RepoUtils;
import org.argeo.util.security.Keyring;
+/**
+ * Abstract a repository. Might be persisted by a node in the current user home
+ * Node or just an URI and a label if user is anonymous
+ */
public class RepoElem extends DistParentElem {
- private Node repoNode;
+
private Repository repository;
private Credentials credentials;
-
private RepositoryFactory repositoryFactory;
private Keyring keyring;
- @Deprecated
- public RepoElem(Node repoNode, boolean inHome, boolean isReadOnly) {
- super(inHome, isReadOnly);
- this.repoNode = repoNode;
- }
-
- /** Inject repofactory and keyring to enable lazy init */
- public RepoElem(Node repoNode, RepositoryFactory repoFactory,
- Keyring keyring, boolean inHome, boolean isReadOnly) {
- super(inHome, isReadOnly);
- this.repoNode = repoNode;
- this.repositoryFactory = repoFactory;
- this.keyring = keyring;
- }
+ // Defines current repo
+ private Node repoNode = null;
+ private String label;
+ private String uri;
- /** Inject repofactory and keyring to enable lazy init */
+ /**
+ * Creates a RepoElement for an authenticated user. repofactory and keyring
+ * are used to enable lazy init
+ *
+ */
public RepoElem(Node repoNode, RepositoryFactory repoFactory,
Keyring keyring) {
this.repoNode = repoNode;
this.repositoryFactory = repoFactory;
this.keyring = keyring;
+ try {
+ // initialize this repo informations
+ setInHome(RepoConstants.DEFAULT_JAVA_REPOSITORY_ALIAS
+ .equals(repoNode.getName()));
+ if (!inHome())
+ setReadOnly(!repoNode.hasNode(ArgeoNames.ARGEO_PASSWORD));
+ uri = JcrUtils.get(repoNode, ArgeoNames.ARGEO_URI);
+ label = repoNode.isNodeType(NodeType.MIX_TITLE) ? repoNode
+ .getProperty(Property.JCR_TITLE).getString() : repoNode
+ .getName();
+ } catch (RepositoryException e) {
+ throw new SlcException("Unable to " + "initialize repo element", e);
+ }
}
- @Deprecated
- public RepoElem(Node repoNode) {
- this.repoNode = repoNode;
+ /**
+ * Creates a RepoElement for anonymous user. repofactory is used to enable
+ * lazy init
+ *
+ */
+ public RepoElem(RepositoryFactory repoFactory, String uri, String label) {
+ this.repositoryFactory = repoFactory;
+ this.uri = uri;
+ this.label = label;
}
/** Lazily connects to repository */
protected void connect() {
if (repository != null)
return;
- repository = RepoUtils.getRepository(repositoryFactory, keyring,
- repoNode);
- credentials = RepoUtils.getRepositoryCredentials(keyring, repoNode);
+ if (repoNode == null)
+ // Anonymous
+ repository = ArgeoJcrUtils.getRepositoryByUri(repositoryFactory,
+ uri);
+ else {
+ repository = RepoUtils.getRepository(repositoryFactory, keyring,
+ repoNode);
+ credentials = RepoUtils.getRepositoryCredentials(keyring, repoNode);
+ }
}
public String getLabel() {
- try {
- if (repoNode.isNodeType(NodeType.MIX_TITLE)) {
- return repoNode.getProperty(Property.JCR_TITLE).getString();
- } else {
- return repoNode.getName();
- }
- } catch (RepositoryException e) {
- throw new SlcException("Cannot read label of " + repoNode, e);
- }
+ return label;
+ }
+
+ public String getUri() {
+ return uri;
}
public String toString() {
- return repoNode.toString();
+ return repoNode != null ? repoNode.toString() : label;
}
public Object[] getChildren() {
session = repository.login(credentials);
String[] workspaceNames = session.getWorkspace()
.getAccessibleWorkspaceNames();
- // List<DistributionElem> distributionElems = new
- // ArrayList<DistributionElem>();
Map<String, GroupElem> children = new HashMap<String, GroupElem>();
- for (String workspaceName : workspaceNames) {
+
+ buildWksp: for (String workspaceName : workspaceNames) {
+ // Add a supplementary check to hide workspace that are not
+ // public to anonymous user
+
+ // TODO fix this
+ // if (repoNode == null) {
+ // Session tmpSession = null;
+ // try {
+ // tmpSession = repository.login();
+ // Privilege[] priv = new Privilege[1];
+ // priv[0] = tmpSession.getAccessControlManager()
+ // .privilegeFromName(Privilege.JCR_READ);
+ // Privilege[] tmp = tmpSession.getAccessControlManager()
+ // .getPrivileges("/");
+ // boolean res = tmpSession.getAccessControlManager()
+ // .hasPrivileges("/", priv);
+ // if (!res)
+ // continue buildWksp;
+ // } catch (RepositoryException e) {
+ // throw new SlcException(
+ // "Cannot list workspaces for anonymous user", e);
+ // } finally {
+ // JcrUtils.logoutQuietly(tmpSession);
+ // }
+ // }
+
// filter technical workspaces
// FIXME: rely on a more robust rule than just wksp name
if (workspaceName.lastIndexOf('-') > 0) {
String prefix = workspaceName.substring(0,
workspaceName.lastIndexOf('-'));
- if (!repoNode.hasNode(workspaceName))
- repoNode.addNode(workspaceName);
- repoNode.getSession().save();
if (!children.containsKey(prefix)) {
children.put(prefix, new GroupElem(RepoElem.this,
prefix));
}
- // FIXME remove deleted workspaces
}
}
return children.values().toArray();
}
}
- public String getRepoPath() {
- try {
- return repoNode.getPath();
- } catch (RepositoryException e) {
- throw new SlcException("Cannot get path for " + repoNode, e);
- }
- }
-
public Repository getRepository() {
connect();
return repository;
return credentials;
}
+ public String getDescription() {
+ String desc = label;
+ if (repoNode != null)
+ desc = label + " (" + uri + ")";
+ return desc;
+ }
+
+ /** Might return null in case of an anonymous user */
public Node getRepoNode() {
return repoNode;
}
-
-}
+}
\ No newline at end of file
package org.argeo.slc.client.ui.dist.model;
-import javax.jcr.Credentials;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-
-import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
-
/** Abstracts a workspace that contains a given distribution */
-public class WorkspaceElem extends TreeParent {
+public class WorkspaceElem extends DistParentElem {
private final RepoElem repoElem;
- private final Node workspaceNode;
+ private String workspaceName;
+ private String label;
/**
* Helper to display only version when the workspace name is well formatted
*/
- private static String formatName(Node workspaceNode) {
- String name = JcrUtils.getNameQuietly(workspaceNode);
+ private static String formatName(String name) {
if (name != null && name.lastIndexOf('-') > 0)
return name.substring(name.lastIndexOf('-') + 1);
else
return name;
}
- public WorkspaceElem(RepoElem repoElem, Node workspaceNode) {
- super(formatName(workspaceNode));
+ public WorkspaceElem(RepoElem repoElem, String workspaceName) {
this.repoElem = repoElem;
- this.workspaceNode = workspaceNode;
- }
-
- public Node getWorkspaceNode() {
- return workspaceNode;
+ this.workspaceName = workspaceName;
+ this.label = formatName(workspaceName);
}
public String getWorkspaceName() {
- return JcrUtils.getNameQuietly(workspaceNode);
+ return workspaceName;
}
- public String getWorkspacePath() {
- try {
- return workspaceNode.getPath();
- } catch (RepositoryException e) {
- throw new SlcException("Cannot get or add workspace path "
- + getWorkspaceName(), e);
- }
+ public RepoElem getRepoElem() {
+ return repoElem;
}
- public String getRepoPath() {
- try {
- return workspaceNode.getParent().getPath();
- } catch (RepositoryException e) {
- throw new SlcException("Cannot get or add workspace path "
- + getWorkspaceName(), e);
- }
+ public boolean isReadOnly() {
+ return repoElem.isReadOnly();
}
- public RepoElem getRepoElem() {
- return repoElem;
+ public boolean hasChildren() {
+ return false;
}
- public Credentials getCredentials() {
- return repoElem.getCredentials();
+ public Object[] getChildren() {
+ return null;
}
- public boolean isReadOnly() {
- return repoElem.isReadOnly();
+ @Override
+ public String getLabel() {
+ return label;
}
}
+++ /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.slc.client.ui.dist.providers;
-
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-
-import org.argeo.ArgeoException;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.client.ui.dist.DistConstants;
-import org.argeo.slc.client.ui.dist.DistImages;
-import org.argeo.slc.jcr.SlcTypes;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.swt.graphics.Image;
-
-public class ArtifactLabelProvider extends ColumnLabelProvider implements
- DistConstants, SlcTypes {
-
- // To be able to change column order easily
- public static final int COLUMN_TREE = 0;
- public static final int COLUMN_DATE = 1;
- public static final int COLUMN_SIZE = 2;
-
- // Utils
- protected static DateFormat timeFormatter = new SimpleDateFormat(
- DATE_TIME_FORMAT);
-
- public void update(ViewerCell cell) {
- int colIndex = cell.getColumnIndex();
- Object element = cell.getElement();
- cell.setText(getColumnText(element, colIndex));
- if (element instanceof Node && colIndex == 0) {
- Node node = (Node) element;
- try {
- if (node.isNodeType(SLC_ARTIFACT_BASE))
- cell.setImage(DistImages.IMG_ARTIFACT_BASE);
- else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE))
- cell.setImage(DistImages.IMG_ARTIFACT_VERSION_BASE);
- } catch (RepositoryException e) {
- // Silent
- }
- }
- }
-
- @Override
- public Image getImage(Object element) {
-
- if (element instanceof Node) {
- Node node = (Node) element;
- try {
- if (node.isNodeType(SLC_ARTIFACT_BASE)) {
- return DistImages.IMG_ARTIFACT_BASE;
- } else if (node.isNodeType(SLC_ARTIFACT_VERSION_BASE)) {
- return DistImages.IMG_ARTIFACT_VERSION_BASE;
- }
- } catch (RepositoryException e) {
- // Silent
- }
- }
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- try {
- if (element instanceof Node) {
- Node node = (Node) element;
- switch (columnIndex) {
- case COLUMN_TREE:
- return node.getName();
- case COLUMN_SIZE:
- long size = JcrUtils.getNodeApproxSize(node) / 1024;
- if (size > 1024)
- return size / 1024 + " MB";
- else
- return size + " KB";
- case COLUMN_DATE:
- if (node.hasProperty(Property.JCR_LAST_MODIFIED))
- return timeFormatter.format(node
- .getProperty(Property.JCR_LAST_MODIFIED)
- .getDate().getTime());
- else
- return null;
- }
- }
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexepected error while getting property values", re);
- }
- 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.slc.client.ui.dist.providers;
-
-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.argeo.slc.jcr.SlcTypes;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-public class ArtifactsTreeContentProvider implements ITreeContentProvider,
- SlcTypes {
-
- // Utils
- private boolean sortChildren = true;
- private JcrItemsComparator itemComparator = new JcrItemsComparator();
-
- public Object[] getElements(Object parent) {
- return getChildren(parent);
- }
-
- public Object getParent(Object child) {
- return null;
- }
-
- public Object[] getChildren(Object parent) {
- Object[] elements = null;
- try {
- if (parent instanceof Node) {
- Node node = (Node) parent;
- NodeIterator ni = node.getNodes();
- List<Node> nodesList = new ArrayList<Node>();
- while (ni.hasNext()) {
- nodesList.add(ni.nextNode());
- }
- if (sortChildren) {
- Node[] arr = (Node[]) nodesList.toArray(new Node[nodesList
- .size()]);
- Arrays.sort(arr, itemComparator);
- return arr;
- } else
- return nodesList.toArray();
-
- }
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected exception while listing node properties", e);
- }
- return elements;
- }
-
- public boolean hasChildren(Object parent) {
- try {
- if (parent instanceof Node) {
- Node curNode = (Node) parent;
- // We manually stop digging at this level
- if (curNode.isNodeType(SLC_ARTIFACT_VERSION_BASE))
- return false;
- else if (curNode.hasNodes())
- return true;
- }
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Unexpected exception while checking if property is multiple",
- e);
- }
- return false;
- }
-
- public void setSortChildren(boolean sortChildren) {
- this.sortChildren = sortChildren;
- }
-
- public boolean getSortChildren() {
- return sortChildren;
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- public void dispose() {
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.argeo.slc.client.ui.dist.providers;
-
-import javax.jcr.Credentials;
-import javax.jcr.NoSuchWorkspaceException;
-import javax.jcr.Node;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.RepositoryFactory;
-import javax.jcr.Session;
-
-import org.argeo.jcr.JcrUtils;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.repo.RepoUtils;
-import org.argeo.util.security.Keyring;
-
-/**
- * Provides shortcut to retrieve sessions, repositories and workspaces that are
- * persisted in the current user node using path only.
- */
-public class DistSessionFactory {
-
- /* DEPENDENCY INJECTION */
- private RepositoryFactory repositoryFactory;
- private Keyring keyring;
- private Repository nodeRepository;
-
- /**
- * Returns a new session on the given workspace. This session *must* be
- * disposed by the caller. If the workspace does not exist and
- * createIfNeeded==true, tries to create it
- *
- * */
- public Session getSessionFromWorkspacePath(String path,
- boolean createIfNeeded) {
- Session nodeSession = null;
- try {
- nodeSession = nodeRepository.login();
- Node localWksp = nodeSession.getNode(path);
- Repository repository = RepoUtils.getRepository(repositoryFactory,
- keyring, localWksp.getParent());
- Credentials credentials = RepoUtils.getRepositoryCredentials(
- keyring, localWksp.getParent());
-
- String wkspName = JcrUtils.lastPathElement(path);
- Session session = null;
- try {
- session = repository.login(credentials, wkspName);
- } catch (NoSuchWorkspaceException e) {
- if (createIfNeeded) {
- Session defaultSession = repository.login(credentials);
- try {
- defaultSession.getWorkspace().createWorkspace(wkspName);
- } catch (Exception e1) {
- throw new SlcException("Cannot create new workspace "
- + wkspName, e);
- } finally {
- JcrUtils.logoutQuietly(defaultSession);
- }
- session = repository.login(credentials, wkspName);
- } else
- throw new SlcException("Workspace" + wkspName
- + "does not exists and should not be created", e);
- }
- return session;
- } catch (RepositoryException e) {
- throw new SlcException("cannot create session" + " for workspace "
- + path, e);
- } finally {
- JcrUtils.logoutQuietly(nodeSession);
- }
- }
-
- /*
- * DEPENDENCY INJECTION
- */
- public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
- this.repositoryFactory = repositoryFactory;
- }
-
- public void setKeyring(Keyring keyring) {
- this.keyring = keyring;
- }
-
- public void setRepository(Repository nodeRepository) {
- this.nodeRepository = nodeRepository;
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.argeo.slc.client.ui.dist.providers;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.Property;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.RepositoryFactory;
-import javax.jcr.Session;
-import javax.jcr.nodetype.NodeType;
-
-import org.argeo.jcr.ArgeoJcrUtils;
-import org.argeo.jcr.ArgeoNames;
-import org.argeo.jcr.ArgeoTypes;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.jcr.UserJcrUtils;
-import org.argeo.slc.SlcException;
-import org.argeo.slc.client.ui.dist.model.DistParentElem;
-import org.argeo.slc.client.ui.dist.model.RepoElem;
-import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
-import org.argeo.slc.repo.RepoConstants;
-import org.argeo.util.security.Keyring;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-
-/**
- * Enables browsing in local and remote slc distribution repositories. Keyring
- * and repository factory must be injected
- */
-public class DistTreeContentProvider implements ITreeContentProvider {
- private Session nodeSession;
- List<RepoElem> repositories = new ArrayList<RepoElem>();
-
- private RepositoryFactory repositoryFactory;
- private Keyring keyring;
-
- public Object[] getElements(Object input) {
- Repository nodeRepository = (Repository) input;
- try {
- if (nodeSession != null)
- dispose();
- nodeSession = nodeRepository.login();
-
- String reposPath = UserJcrUtils.getUserHome(nodeSession).getPath()
- + RepoConstants.REPOSITORIES_BASE_PATH;
-
- if (!nodeSession.itemExists(reposPath))
- initializeModel(nodeSession);
-
- NodeIterator repos = nodeSession.getNode(reposPath).getNodes();
- while (repos.hasNext()) {
- Node repoNode = repos.nextNode();
- if (repoNode.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY)) {
- if (RepoConstants.DEFAULT_JAVA_REPOSITORY_ALIAS
- .equals(repoNode.getName()))
- repositories.add(new RepoElem(repoNode,
- repositoryFactory, keyring, true, false));
- else if (repoNode.hasNode(ArgeoNames.ARGEO_PASSWORD))
- repositories.add(new RepoElem(repoNode,
- repositoryFactory, keyring));
- else
- repositories.add(new RepoElem(repoNode,
- repositoryFactory, keyring, false, true));
- }
- }
- } catch (RepositoryException e) {
- throw new SlcException("Cannot get base elements", e);
- }
- return repositories.toArray();
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof DistParentElem) {
- return ((DistParentElem) parentElement).getChildren();
- } else if (parentElement instanceof WorkspaceElem) {
- return ((WorkspaceElem) parentElement).getChildren();
- }
- return null;
- }
-
- public Object getParent(Object element) {
- // TODO register repo elem in distribution elem?
- return null;
- }
-
- public boolean hasChildren(Object element) {
- if (element instanceof DistParentElem) {
- return true;
- } else if (element instanceof WorkspaceElem) {
- return false;
- }
- return false;
- }
-
- public void dispose() {
- for (RepoElem repoElem : repositories)
- repoElem.dispose();
- repositories = new ArrayList<RepoElem>();
- JcrUtils.logoutQuietly(nodeSession);
- }
-
- private void initializeModel(Session nodeSession) {
- try {
-
- Node homeNode = UserJcrUtils.getUserHome(nodeSession);
- if (homeNode == null) // anonymous
- throw new SlcException("User must be authenticated.");
-
- // make sure base directory is available
- Node repos = JcrUtils.mkdirs(nodeSession, homeNode.getPath()
- + RepoConstants.REPOSITORIES_BASE_PATH);
- nodeSession.save();
-
- // register default local java repository
- String alias = RepoConstants.DEFAULT_JAVA_REPOSITORY_ALIAS;
- Repository javaRepository = ArgeoJcrUtils.getRepositoryByAlias(
- repositoryFactory, alias);
- if (javaRepository != null) {
- if (!repos.hasNode(alias)) {
- Node repoNode = repos.addNode(alias,
- ArgeoTypes.ARGEO_REMOTE_REPOSITORY);
- repoNode.setProperty(ArgeoNames.ARGEO_URI, "vm:///" + alias);
- repoNode.addMixin(NodeType.MIX_TITLE);
- repoNode.setProperty(Property.JCR_TITLE,
- RepoConstants.DEFAULT_JAVA_REPOSITORY_LABEL);
- nodeSession.save();
- }
- }
- } catch (RepositoryException e) {
- throw new SlcException("Cannot initialize model", e);
- }
- }
-
- /*
- * DEPENDENCY INJECTION
- */
- public void setRepositoryFactory(RepositoryFactory repositoryFactory) {
- this.repositoryFactory = repositoryFactory;
- }
-
- public void setKeyring(Keyring keyring) {
- this.keyring = keyring;
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.argeo.slc.client.ui.dist.providers;
-
-import org.argeo.slc.client.ui.dist.DistImages;
-import org.argeo.slc.client.ui.dist.model.DistParentElem;
-import org.argeo.slc.client.ui.dist.model.GroupElem;
-import org.argeo.slc.client.ui.dist.model.RepoElem;
-import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Manages icons and labels for the distributions browser
- */
-public class DistTreeLabelProvider extends ColumnLabelProvider {
- @Override
- public String getText(Object element) {
- if (element instanceof DistParentElem)
- return ((DistParentElem) element).getLabel();
- else
- return element.toString();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof DistParentElem) {
- DistParentElem bElement = (DistParentElem) element;
- if (bElement instanceof RepoElem) {
- if (bElement.inHome())
- return DistImages.IMG_HOME_REPO;
- else if (bElement.isReadOnly())
- return DistImages.IMG_REPO_READONLY;
- else
- return DistImages.IMG_REPO;
-
- } else if (bElement instanceof GroupElem) {
- return DistImages.IMG_WKSP;
- }
- } else if (element instanceof WorkspaceElem)
- if (((WorkspaceElem) element).isReadOnly())
- return DistImages.IMG_DISTGRP_READONLY;
- else
- return DistImages.IMG_DISTGRP;
-
- return null;
- }
-}
\ 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.slc.client.ui.dist.views;
+
+import org.argeo.jcr.ArgeoNames;
+import org.argeo.slc.client.ui.dist.DistConstants;
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.controllers.DistTreeComparator;
+import org.argeo.slc.client.ui.dist.controllers.DistTreeDoubleClickListener;
+import org.argeo.slc.client.ui.dist.controllers.DistTreeLabelProvider;
+import org.argeo.slc.jcr.SlcNames;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.TreeViewerColumn;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * Browse, manipulate and manage distributions accross multiple repositories
+ * (like fetch, merge, publish, etc.).
+ */
+public class AnonymousDistributionsView extends ViewPart implements SlcNames,
+ ArgeoNames {
+ // private final static Log log = LogFactory
+ // .getLog(AnonymousDistributionsView.class);
+ public final static String ID = DistPlugin.ID + ".anonymousDistributionsView";
+
+ /* DEPENDENCY INJECTION */
+ private ITreeContentProvider treeContentProvider;
+
+ // This view widgets
+ private TreeViewer viewer;
+
+ @Override
+ public void createPartControl(Composite parent) {
+ // Define the TableViewer
+ viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL
+ | SWT.FULL_SELECTION | SWT.BORDER);
+
+ TreeViewerColumn col = new TreeViewerColumn(viewer, SWT.NONE);
+ col.getColumn().setWidth(400);
+ col.setLabelProvider(new DistTreeLabelProvider());
+
+ final Tree tree = viewer.getTree();
+ tree.setHeaderVisible(false);
+ tree.setLinesVisible(false);
+
+ // viewer.setContentProvider(new DistTreeContentProvider());
+ viewer.setContentProvider(treeContentProvider);
+ viewer.addDoubleClickListener(new DistTreeDoubleClickListener());
+ viewer.setComparator(new DistTreeComparator());
+
+ // Initialize
+ refresh();
+ }
+
+ /**
+ * Force refresh of the whole view
+ */
+ public void refresh() {
+ viewer.setInput(DistConstants.DEFAULT_PUBLIC_REPOSITORY_URI);
+ viewer.expandToLevel(2);
+ }
+
+ @Override
+ public void setFocus() {
+ viewer.getTree().setFocus();
+ }
+
+ /*
+ * DEPENDENCY INJECTION
+ */
+ public void setTreeContentProvider(ITreeContentProvider treeContentProvider) {
+ this.treeContentProvider = treeContentProvider;
+ }
+}
\ No newline at end of file
import javax.jcr.Node;
import javax.jcr.Property;
-import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
-import javax.jcr.Value;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.argeo.ArgeoException;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.client.ui.dist.DistConstants;
import org.argeo.slc.client.ui.dist.DistImages;
import org.argeo.slc.client.ui.dist.DistPlugin;
-import org.argeo.slc.client.ui.dist.providers.ArtifactsTreeContentProvider;
+import org.argeo.slc.client.ui.dist.controllers.ArtifactsTreeContentProvider;
import org.argeo.slc.client.ui.dist.utils.GenericDoubleClickListener;
import org.argeo.slc.jcr.SlcTypes;
import org.argeo.slc.repo.RepoConstants;
public class ArtifactsBrowser extends ViewPart implements DistConstants,
RepoConstants {
- private final static Log log = LogFactory.getLog(ArtifactsBrowser.class);
+ // private final static Log log = LogFactory.getLog(ArtifactsBrowser.class);
public final static String ID = DistPlugin.ID + ".artifactsBrowser";
/* DEPENDENCY INJECTION */
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);
- }
- }
+ // 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);
+ // }
+ // }
}
private class ArtifactTreeSelectionListener implements
import java.util.HashMap;
import java.util.Map;
-import javax.jcr.Credentials;
-import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoMonitor;
-import org.argeo.eclipse.ui.EclipseArgeoMonitor;
-import org.argeo.eclipse.ui.ErrorFeedback;
+
import org.argeo.eclipse.ui.TreeParent;
import org.argeo.jcr.ArgeoNames;
-import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
import org.argeo.slc.client.ui.dist.DistPlugin;
import org.argeo.slc.client.ui.dist.commands.CopyWorkspace;
import org.argeo.slc.client.ui.dist.commands.CreateWorkspace;
import org.argeo.slc.client.ui.dist.commands.DeleteWorkspace;
import org.argeo.slc.client.ui.dist.commands.DisplayRepoInformation;
import org.argeo.slc.client.ui.dist.commands.Fetch;
+import org.argeo.slc.client.ui.dist.commands.MergeWorkspaces;
import org.argeo.slc.client.ui.dist.commands.NormalizeDistribution;
import org.argeo.slc.client.ui.dist.commands.PublishWorkspace;
+import org.argeo.slc.client.ui.dist.commands.RefreshDistributionsView;
import org.argeo.slc.client.ui.dist.commands.RegisterRepository;
import org.argeo.slc.client.ui.dist.commands.UnregisterRemoteRepo;
-import org.argeo.slc.client.ui.dist.editors.DistributionEditor;
-import org.argeo.slc.client.ui.dist.editors.DistributionEditorInput;
+import org.argeo.slc.client.ui.dist.controllers.DistTreeComparator;
+import org.argeo.slc.client.ui.dist.controllers.DistTreeContentProvider;
+import org.argeo.slc.client.ui.dist.controllers.DistTreeDoubleClickListener;
+import org.argeo.slc.client.ui.dist.controllers.DistTreeLabelProvider;
import org.argeo.slc.client.ui.dist.model.DistParentElem;
import org.argeo.slc.client.ui.dist.model.GroupElem;
import org.argeo.slc.client.ui.dist.model.RepoElem;
import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
-import org.argeo.slc.client.ui.dist.providers.DistTreeContentProvider;
-import org.argeo.slc.client.ui.dist.providers.DistTreeLabelProvider;
-import org.argeo.slc.client.ui.dist.utils.ArtifactNamesComparator;
import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
import org.argeo.slc.jcr.SlcNames;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.MessageDialog;
-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.jface.viewers.TreeViewerColumn;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.ViewPart;
/**
* (like fetch, merge, publish, etc.).
*/
public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames {
- private final static Log log = LogFactory.getLog(DistributionsView.class);
+ // private final static Log log =
+ // LogFactory.getLog(DistributionsView.class);
public final static String ID = DistPlugin.ID + ".distributionsView";
/* DEPENDENCY INJECTION */
// viewer.setContentProvider(new DistTreeContentProvider());
viewer.setContentProvider(treeContentProvider);
- viewer.addDoubleClickListener(new DistributionsDCL());
- viewer.setComparator(new BrowserElementComparator());
+ viewer.addDoubleClickListener(new DistTreeDoubleClickListener());
+ viewer.setComparator(new DistTreeComparator());
// Enable selection retrieving from outside the view
getSite().setSelectionProvider(viewer);
protected void contextMenuAboutToShow(IMenuManager menuManager) {
IWorkbenchWindow window = DistPlugin.getDefault().getWorkbench()
.getActiveWorkbenchWindow();
- // Most of the implemented commands support only one selected
- // element
- boolean singleElement = ((IStructuredSelection) viewer.getSelection())
- .size() == 1;
- // Get Current selected item :
- Object firstElement = ((IStructuredSelection) viewer.getSelection())
- .getFirstElement();
-
- if (firstElement instanceof TreeParent
- || firstElement instanceof DistParentElem) {
- String targetRepoPath = null;
-
- // Build conditions depending on element type
- boolean isDistribElem = false, isRepoElem = false, isDistribGroupElem = false;
- boolean isHomeRepo = false, isReadOnly = true;
-
- if (firstElement instanceof WorkspaceElem) {
- WorkspaceElem de = (WorkspaceElem) firstElement;
- isDistribElem = true;
- isReadOnly = de.isReadOnly();
- } else if (firstElement instanceof RepoElem) {
- RepoElem re = (RepoElem) firstElement;
- isRepoElem = true;
- targetRepoPath = re.getRepoPath();
- isHomeRepo = re.inHome();
- isReadOnly = re.isReadOnly();
- } else if (firstElement instanceof GroupElem) {
- GroupElem dge = (GroupElem) firstElement;
- isReadOnly = dge.isReadOnly();
- isDistribGroupElem = true;
- }
- // Display repo info
- CommandHelpers.refreshCommand(menuManager, window,
- DisplayRepoInformation.ID,
- DisplayRepoInformation.DEFAULT_LABEL,
- DisplayRepoInformation.DEFAULT_ICON_PATH, isRepoElem
- && singleElement);
-
- // create workspace
- CommandHelpers.refreshCommand(menuManager, window,
- CreateWorkspace.ID, CreateWorkspace.DEFAULT_LABEL,
- CreateWorkspace.DEFAULT_ICON_PATH,
- (isRepoElem || isDistribGroupElem) && singleElement
- && !isReadOnly);
- // publish workspace
- CommandHelpers.refreshCommand(menuManager, window,
- PublishWorkspace.ID, PublishWorkspace.DEFAULT_LABEL,
- PublishWorkspace.DEFAULT_ICON_PATH, isDistribElem
- && singleElement && !isReadOnly);
-
- // Register a remote repository
- CommandHelpers.refreshCommand(menuManager, window,
- RegisterRepository.ID, RegisterRepository.DEFAULT_LABEL,
- RegisterRepository.DEFAULT_ICON_PATH, isRepoElem
- && singleElement);
-
- // Unregister a remote repository
- Map<String, String> params = new HashMap<String, String>();
- params.put(UnregisterRemoteRepo.PARAM_REPO_PATH, targetRepoPath);
- CommandHelpers.refreshParameterizedCommand(menuManager, window,
- UnregisterRemoteRepo.ID,
- UnregisterRemoteRepo.DEFAULT_LABEL,
- UnregisterRemoteRepo.DEFAULT_ICON_PATH, isRepoElem
- && !isHomeRepo && singleElement, params);
-
- // Fetch repository
- params = new HashMap<String, String>();
- params.put(Fetch.PARAM_TARGET_REPO, targetRepoPath);
- CommandHelpers.refreshParameterizedCommand(menuManager, window,
- Fetch.ID, Fetch.DEFAULT_LABEL, Fetch.DEFAULT_ICON_PATH,
- isRepoElem && singleElement && !isReadOnly, params);
-
- // Normalize workspace
- CommandHelpers.refreshCommand(menuManager, window,
- NormalizeDistribution.ID,
- NormalizeDistribution.DEFAULT_LABEL,
- NormalizeDistribution.DEFAULT_ICON_PATH, isDistribElem
- && singleElement && !isReadOnly);
-
- // Copy workspace
- CommandHelpers.refreshCommand(menuManager, window,
- CopyWorkspace.ID, CopyWorkspace.DEFAULT_LABEL,
- CopyWorkspace.DEFAULT_ICON_PATH, isDistribElem
- && singleElement);
-
- // Clear Workspace
- CommandHelpers.refreshCommand(menuManager, window,
- DeleteWorkspace.ID, DeleteWorkspace.DEFAULT_LABEL,
- DeleteWorkspace.DEFAULT_ICON_PATH, isDistribElem
- && singleElement && !isReadOnly);
-
- // // Manage workspace authorizations
- // params = new HashMap<String, String>();
- // params.put(ManageWorkspaceAuth.PARAM_WORKSPACE_NAME, wsName);
- // CommandHelpers.refreshParameterizedCommand(menuManager, window,
- // ManageWorkspaceAuth.ID, ManageWorkspaceAuth.DEFAULT_LABEL,
- // ManageWorkspaceAuth.DEFAULT_ICON_PATH, isDistribElem
- // && singleElement && !isReadOnly, params);
- }
- // } catch (RepositoryException e) {
- // throw new SlcException("unexpected errror while "
- // + "building context menu", e);
- // }
- }
+ try {
+ // Most of the implemented commands support only one selected
+ // element
+ boolean singleElement = ((IStructuredSelection) viewer
+ .getSelection()).size() == 1;
+ // Get Current selected item :
+ Object firstElement = ((IStructuredSelection) viewer.getSelection())
+ .getFirstElement();
- /**
- * Exposes some Repository and workspace information about the selected
- * element without exposing the UI model
- */
- public class DistributionViewSelectedElement {
- public boolean isRepository = false;
- public boolean isWorkspaceGroup = false;
- public boolean isWorkspace = false;
- public boolean isReadOnly = false;
- public String repositoryDescription;
- public Node repoNode;
- public String wkspName;
- public String wkspPrefix;
- public Repository repository;
- public Credentials credentials;
- }
+ if (firstElement instanceof TreeParent
+ || firstElement instanceof DistParentElem) {
+
+ String targetRepoPath = null, workspaceName = null, workspacePrefix = null;
+ // String targetRepoUri = null;
+ // Build conditions depending on element type
+ boolean isDistribElem = false, isRepoElem = false, isDistribGroupElem = false;
+ boolean isHomeRepo = false, isReadOnly = true;
+
+ RepoElem re = null;
+
+ if (firstElement instanceof WorkspaceElem) {
+ WorkspaceElem de = (WorkspaceElem) firstElement;
+ re = de.getRepoElem();
+ isDistribElem = true;
+ isReadOnly = de.isReadOnly();
+ workspaceName = de.getWorkspaceName();
+ } else if (firstElement instanceof RepoElem) {
+ re = (RepoElem) firstElement;
+ isRepoElem = true;
+ isHomeRepo = re.inHome();
+ isReadOnly = re.isReadOnly();
+ } else if (firstElement instanceof GroupElem) {
+ GroupElem dge = (GroupElem) firstElement;
+ isReadOnly = dge.isReadOnly();
+ isDistribGroupElem = true;
+ re = dge.getRepoElem();
+ workspacePrefix = dge.getLabel();
+ }
- /**
- * Returns a {@see DistributionViewSelectedElement} if one and only one
- * valid element is currently selected.
- *
- */
- public DistributionViewSelectedElement getSelectedElement() {
-
- IStructuredSelection iss = (IStructuredSelection) viewer.getSelection();
- if (iss.isEmpty() || iss.size() > 1)
- return null;
-
- DistributionViewSelectedElement dvse = new DistributionViewSelectedElement();
- Object obj = iss.getFirstElement();
- if (obj instanceof RepoElem) {
- RepoElem re = (RepoElem) obj;
- dvse.isRepository = true;
- dvse.isReadOnly = re.isReadOnly();
- dvse.repository = re.getRepository();
- dvse.repoNode = re.getRepoNode();
- dvse.credentials = re.getCredentials();
- dvse.repositoryDescription = getRepositoryDescription(re);
- } else if (obj instanceof GroupElem) {
- GroupElem dge = (GroupElem) obj;
- dvse.isWorkspaceGroup = true;
- dvse.isReadOnly = dge.isReadOnly();
- dvse.repository = dge.getRepoElem().getRepository();
- dvse.repoNode = dge.getRepoElem().getRepoNode();
- dvse.credentials = dge.getRepoElem().getCredentials();
- dvse.wkspPrefix = dge.getLabel();
- dvse.repositoryDescription = getRepositoryDescription(dge
- .getRepoElem());
- } else if (obj instanceof WorkspaceElem) {
- WorkspaceElem de = (WorkspaceElem) obj;
- dvse.isWorkspace = true;
- dvse.isReadOnly = de.isReadOnly();
- dvse.repository = de.getRepoElem().getRepository();
- dvse.repoNode = de.getRepoElem().getRepoNode();
- dvse.credentials = de.getRepoElem().getCredentials();
- dvse.wkspName = de.getWorkspaceName();
- dvse.repositoryDescription = getRepositoryDescription(de
- .getRepoElem());
- }
- return dvse;
- }
+ if (re != null) {
+ // targetRepoUri = re.getUri();
+ targetRepoPath = re.getRepoNode().getPath();
+ }
- private String getRepositoryDescription(RepoElem repo) {
- StringBuffer repoDesc = new StringBuffer();
- repoDesc.append(repo.getLabel());
- repoDesc.append(" (");
- repoDesc.append(JcrUtils.get(repo.getRepoNode(), ARGEO_URI));
- repoDesc.append(")");
- return repoDesc.toString();
+ // Display repo info
+ CommandHelpers.refreshCommand(menuManager, window,
+ DisplayRepoInformation.ID,
+ DisplayRepoInformation.DEFAULT_LABEL,
+ DisplayRepoInformation.DEFAULT_ICON_PATH, isRepoElem
+ && singleElement);
+
+ // create workspace
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(CreateWorkspace.PARAM_TARGET_REPO_PATH,
+ targetRepoPath);
+ params.put(CreateWorkspace.PARAM_WORKSPACE_PREFIX,
+ workspacePrefix);
+ CommandHelpers.refreshParameterizedCommand(menuManager, window,
+ CreateWorkspace.ID, CreateWorkspace.DEFAULT_LABEL,
+ CreateWorkspace.DEFAULT_ICON_PATH,
+ (isRepoElem || isDistribGroupElem) && singleElement
+ && !isReadOnly, params);
+
+ // publish workspace
+ params = new HashMap<String, String>();
+ params.put(PublishWorkspace.PARAM_TARGET_REPO_PATH,
+ targetRepoPath);
+ params.put(PublishWorkspace.PARAM_WORKSPACE_NAME, workspaceName);
+ CommandHelpers.refreshParameterizedCommand(menuManager, window,
+ PublishWorkspace.ID, PublishWorkspace.DEFAULT_LABEL,
+ PublishWorkspace.DEFAULT_ICON_PATH, isDistribElem
+ && singleElement && !isReadOnly, params);
+
+ // Register a remote repository
+ CommandHelpers.refreshCommand(menuManager, window,
+ RegisterRepository.ID,
+ RegisterRepository.DEFAULT_LABEL,
+ RegisterRepository.DEFAULT_ICON_PATH, isRepoElem
+ && singleElement);
+
+ // Unregister a remote repository
+ params = new HashMap<String, String>();
+ params.put(UnregisterRemoteRepo.PARAM_REPO_PATH, targetRepoPath);
+ CommandHelpers.refreshParameterizedCommand(menuManager, window,
+ UnregisterRemoteRepo.ID,
+ UnregisterRemoteRepo.DEFAULT_LABEL,
+ UnregisterRemoteRepo.DEFAULT_ICON_PATH, isRepoElem
+ && !isHomeRepo && singleElement, params);
+
+ // Fetch repository
+ params = new HashMap<String, String>();
+ params.put(Fetch.PARAM_TARGET_REPO_PATH, targetRepoPath);
+ CommandHelpers.refreshParameterizedCommand(menuManager, window,
+ Fetch.ID, Fetch.DEFAULT_LABEL, Fetch.DEFAULT_ICON_PATH,
+ isRepoElem && singleElement && !isReadOnly, params);
+
+ // Normalize workspace
+ params = new HashMap<String, String>();
+ params.put(NormalizeDistribution.PARAM_TARGET_REPO_PATH,
+ targetRepoPath);
+ params.put(NormalizeDistribution.PARAM_WORKSPACE_NAME,
+ workspaceName);
+ CommandHelpers.refreshParameterizedCommand(menuManager, window,
+ NormalizeDistribution.ID,
+ NormalizeDistribution.DEFAULT_LABEL,
+ NormalizeDistribution.DEFAULT_ICON_PATH, isDistribElem
+ && singleElement && !isReadOnly, params);
+
+ // Copy workspace
+ params = new HashMap<String, String>();
+ params.put(CopyWorkspace.PARAM_TARGET_REPO_PATH, targetRepoPath);
+ params.put(CopyWorkspace.PARAM_SOURCE_WORKSPACE_NAME,
+ workspaceName);
+ CommandHelpers.refreshParameterizedCommand(menuManager, window,
+ CopyWorkspace.ID, CopyWorkspace.DEFAULT_LABEL,
+ CopyWorkspace.DEFAULT_ICON_PATH, isDistribElem
+ && singleElement, params);
+
+ // Clear Workspace
+ params = new HashMap<String, String>();
+ params.put(DeleteWorkspace.PARAM_TARGET_REPO_PATH,
+ targetRepoPath);
+ params.put(DeleteWorkspace.PARAM_WORKSPACE_NAME, workspaceName);
+ CommandHelpers.refreshParameterizedCommand(menuManager, window,
+ DeleteWorkspace.ID, DeleteWorkspace.DEFAULT_LABEL,
+ DeleteWorkspace.DEFAULT_ICON_PATH, isDistribElem
+ && singleElement && !isReadOnly, params);
+
+ // // Manage workspace authorizations
+ // params = new HashMap<String, String>();
+ // params.put(ManageWorkspaceAuth.PARAM_WORKSPACE_NAME, wsName);
+ // CommandHelpers.refreshParameterizedCommand(menuManager,
+ // window,
+ // ManageWorkspaceAuth.ID, ManageWorkspaceAuth.DEFAULT_LABEL,
+ // ManageWorkspaceAuth.DEFAULT_ICON_PATH, isDistribElem
+ // && singleElement && !isReadOnly, params);
+ }
+ } catch (RepositoryException e) {
+ throw new SlcException("unexpected errror while "
+ + "building context menu", e);
+ }
}
@Override
viewer.expandToLevel(2);
}
- /** Add some view specific behaviours to the comparator */
- private class BrowserElementComparator extends ArtifactNamesComparator {
- @Override
- public int category(Object element) {
- // Home repository always first
- if (element instanceof RepoElem && ((RepoElem) element).inHome())
- return 2;
- else
- return super.category(element);
- }
-
- @Override
- public int compare(Viewer viewer, Object e1, Object e2) {
- // reverse order for versions
- if (e1 instanceof WorkspaceElem)
- return -super.compare(viewer, e1, e2);
- else
- return super.compare(viewer, e1, e2);
- }
- }
-
- /** Abstract class to simplify UI conditions build */
-
- /** A software repository */
-
/** Listens to drag */
class ViewDragListener extends DragSourceAdapter {
public void dragSetData(DragSourceEvent event) {
if (selection.getFirstElement() instanceof WorkspaceElem) {
WorkspaceElem de = (WorkspaceElem) selection.getFirstElement();
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
- event.data = de.getWorkspacePath();
+ event.data = de.getRepoElem().getUri() + "/"
+ + de.getWorkspaceName();
}
}
}
RepoElem targetRepo = (RepoElem) getCurrentTarget();
Boolean ok = MessageDialog.openConfirm(getSite().getShell(),
- "FIXME: BROKEN BY REFACTORING--Confirm distribution merge",
- "Do you want to merge " + sourceDist.getWorkspaceName()
- + " (from repo "
+ "Confirm distribution merge", "Do you want to merge "
+ + sourceDist.getWorkspaceName() + " (from repo "
+ sourceDist.getRepoElem().getLabel()
+ ") to repo " + targetRepo.getLabel() + "?");
if (!ok)
return false;
- // TODO uncomment that
- return true;
- // try {
- // String sourceWorkspace = sourceDist.getWorkspaceName();
- // Repository sourceRepository = RepoUtils.getRepository(
- // repositoryFactory, keyring, sourceDist
- // .getWorkspaceNode().getParent());
- // Credentials sourceCredentials = RepoUtils
- // .getRepositoryCredentials(keyring, sourceDist
- // .getWorkspaceNode().getParent());
- //
- // String targetWorkspace = sourceWorkspace;
- // Repository targetRepository = RepoUtils.getRepository(
- // repositoryFactory, keyring, targetRepo.getRepoNode());
- // Credentials targetCredentials = RepoUtils
- // .getRepositoryCredentials(keyring,
- // targetRepo.getRepoNode());
- //
- // // Open sessions here since the background thread
- // // won't necessarily be authenticated.
- // // Job should close the sessions.
- // Session sourceSession = sourceRepository.login(
- // sourceCredentials, sourceWorkspace);
- // Session targetSession;
- // try {
- // targetSession = targetRepository.login(targetCredentials,
- // targetWorkspace);
- // } catch (NoSuchWorkspaceException e) {
- // Session defaultSession = targetRepository
- // .login(targetCredentials);
- // try {
- // defaultSession.getWorkspace().createWorkspace(
- // targetWorkspace);
- // } catch (Exception e1) {
- // throw new SlcException("Cannot create new workspace "
- // + targetWorkspace, e);
- // } finally {
- // JcrUtils.logoutQuietly(defaultSession);
- // }
- // targetSession = targetRepository.login(targetCredentials,
- // targetWorkspace);
- // }
- //
- // Job workspaceMergeJob = new WorkspaceMergeJob(sourceSession,
- // targetSession);
- // workspaceMergeJob.setUser(true);
- // workspaceMergeJob.schedule();
- // return true;
- // } catch (RepositoryException e) {
- // throw new SlcException("Cannot process drop from " + sourceDist
- // + " to " + targetRepo, e);
- // }
+ try {
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(MergeWorkspaces.PARAM_TARGET_REPO_PATH, targetRepo
+ .getRepoNode().getPath());
+ params.put(MergeWorkspaces.PARAM_SOURCE_REPO_PATH, sourceDist
+ .getRepoElem().getRepoNode().getPath());
+ params.put(MergeWorkspaces.PARAM_SOURCE_WORKSPACE_NAME,
+ sourceDist.getWorkspaceName());
+ CommandHelpers.callCommand(RefreshDistributionsView.ID, params);
+ return true;
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot process drop from " + sourceDist
+ + " to " + targetRepo, e);
+ }
}
@Override
if (target instanceof RepoElem) {
if (getSelectedObject() instanceof WorkspaceElem) {
// check if not same repository
- String srcRepoPath = ((WorkspaceElem) getSelectedObject())
- .getRepoPath();
- String targetRepoPath = ((RepoElem) target).getRepoPath();
- return !targetRepoPath.equals(srcRepoPath);
+ String srcRepoUri = ((WorkspaceElem) getSelectedObject())
+ .getRepoElem().getUri();
+ String targetRepoUri = ((RepoElem) target).getUri();
+ return !targetRepoUri.equals(srcRepoUri);
}
}
return false;
}
}
- private static class WorkspaceMergeJob extends Job {
- private Session sourceSession;
- private Session targetSession;
-
- public WorkspaceMergeJob(Session sourceSession, Session targetSession) {
- super("Workspace merge");
- this.sourceSession = sourceSession;
- this.targetSession = targetSession;
- }
-
- @Override
- protected IStatus run(IProgressMonitor eclipseMonitor) {
- long begin = System.currentTimeMillis();
- try {
- Query countQuery = sourceSession
- .getWorkspace()
- .getQueryManager()
- .createQuery("select file from [nt:file] as file",
- Query.JCR_SQL2);
- QueryResult result = countQuery.execute();
- Long expectedCount = result.getNodes().getSize();
- if (log.isDebugEnabled())
- log.debug("Will copy " + expectedCount + " files...");
-
- ArgeoMonitor monitor = new EclipseArgeoMonitor(eclipseMonitor);
- eclipseMonitor
- .beginTask("Copy files", expectedCount.intValue());
-
- Long count = JcrUtils.copyFiles(sourceSession.getRootNode(),
- targetSession.getRootNode(), true, monitor);
-
- monitor.done();
- long duration = (System.currentTimeMillis() - begin) / 1000;// in
- // s
- if (log.isDebugEnabled())
- log.debug("Copied " + count + " files in "
- + (duration / 60) + "min " + (duration % 60) + "s");
-
- return Status.OK_STATUS;
- } catch (RepositoryException e) {
- return new Status(IStatus.ERROR, DistPlugin.ID, "Cannot merge",
- e);
- } finally {
- JcrUtils.logoutQuietly(sourceSession);
- JcrUtils.logoutQuietly(targetSession);
- }
- }
- }
-
- /** Listen to double-clicks */
- private class DistributionsDCL implements IDoubleClickListener {
-
- public void doubleClick(DoubleClickEvent event) {
- if (event.getSelection() == null || event.getSelection().isEmpty())
- return;
- Object obj = ((IStructuredSelection) event.getSelection())
- .getFirstElement();
- if (obj instanceof WorkspaceElem) {
- WorkspaceElem distributionElem = (WorkspaceElem) obj;
- DistributionEditorInput dei = new DistributionEditorInput(
- distributionElem.getName(),
- getRepositoryDescription(distributionElem.getRepoElem()),
- distributionElem.getRepoElem().getRepository(),
- distributionElem.getWorkspaceName(), distributionElem
- .getCredentials());
- try {
- DistPlugin.getDefault().getWorkbench()
- .getActiveWorkbenchWindow().getActivePage()
- .openEditor(dei, DistributionEditor.ID);
- } catch (PartInitException e) {
- ErrorFeedback.show("Cannot open editor for "
- + distributionElem.getWorkspaceName(), e);
- }
- }
- }
- }
-
/*
* DEPENDENCY INJECTION
*/
--- /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.slc.client.ui.dist.views;
+
+import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.browser.Browser;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ *
+ * Displays some info about the distribution
+ *
+ */
+public class HelpView extends ViewPart {
+ public final static String ID = DistPlugin.ID + ".helpView";
+
+ @Override
+ public void createPartControl(Composite parent) {
+ parent.setLayout(new GridLayout(2, false));
+ Browser browser = new Browser(parent, SWT.NONE);
+ browser.setUrl("http://www.argeo.org");
+ browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ }
+
+ /**
+ * Force refresh of the whole view
+ */
+ public void refresh() {
+ }
+
+ @Override
+ public void setFocus() {
+ }
+
+}
\ No newline at end of file
import java.util.Hashtable;
import javax.jcr.Node;
+import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.Repository;
import javax.jcr.RepositoryFactory;
import javax.jcr.SimpleCredentials;
import javax.jcr.nodetype.NodeType;
-import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.ErrorFeedback;
import org.argeo.jcr.ArgeoJcrConstants;
import org.argeo.jcr.ArgeoJcrUtils;
Node repos = nodeSession.getNode(reposPath);
String repoNodeName = JcrUtils.replaceInvalidChars(name.getText());
if (repos.hasNode(repoNodeName))
- throw new ArgeoException(
+ throw new SlcException(
"There is already a remote repository named "
+ repoNodeName);
+
+ // check if the same URI has already been registered
+ NodeIterator ni = repos.getNodes();
+ while (ni.hasNext()) {
+ Node node = ni.nextNode();
+ if (node.isNodeType(ArgeoTypes.ARGEO_REMOTE_REPOSITORY)
+ && node.hasProperty(ArgeoNames.ARGEO_URI)
+ && node.getProperty(ArgeoNames.ARGEO_URI).getString()
+ .equals(uri.getText()))
+ throw new SlcException(
+ "This URI "
+ + uri.getText()
+ + " is already registered, "
+ + "for the time being, only one instance of a single "
+ + "repository at a time is implemented.");
+ }
+
Node repoNode = repos.addNode(repoNodeName,
ArgeoTypes.ARGEO_REMOTE_REPOSITORY);
repoNode.setProperty(ArgeoNames.ARGEO_URI, uri.getText());
import javax.jcr.observation.EventListener;\r
import javax.jcr.observation.ObservationManager;\r
\r
-import org.apache.commons.logging.Log;\r
-import org.apache.commons.logging.LogFactory;\r
import org.argeo.ArgeoException;\r
import org.argeo.eclipse.ui.jcr.AsyncUiEventListener;\r
import org.argeo.eclipse.ui.utils.CommandUtils;\r
private final static DateFormat dateFormat = new SimpleDateFormat(\r
SlcUiConstants.DEFAULT_DISPLAY_DATE_TIME_FORMAT);\r
\r
- private final static Log log = LogFactory.getLog(JcrResultTreeView.class);\r
+ // private final static Log log =\r
+ // LogFactory.getLog(JcrResultTreeView.class);\r
\r
/* DEPENDENCY INJECTION */\r
private Session session;\r
ResultParentUtils.updatePassedStatus(\r
session.getNode(JcrUtils.parentPath(sourcePath)),\r
true);\r
- Node target = session.getNode(destPath);\r
+ // Node target = session.getNode(destPath);\r
session.save();\r
return true;\r
}\r