<property name="workspace" value="org.argeo.tp-1.3.1" />
</bean>
- <bean id="normalizeDistribution"
- class="org.argeo.slc.client.ui.dist.commands.NormalizeDistribution"
- scope="prototype">
- <property name="repository" ref="javaRepository" />
- </bean>
<bean id="fetch" class="org.argeo.slc.client.ui.dist.commands.Fetch"
scope="prototype">
<property name="repositoryFactory" ref="repositoryFactory" />
<property name="nodeRepository" ref="nodeRepository" />
</bean>
- <bean id="copyWorkspace" class="org.argeo.slc.client.ui.dist.commands.CopyWorkspace"
- scope="prototype">
- <property name="repository" ref="javaRepository" />
- </bean>
<bean id="manageWorkspaceAuth"
class="org.argeo.slc.client.ui.dist.commands.ManageWorkspaceAuth"
scope="prototype">
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="Remote Repo path">
</commandParameter>
</command>
-
<command
id="org.argeo.slc.client.ui.dist.runInOSGi"
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
id="workspace"
name="Workspace Name">
</commandParameter>
- </command>
- <command
- id="org.argeo.slc.client.ui.dist.normalizeDistribution"
- defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
- name="Normalize Distribution">
- <commandParameter
- id="workspace"
- name="Workspace Name">
- </commandParameter>
</command>
<command
id="org.argeo.slc.client.ui.dist.registerRepository"
</command>
<!-- TO MANIPULATE WORKSPACES -->
- <command
- id="org.argeo.slc.client.ui.dist.copyWorkspace"
- defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
- name="Copy chosen Workspace">
- <commandParameter
- id="org.argeo.slc.client.ui.dist.workspaceName"
- name="Workspace Name">
- </commandParameter>
- </command>
<command
id="org.argeo.slc.client.ui.dist.manageWorkspaceAuth"
defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
*/
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.Session;
+import javax.jcr.security.Privilege;
-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.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.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;
/**
*/
public class CopyWorkspace extends AbstractHandler {
- private static final Log log = LogFactory.getLog(CopyWorkspace.class);
+ // private static final Log log = LogFactory.getLog(CopyWorkspace.class);
public final static String ID = DistPlugin.ID + ".copyWorkspace";
- public final static String PARAM_WORKSPACE_NAME = DistPlugin.ID
- + ".workspaceName";
public final static String DEFAULT_LABEL = "Duplicate";
public final static String DEFAULT_ICON_PATH = "icons/addItem.gif";
- /* DEPENDENCY INJECTION */
private Repository repository;
+ private Credentials credentials;
+ private String wkspName;
+ private String slcRole = "ROLE_SLC";
public Object execute(ExecutionEvent event) throws ExecutionException {
- String srcWorkspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
-
- if (log.isTraceEnabled())
- log.debug("WORKSPACE " + srcWorkspaceName + " About to be copied");
-
- // MessageDialog.openWarning(DistPlugin.getDefault()
- // .getWorkbench().getDisplay().getActiveShell(),
- // "WARNING", "Not yet implemented");
- // return null;
-
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 the current workspace",
+ "New copy of workspace " + wkspName,
"Choose a name for the workspace to create", "", null);
inputDialog.open();
String newWorkspaceName = inputDialog.getValue();
Session srcSession = null;
Session newSession = null;
try {
- srcSession = repository.login(srcWorkspaceName);
+ srcSession = repository.login(credentials, wkspName);
// Create the workspace
srcSession.getWorkspace().createWorkspace(newWorkspaceName);
Node srcRootNode = srcSession.getRootNode();
// log in the newly created workspace
- newSession = repository.login(newWorkspaceName);
- // newSession.save();
+ newSession = repository.login(credentials, newWorkspaceName);
Node newRootNode = newSession.getRootNode();
RepoUtils.copy(srcRootNode, newRootNode);
newSession.save();
-
+ JcrUtils.addPrivilege(newSession, "/", slcRole, Privilege.JCR_ALL);
CommandHelpers.callCommand(RefreshDistributionsView.ID);
} catch (RepositoryException re) {
throw new ArgeoException(
IWorkbenchWindow iww = DistPlugin.getDefault().getWorkbench()
.getActiveWorkbenchWindow();
-
IWorkbenchPart view = iww.getActivePage().getActivePart();
if (view instanceof DistributionsView) {
DistributionViewSelectedElement dvse = ((DistributionsView) view)
package org.argeo.slc.client.ui.dist.commands;
import javax.jcr.Binary;
+import javax.jcr.Credentials;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Property;
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.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;
/** Make sure than Maven and OSGi metadata are consistent */
public class NormalizeDistribution extends AbstractHandler implements SlcNames {
public final static String ID = DistPlugin.ID + ".normalizeDistribution";
- public final static String PARAM_WORKSPACE = "workspace";
public final static String DEFAULT_LABEL = "Normalize...";
public final static String DEFAULT_ICON_PATH = "icons/normalize.gif";
.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 {
- String workspace = event.getParameter(PARAM_WORKSPACE);
+
+ 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)
NormalizeJob job;
try {
- job = new NormalizeJob(repository.login(workspace), version,
- overridePoms);
+ job = new NormalizeJob(repository.login(credentials, wkspName),
+ version, overridePoms);
} catch (RepositoryException e) {
- throw new SlcException("Cannot normalize " + workspace, e);
+ throw new SlcException("Cannot normalize " + wkspName, e);
}
job.setUser(true);
job.schedule();
}
}
-}
+}
\ No newline at end of file
createField(details, "Symbolic name", SlcNames.SLC_SYMBOLIC_NAME);
createField(details, "Version", SlcNames.SLC_BUNDLE_VERSION);
createField(details, "Group Id", SlcNames.SLC_GROUP_ID);
- //createHyperlink(details, "Licence", DistConstants.SLC_BUNDLE_LICENCE);
+ // Single sourcing issue: this does not works with rap
+ // createHyperlink(details, "Licence",
+ // DistConstants.SLC_BUNDLE_LICENCE);
+ createField(details, "Licence", DistConstants.SLC_BUNDLE_LICENCE);
+
createField(details, "Vendor", DistConstants.SLC_BUNDLE_VENDOR);
}
import javax.jcr.query.qom.StaticOperand;
import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.ErrorFeedback;
+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.DistConstants;
import org.argeo.slc.client.ui.dist.DistImages;
import org.argeo.slc.client.ui.dist.DistPlugin;
import org.argeo.slc.client.ui.dist.utils.NodeViewerComparator;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
+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;
private Text artifactTxt;
private FormToolkit tk;
private Composite header;
-
- // private Section headerSection;
+ private final static String FILTER_HELP_MSG = "Enter filter criterion separated by a space";
public DistributionOverviewPage(FormEditor formEditor, String title,
Session session) {
this.session = session;
}
+ 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);
+ }
+
+ private class RefreshJob extends Job {
+ private Session session;
+ private List<Node> nodes;
+ private String filter;
+
+ public RefreshJob(Session session, String filter, List<Node> nodes) {
+ super("Get bundle list");
+ this.session = session;
+ }
+
+ @Override
+ protected IStatus run(IProgressMonitor progressMonitor) {
+ try {
+ ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor);
+ monitor.beginTask("Getting bundle list", -1);
+ List<Node> result = JcrUtils
+ .nodeIteratorToList(listBundleArtifacts(session, filter));
+ nodes.addAll(result);
+ } catch (Exception e) {
+ return new Status(IStatus.ERROR, DistPlugin.ID,
+ "Cannot get bundle list", e);
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
@Override
protected void createFormContent(IManagedForm managedForm) {
ScrolledForm form = managedForm.getForm();
createFilterPart(body);
// Add the table
createTableViewer(body);
-
- viewer.setInput(session);
- resetFilter();
-
+ viewer.setInput(null);
// Add a listener to enable custom resize process
form.addControlListener(new ControlListener() {
+ // form.addListener(SWT.RESIZE, new Listener() does not work
public void controlResized(ControlEvent e) {
refreshLayout();
}
public void controlMoved(ControlEvent e) {
}
});
-
- // This below doesn not work; the listener must be added as a control
- // listener to be correctly notified when resize events happen
-
- // form.addListener(SWT.RESIZE, new Listener() {
- // public void handleEvent(Event event) {
- // log.debug("Form resized ....");
- // }
- // });
-
+ asynchronousRefresh();
}
/** Build repository request */
- private NodeIterator listBundleArtifacts(Session session)
+ private NodeIterator listBundleArtifacts(Session session, String filter)
throws RepositoryException {
QueryManager queryManager = session.getWorkspace().getQueryManager();
QueryObjectModelFactory factory = queryManager.getQOMFactory();
"%.source"))));
// Build constraints based the textArea content
- String artifactTxtVal = artifactTxt.getText();
- if (!"".equals(artifactTxtVal.trim())) {
+ if (filter != null && !"".equals(filter.trim())) {
// Parse the String
- String[] strs = artifactTxtVal.trim().split(" ");
+ String[] strs = filter.trim().split(" ");
for (String token : strs) {
token = token.replace('*', '%');
StaticOperand so = factory.literal(session.getValueFactory()
// Text Area to filter
artifactTxt = tk.createText(header, "", SWT.BORDER | SWT.SINGLE);
+ artifactTxt.setMessage(FILTER_HELP_MSG);
gd = new GridData(SWT.FILL, SWT.FILL, false, false);
gd.grabExcessHorizontalSpace = true;
artifactTxt.setLayoutData(gd);
artifactTxt.addModifyListener(new ModifyListener() {
-
public void modifyText(ModifyEvent event) {
- refreshFilteredList();
+ if ("".equals(artifactTxt.getText().trim()))
+ asynchronousRefresh();
+ else
+ refreshFilteredList();
}
});
private void resetFilter() {
artifactTxt.setText("");
- artifactTxt.setMessage("Enter filter criterion separated by a space");
- viewer.refresh();
+ artifactTxt.setMessage(FILTER_HELP_MSG);
}
private void refreshFilteredList() {
- viewer.refresh();
+ List<Node> nodes;
+ try {
+ nodes = JcrUtils.nodeIteratorToList(listBundleArtifacts(session,
+ artifactTxt.getText()));
+ viewer.setInput(nodes);
+ } catch (RepositoryException e) {
+ throw new SlcException("Unable to list bundles", e);
+ }
}
private void createTableViewer(Composite parent) {
/** force refresh of the artifact list */
public void refresh() {
- viewer.refresh();
+ asynchronousRefresh();
}
/** Programmatically configure the context menu */
protected void contextMenuAboutToShow(IMenuManager menuManager) {
IWorkbenchWindow window = DistPlugin.getDefault().getWorkbench()
.getActiveWorkbenchWindow();
-
// Build conditions
-
// Delete selected artifacts
CommandHelpers.refreshCommand(menuManager, window, DeleteArtifacts.ID,
DeleteArtifacts.DEFAULT_LABEL,
DeleteArtifacts.DEFAULT_ICON_PATH, true);
-
}
private SelectionAdapter getSelectionAdapter(final int index) {
/* LOCAL CLASSES */
private class DistributionsContentProvider implements
IStructuredContentProvider {
- // private Session session;
+ // we keep a cache of the Nodes in the content provider to be able to
+ // manage long request
+ private List<Node> nodes;
public void dispose() {
}
+ // We expect a list of nodes as a new input
+ @SuppressWarnings("unchecked")
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // session = (Session) newInput;
+ nodes = (List<Node>) newInput;
}
public Object[] getElements(Object arg0) {
- try {
- List<Node> nodes = JcrUtils
- .nodeIteratorToList(listBundleArtifacts(session));
- return nodes.toArray();
- } catch (RepositoryException e) {
- ErrorFeedback.show("Cannot list bundles", e);
- return null;
- }
+ return nodes.toArray();
}
}
if (firstElement instanceof TreeParent
|| firstElement instanceof BrowserElem) {
- String wsName = null;
String targetRepoPath = null;
// Build conditions depending on element type
if (firstElement instanceof DistributionElem) {
DistributionElem de = (DistributionElem) firstElement;
isDistribElem = true;
- wsName = de.getName();
isReadOnly = de.isReadOnly();
} else if (firstElement instanceof RepoElem) {
RepoElem re = (RepoElem) firstElement;
isRepoElem && singleElement && !isReadOnly, params);
// Normalize workspace
- params = new HashMap<String, String>();
- params.put(NormalizeDistribution.PARAM_WORKSPACE, wsName);
- CommandHelpers.refreshParameterizedCommand(menuManager, window,
+ CommandHelpers.refreshCommand(menuManager, window,
NormalizeDistribution.ID,
NormalizeDistribution.DEFAULT_LABEL,
NormalizeDistribution.DEFAULT_ICON_PATH, isDistribElem
- && singleElement && !isReadOnly, params);
+ && singleElement && !isReadOnly);
// Copy workspace
- params = new HashMap<String, String>();
- params.put(CopyWorkspace.PARAM_WORKSPACE_NAME, wsName);
- CommandHelpers.refreshParameterizedCommand(menuManager, window,
+ CommandHelpers.refreshCommand(menuManager, window,
CopyWorkspace.ID, CopyWorkspace.DEFAULT_LABEL,
CopyWorkspace.DEFAULT_ICON_PATH, isDistribElem
- && singleElement, params);
+ && singleElement);
// Clear Workspace
CommandHelpers.refreshCommand(menuManager, window,