*/
public final static String DATE_TIME_FORMAT = "MM/dd/yyyy, HH:mm";
public final static String DATE_FORMAT = "MM/dd/yyyy";
- // this should be directly retrieved from JCR APIs
+ // this should be directly retrieved from JCR APIs once we have solved the
+ // problem of the translation of name space to shortcut, typically
+ // {http://www.jcp.org/jcr/1.0} to jcr:
public final static String JCR_IDENTIFIER = "jcr:uuid";
+ public final static String JCR_MIXIN_TYPES = "jcr:mixinTypes";
// FIXME: should be defined in SlcNames
public final static String SLC_BUNDLE_NAME = SlcNames.SLC_
+ Constants.BUNDLE_VENDOR;
public final String DEFAULT_PUBLIC_REPOSITORY_URI = "vm:///java";
+
}
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.ArgeoMonitor;
+import org.argeo.eclipse.ui.EclipseArgeoMonitor;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.SlcConstants;
import org.argeo.slc.client.ui.dist.DistPlugin;
+import org.argeo.slc.client.ui.dist.PrivilegedJob;
import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
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;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.handlers.HandlerUtil;
/**
*/
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 DEFAULT_LABEL = "Duplicate...";
public final static String PARAM_SOURCE_WORKSPACE_NAME = "srcWkspName";
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);
- int result = inputDialog.open();
- if (result == Window.OK) {
- String newWorkspaceName = inputDialog.getValue();
- srcSession = repository.login(credentials, wkspName);
+ InputDialog inputDialog = new InputDialog(HandlerUtil
+ .getActiveWorkbenchWindow(event).getShell(),
+ "New copy of workspace " + wkspName,
+ "Choose a name for the workspace to create", "", null);
+ int result = inputDialog.open();
+ if (result == Window.OK) {
+ String newWorkspaceName = inputDialog.getValue();
+
+ if (newWorkspaceName == null || newWorkspaceName.trim().equals("")
+ || newWorkspaceName.trim().equals(wkspName.trim())) {
+ ErrorDialog
+ .openError(HandlerUtil.getActiveShell(event),
+ "Non valid workspace name", newWorkspaceName
+ + " is not a valid workspace name.",
+ new Status(IStatus.ERROR, "not valid", 0,
+ "Error", null));
+ return null;
+ }
+ Job copyWkspJob = new CopyWkspJob(repositoryFactory, keyring,
+ nodeRepository, targetRepoPath, wkspName, newWorkspaceName,
+ HandlerUtil.getActiveWorkbenchWindow(event).getShell()
+ .getDisplay());
+ copyWkspJob.setUser(true);
+ copyWkspJob.schedule();
+ }
+
+ // 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);
+ // int result = inputDialog.open();
+ // if (result == Window.OK) {
+ // String newWorkspaceName = inputDialog.getValue();
+ // 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(credentials, newWorkspaceName);
+ // Node newRootNode = newSession.getRootNode();
+ // RepoUtils.copy(srcRootNode, newRootNode);
+ // newSession.save();
+ // JcrUtils.addPrivilege(newSession, "/", SlcConstants.ROLE_SLC,
+ // Privilege.JCR_ALL);
+ // CommandHelpers.callCommand(RefreshDistributionsView.ID);
+ // }
+ // } catch (RepositoryException re) {
+ // throw new ArgeoException(
+ // "Unexpected error while creating the new workspace.", re);
+ // } finally {
+ // JcrUtils.logoutQuietly(newSession);
+ // JcrUtils.logoutQuietly(srcSession);
+ // JcrUtils.logoutQuietly(nodeSession);
+ // }
+ return null;
+ }
+
+ private static class CopyWkspJob extends PrivilegedJob {
+
+ private RepositoryFactory repositoryFactory;
+ private Keyring keyring;
+ private Repository localRepository;
+ private String targetRepoPath;
+ private String srcWkspName;
+ private String targetWkspName;
+ private Display display;
+
+ public CopyWkspJob(RepositoryFactory repositoryFactory,
+ Keyring keyring, Repository localRepository,
+ String targetRepoPath, String srcWkspName,
+ String targetWkspName, Display display) {
+ super("Duplicate workspace");
+ this.repositoryFactory = repositoryFactory;
+ this.keyring = keyring;
+ this.localRepository = localRepository;
+ this.targetRepoPath = targetRepoPath;
+ this.srcWkspName = srcWkspName;
+ this.targetWkspName = targetWkspName;
+ this.display = display;
+ }
+
+ @Override
+ protected IStatus doRun(IProgressMonitor progressMonitor) {
+ long begin = System.currentTimeMillis();
+
+ ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor);
+ monitor.beginTask("Copy workspace", -1);
+ monitor.subTask("Copying nodes");
+
+ Session nodeSession = null;
+ Session srcSession = null;
+ Session newSession = null;
+ try {
+ nodeSession = localRepository.login();
+ Node repoNode = nodeSession.getNode(targetRepoPath);
+ Repository repository = RepoUtils.getRepository(
+ repositoryFactory, keyring, repoNode);
+ Credentials credentials = RepoUtils.getRepositoryCredentials(
+ keyring, repoNode);
+
+ srcSession = repository.login(credentials, srcWkspName);
// Create the workspace
- srcSession.getWorkspace().createWorkspace(newWorkspaceName);
+ srcSession.getWorkspace().createWorkspace(targetWkspName);
Node srcRootNode = srcSession.getRootNode();
// log in the newly created workspace
- newSession = repository.login(credentials, newWorkspaceName);
+ newSession = repository.login(credentials, targetWkspName);
Node newRootNode = newSession.getRootNode();
RepoUtils.copy(srcRootNode, newRootNode);
newSession.save();
JcrUtils.addPrivilege(newSession, "/", SlcConstants.ROLE_SLC,
Privilege.JCR_ALL);
- CommandHelpers.callCommand(RefreshDistributionsView.ID);
+
+ display.asyncExec(new Runnable() {
+ public void run() {
+ CommandHelpers.callCommand(RefreshDistributionsView.ID);
+ }
+ });
+ monitor.worked(1);
+
+ } catch (RepositoryException re) {
+ throw new ArgeoException(
+ "Unexpected error while creating the new workspace.",
+ re);
+ } finally {
+ JcrUtils.logoutQuietly(newSession);
+ JcrUtils.logoutQuietly(srcSession);
+ JcrUtils.logoutQuietly(nodeSession);
}
- } catch (RepositoryException re) {
- throw new ArgeoException(
- "Unexpected error while creating the new workspace.", re);
- } finally {
- JcrUtils.logoutQuietly(newSession);
- JcrUtils.logoutQuietly(srcSession);
- JcrUtils.logoutQuietly(nodeSession);
+
+ monitor.done();
+ long duration = (System.currentTimeMillis() - begin) / 1000;// in
+ // s
+ if (log.isDebugEnabled())
+ log.debug("Created workspace " + targetWkspName + " in "
+ + (duration / 60) + "min " + (duration % 60) + "s");
+ return Status.OK_STATUS;
}
- return null;
+
+
}
/* DEPENDENCY INJECTION */
public final static String ID = DistPlugin.ID + ".markAsRelevantCategory";
public final static String DEFAULT_LABEL = "Mark as relevant category base";
+ public final static String DEFAULT_REMOVE_LABEL = "Remove this category from relevant list";
public final static ImageDescriptor DEFAULT_ICON = DistPlugin
.getImageDescriptor("icons/addItem.gif");
+ public final static ImageDescriptor DEFAULT_REMOVE_ICON = DistPlugin
+ .getImageDescriptor("icons/removeMark.gif");
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
Iterator<?> it = ((IStructuredSelection) selector)
.iterator();
- String msg = "Your are about to mark this group as category base in the current workspace"
- + ".\n" + "Are you sure you want to proceed?";
-
- boolean result = MessageDialog.openConfirm(DistPlugin
- .getDefault().getWorkbench().getDisplay()
- .getActiveShell(), "Confirm", msg);
+ Node node = (Node) it.next();
+ if (node.isNodeType(SlcTypes.SLC_RELEVANT_CATEGORY)) {
+ String msg = "Your are about to unlist this category from the relevant category list for current workspace"
+ + ".\n" + "Are you sure you want to proceed?";
+ if (MessageDialog.openConfirm(DistPlugin.getDefault()
+ .getWorkbench().getDisplay().getActiveShell(),
+ "Confirm", msg)) {
+ node.removeMixin(SlcTypes.SLC_RELEVANT_CATEGORY);
+ node.getSession().save();
+ }
+ } else {
+ String msg = "Your are about to mark this group as category base in the current workspace"
+ + ".\n" + "Are you sure you want to proceed?";
- if (result) {
- while (it.hasNext()) {
- Node node = (Node) it.next();
+ if (MessageDialog.openConfirm(DistPlugin.getDefault()
+ .getWorkbench().getDisplay().getActiveShell(),
+ "Confirm", msg)) {
node.addMixin(SlcTypes.SLC_RELEVANT_CATEGORY);
node.getSession().save();
}
businessSession = RepoUtils.getCorrespondingSession(
repositoryFactory, keyring, repoNode, repoUri,
workspaceName);
- repoUri = repoNode.getProperty(ArgeoNames.ARGEO_URI)
- .getString();
+ if (repoUri == null && repoNode != null)
+ repoUri = repoNode.getProperty(ArgeoNames.ARGEO_URI)
+ .getString();
} catch (RepositoryException e) {
throw new SlcException("Cannot log to workspace "
treeViewer.refresh(obj);
}
} else if (obj instanceof WorkspaceElem) {
- WorkspaceElem wn = (WorkspaceElem) obj;
- if (!wn.isConnected()) {
- wn.login();
- treeViewer.refresh(obj);
- } else {
- WorkspaceElem we = (WorkspaceElem) obj;
- Node repoNode = null;
- try {
- RepoElem repoElem = we.getRepoElem();
- Map<String, String> params = new HashMap<String, String>();
+ //WorkspaceElem wn = (WorkspaceElem) obj;
+ // if (!wn.isConnected()) {
+ // wn.login();
+ // treeViewer.refresh(obj);
+ // } else {
+ WorkspaceElem we = (WorkspaceElem) obj;
+ Node repoNode = null;
+ try {
+ RepoElem repoElem = we.getRepoElem();
+ Map<String, String> params = new HashMap<String, String>();
- repoNode = repoElem.getRepoNode();
- if (repoNode != null)
- params.put(OpenWorkspaceEditor.PARAM_REPO_NODE_PATH,
- repoNode.getPath());
- params.put(OpenWorkspaceEditor.PARAM_REPO_URI,
- repoElem.getUri());
- params.put(OpenWorkspaceEditor.PARAM_WORKSPACE_NAME,
- we.getWorkspaceName());
- CommandUtils.callCommand(OpenWorkspaceEditor.ID, params);
- } catch (RepositoryException re) {
- throw new SlcException("Cannot get path for node "
- + repoNode + " while "
- + "setting parameters of command "
- + "OpenWorkspaceEditor", re);
- }
+ repoNode = repoElem.getRepoNode();
+ if (repoNode != null)
+ params.put(OpenWorkspaceEditor.PARAM_REPO_NODE_PATH,
+ repoNode.getPath());
+ params.put(OpenWorkspaceEditor.PARAM_REPO_URI,
+ repoElem.getUri());
+ params.put(OpenWorkspaceEditor.PARAM_WORKSPACE_NAME,
+ we.getWorkspaceName());
+ CommandUtils.callCommand(OpenWorkspaceEditor.ID, params);
+ } catch (RepositoryException re) {
+ throw new SlcException("Cannot get path for node " + repoNode
+ + " while " + "setting parameters of command "
+ + "OpenWorkspaceEditor", re);
}
+ // }
} else if (obj instanceof ModularDistVersionElem) {
ModularDistVersionElem modDistElem = (ModularDistVersionElem) obj;
WorkspaceElem wkspElem = modDistElem.getWorkspaceElem();
else
return JcrImages.REPOSITORY_DISCONNECTED;
} else if (element instanceof WorkspaceElem) {
- if (((WorkspaceElem) element).isConnected())
- return JcrImages.WORKSPACE_CONNECTED;
- else
- return JcrImages.WORKSPACE_DISCONNECTED;
+ return JcrImages.WORKSPACE_CONNECTED;
} else if (element instanceof WkspGroupElem)
return DistImages.IMG_WKSP_GROUP;
// else if (element instanceof GroupBaseElem)
import org.argeo.slc.jcr.SlcTypes;
import org.argeo.slc.repo.RepoConstants;
import org.argeo.slc.repo.RepoUtils;
+import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
form.setText(currBundle.hasProperty(DistConstants.SLC_BUNDLE_NAME) ? currBundle
.getProperty(DistConstants.SLC_BUNDLE_NAME).getString()
: "");
+ form.setMessage(" test", IMessageProvider.NONE);
Composite body = form.getBody();
GridLayout layout = new GridLayout(1, false);
layout.marginWidth = 5;
import org.argeo.ArgeoMonitor;
import org.argeo.eclipse.ui.EclipseArgeoMonitor;
+import org.argeo.eclipse.ui.EclipseUiUtils;
import org.argeo.eclipse.ui.utils.CommandUtils;
import org.argeo.jcr.JcrUtils;
import org.argeo.slc.SlcException;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
private NodeViewerComparator comparator;
private TableViewer viewer;
- private Composite header;
+ // private Composite header;
private Text artifactTxt;
- private final static String FILTER_HELP_MSG = "Enter filter criterion separated by a space";
+ private final static String FILTER_HELP_MSG = "Search bundles in the current workspace";
public DistWkspSearchPage(DistWorkspaceEditor formEditor, String title,
Session session) {
Composite body = form.getBody();
body.setLayout(layout);
- // Add the filter section
- createFilterPart(body);
- // Add the table
- createTableViewer(body);
- // 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();
- }
+ // Meta info about current workspace
+ Composite header = tk.createComposite(body);
+ header.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ createHeaderPart(form, header);
- public void controlMoved(ControlEvent e) {
- }
- });
- asynchronousRefresh();
+ // filter text
+ Composite filter = tk.createComposite(body);
+ filter.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ createFilterPart(filter);
+
+ // the table
+ Composite tableCmp = tk.createComposite(body);
+ tableCmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ createTableViewer(tableCmp);
}
/** Build repository request */
}
- private void createFilterPart(Composite parent) {
- header = tk.createComposite(parent);
- GridLayout layout = new GridLayout(2, false);
+ private void createHeaderPart(ScrolledForm form, Composite parent) {
+ GridLayout layout = new GridLayout(4, false);
layout.marginWidth = layout.marginHeight = layout.verticalSpacing = 0;
layout.horizontalSpacing = 5;
- header.setLayout(layout);
- GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
- header.setLayoutData(gd);
+ parent.setLayout(layout);
+
+ String wkspName = ((DistWkspEditorInput) getEditorInput())
+ .getWorkspaceName();
+ // wkspName = "Workspace " + wkspName;
+ form.setText(wkspName);
- // Title: some meta information
- // label = repoNode.isNodeType(NodeType.MIX_TITLE) ? repoNode
- // .getProperty(Property.JCR_TITLE).getString() : repoNode
- // .getName();
+ // form.setMessage("Choose in the below list "
+ // + "the categories that can be used as base for "
+ // + "modular distributions maintained via the current workspace",
+ // IMessageProvider.NONE);
- String desc = null;
+ String repoAlias = "";
Node repoNode = ((DistWorkspaceEditor) getEditor()).getRepoNode();
if (repoNode != null)
try {
- desc = repoNode.isNodeType(NodeType.MIX_TITLE) ? repoNode
+ repoAlias = repoNode.isNodeType(NodeType.MIX_TITLE) ? repoNode
.getProperty(Property.JCR_TITLE).getString() : repoNode
.getName();
} catch (RepositoryException e1) {
throw new SlcException("Unable to get repository alias ", e1);
}
- desc += " (" + ((DistWkspEditorInput) getEditorInput()).getUri() + ")";
- Label lbl = tk.createLabel(header, desc, SWT.NONE);
+ else
+ repoAlias = " - ";
- gd = new GridData(SWT.FILL, SWT.FILL, false, false);
- gd.horizontalSpan = 2;
- lbl.setLayoutData(gd);
+ createLT(parent, "Repository alias", repoAlias);
+ createLT(parent, "URI",
+ ((DistWkspEditorInput) getEditorInput()).getUri());
+ }
+
+ private Text createLT(Composite parent, String labelValue, String textValue) {
+ Label label = tk.createLabel(parent, labelValue, SWT.RIGHT);
+ label.setFont(EclipseUiUtils.getBoldFont(parent));
+ label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ // Add a trailing space to workaround a display glitch in RAP 1.3
+ Text text = tk.createText(parent, textValue + " ", SWT.LEFT);
+ text.setEditable(false);
+ return text;
+ }
+
+ private void createFilterPart(Composite parent) {
+ GridLayout layout = new GridLayout(2, false);
+ layout.marginWidth = layout.marginHeight = layout.verticalSpacing = 0;
+ layout.horizontalSpacing = 5;
+ parent.setLayout(layout);
// Text Area to filter
- artifactTxt = tk.createText(header, "", SWT.BORDER | SWT.SINGLE
+ artifactTxt = tk.createText(parent, "", SWT.BORDER | SWT.SINGLE
| SWT.SEARCH | SWT.CANCEL);
artifactTxt.setMessage(FILTER_HELP_MSG);
- gd = new GridData(SWT.FILL, SWT.FILL, false, false);
+ GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
gd.grabExcessHorizontalSpace = true;
artifactTxt.setLayoutData(gd);
artifactTxt.addModifyListener(new ModifyListener() {
}
});
- Button resetBtn = tk.createButton(header, null, SWT.PUSH);
+ Button resetBtn = tk.createButton(parent, null, SWT.PUSH);
resetBtn.setImage(DistImages.IMG_REPO_READONLY);
resetBtn.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
});
-
}
private void resetFilter() {
}
private void createTableViewer(Composite parent) {
+ parent.setLayout(new FillLayout());
// helpers to enable sorting by column
List<String> propertiesList = new ArrayList<String>();
List<Integer> propertyTypesList = new ArrayList<Integer>();
* UI Trick to put scroll bar on the table rather than on the scrollform
*/
private void refreshLayout() {
- // Compute desired table size
- int maxH = getManagedForm().getForm().getSize().y;
- int maxW = getManagedForm().getForm().getParent().getSize().x;
- maxH = maxH - header.getSize().y;
- final Table table = viewer.getTable();
- GridData gd = new GridData(SWT.LEFT, SWT.TOP, true, true);
-
- // when table height is less than 200 px, we let the scroll bar on the
- // scrollForm
- // FIXME substract some spare space. There is room here for optimization
- gd.heightHint = Math.max(maxH - 35, 200);
- gd.widthHint = Math.max(maxW - 35, 200);
-
- table.setLayoutData(gd);
- getManagedForm().reflow(true);
+ // // Compute desired table size
+ // int maxH = getManagedForm().getForm().getSize().y;
+ // int maxW = getManagedForm().getForm().getParent().getSize().x;
+ // // maxH = maxH - header.getSize().y;
+ // final Table table = viewer.getTable();
+ // GridData gd = new GridData(SWT.LEFT, SWT.TOP, true, true);
+ //
+ // // when table height is less than 200 px, we let the scroll bar on
+ // the
+ // // scrollForm
+ // // FIXME substract some spare space. There is room here for
+ // optimization
+ // gd.heightHint = Math.max(maxH - 35, 200);
+ // gd.widthHint = Math.max(maxW - 35, 200);
+ //
+ // table.setLayoutData(gd);
+ // getManagedForm().reflow(true);
}
@Override
protected void addPages() {
try {
addPage(new DistWkspSearchPage(this, "Details ", businessSession));
- addPage(new DistWkspBrowserPage(this, "Browser ", businessSession));
- addPage(new WkspCategoryBaseListPage(this, "Group base ",
+ addPage(new DistWkspBrowserPage(this, "Maven ", businessSession));
+ addPage(new WkspCategoryBaseListPage(this, "Groups ",
businessSession));
} catch (PartInitException e) {
throw new ArgeoException("Cannot add distribution editor pages", e);
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.ObservationManager;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import javax.jcr.query.qom.Constraint;
import javax.jcr.query.qom.StaticOperand;
import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.jcr.AsyncUiEventListener;
import org.argeo.eclipse.ui.utils.CommandUtils;
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.commands.MarkAsRelevantCategory;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
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.Menu;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
private NodeViewerComparator comparator;
private TableViewer viewer;
private FormToolkit tk;
- private Composite header;
private Text filterTxt;
private final static String FILTER_HELP_MSG = "Enter filter criterion separated by a space";
+ // Observes changes
+ private final static String[] observedTypes = { SlcTypes.SLC_GROUP_BASE };
+ private CategoryObserver categoriesObserver;
+
public WkspCategoryBaseListPage(FormEditor formEditor, String title,
Session session) {
super(formEditor, PAGE_ID, title);
ScrolledForm form = managedForm.getForm();
tk = managedForm.getToolkit();
- form.setText("Category base definition");
- form.setMessage("Define relevant group base objects",
+ form.setText("Define Relevant Category");
+ form.setMessage("Choose in the below list "
+ + "the categories that can be used as base for "
+ + "modular distributions maintained via the current workspace",
IMessageProvider.NONE);
// Main Layout
GridLayout layout = new GridLayout(1, false);
Composite body = form.getBody();
body.setLayout(layout);
- // Add the filter section
- createFilterPart(body);
- // Add the table
- createTableViewer(body);
-
- // 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) {
- }
- });
+ // filter section
+ Composite header = tk.createComposite(body);
+ header.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ createFilterPart(header);
+
+ // the table
+ Composite tableCmp = tk.createComposite(body);
+ tableCmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ createTableViewer(tableCmp);
+
+ categoriesObserver = new CategoryObserver(viewer.getTable()
+ .getDisplay());
+ try {
+ ObservationManager observationManager = session.getWorkspace()
+ .getObservationManager();
+ // FIXME Will not be notified if empty result is deleted
+ observationManager.addEventListener(categoriesObserver,
+ Event.PROPERTY_CHANGED, "/", true, null, observedTypes,
+ false);
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot register listeners", e);
+ }
+
refresh();
}
}
private void createFilterPart(Composite parent) {
- header = tk.createComposite(parent);
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = layout.marginHeight = layout.verticalSpacing = 0;
layout.horizontalSpacing = 5;
- header.setLayout(layout);
- GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
- header.setLayoutData(gd);
+ parent.setLayout(layout);
// Text Area to filter
- filterTxt = tk.createText(header, "", SWT.BORDER | SWT.SINGLE
+ filterTxt = tk.createText(parent, "", SWT.BORDER | SWT.SINGLE
| SWT.SEARCH | SWT.CANCEL);
filterTxt.setMessage(FILTER_HELP_MSG);
- gd = new GridData(SWT.FILL, SWT.FILL, false, false);
- gd.grabExcessHorizontalSpace = true;
- filterTxt.setLayoutData(gd);
+ filterTxt.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
filterTxt.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
refresh();
}
});
- Button resetBtn = tk.createButton(header, null, SWT.PUSH);
+ Button resetBtn = tk.createButton(parent, null, SWT.PUSH);
resetBtn.setImage(DistImages.IMG_REPO_READONLY);
- resetBtn.addSelectionListener(new SelectionListener() {
-
+ resetBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
resetFilter();
}
-
- public void widgetDefaultSelected(SelectionEvent e) {
- }
});
-
}
private void resetFilter() {
}
private void createTableViewer(Composite parent) {
+ parent.setLayout(new FillLayout());
// helpers to enable sorting by column
List<String> propertiesList = new ArrayList<String>();
List<Integer> propertyTypesList = new ArrayList<Integer>();
// Define the TableViewer
- viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
+ viewer = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
TableViewerColumn col;
}
});
col.getColumn().addSelectionListener(getSelectionAdapter(0));
- propertiesList.add(SLC_NAME);
+ propertiesList.add(SLC_GROUP_BASE_ID);
propertyTypesList.add(PropertyType.STRING);
// Version
col = new TableViewerColumn(viewer, SWT.NONE);
col.getColumn().setWidth(80);
- col.getColumn().setText("Is category");
+ col.getColumn().setText("Relevant");
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
try {
return ((Node) element)
.isNodeType(SlcTypes.SLC_RELEVANT_CATEGORY) ? "Yes"
- : "-";
+ : "No";
} catch (RepositoryException e) {
throw new SlcException("unable to check type of node "
+ element, e);
// Mark as category base
Object firstElement = ((IStructuredSelection) viewer.getSelection())
.getFirstElement();
- boolean showMark = false;
+ Node currSelected = (Node) firstElement;
+
+ boolean isRelevant = false;
try {
- showMark = !((Node) firstElement)
+ isRelevant = currSelected
.isNodeType(SlcTypes.SLC_RELEVANT_CATEGORY);
+ boolean canEdit = currSelected
+ .canAddMixin(SlcTypes.SLC_RELEVANT_CATEGORY);
+
} catch (RepositoryException e) {
throw new SlcException("unable to check type of node "
+ firstElement, e);
}
- CommandUtils.refreshCommand(menuManager, window,
- MarkAsRelevantCategory.ID,
- MarkAsRelevantCategory.DEFAULT_LABEL,
- MarkAsRelevantCategory.DEFAULT_ICON, showMark);
+ // Add
+ if (isRelevant) {// Remove
+ CommandUtils.refreshCommand(menuManager, window,
+ MarkAsRelevantCategory.ID,
+ MarkAsRelevantCategory.DEFAULT_REMOVE_LABEL,
+ MarkAsRelevantCategory.DEFAULT_REMOVE_ICON, true);
+ } else {
+ CommandUtils.refreshCommand(menuManager, window,
+ MarkAsRelevantCategory.ID,
+ MarkAsRelevantCategory.DEFAULT_LABEL,
+ MarkAsRelevantCategory.DEFAULT_ICON, true);
+ }
}
private SelectionAdapter getSelectionAdapter(final int index) {
}
}
- /**
- * UI Trick to put scroll bar on the table rather than on the scrollform
- */
- private void refreshLayout() {
- // Compute desired table size
- int maxH = getManagedForm().getForm().getSize().y;
- int maxW = getManagedForm().getForm().getParent().getSize().x;
- maxH = maxH - header.getSize().y;
- final Table table = viewer.getTable();
- GridData gd = new GridData(SWT.LEFT, SWT.TOP, true, true);
+ class CategoryObserver extends AsyncUiEventListener {
- // when table height is less than 200 px, we let the scroll bar on the
- // scrollForm
- // FIXME substract some spare space. There is room here for optimization
- gd.heightHint = Math.max(maxH - 35, 200);
- gd.widthHint = Math.max(maxW - 35, 200);
+ public CategoryObserver(Display display) {
+ super(display);
+ }
- table.setLayoutData(gd);
- getManagedForm().reflow(true);
+ @Override
+ protected Boolean willProcessInUiThread(List<Event> events)
+ throws RepositoryException {
+ for (Event event : events) {
+ String path = event.getPath();
+ if (JcrUtils.lastPathElement(path).equals(
+ DistConstants.JCR_MIXIN_TYPES))
+ return true;
+ }
+ return false;
+ }
+
+ protected void onEventInUiThread(List<Event> events)
+ throws RepositoryException {
+ if (getLog().isTraceEnabled())
+ getLog().trace("Refresh table");
+ viewer.refresh();
+ }
}
@Override
public void setActive(boolean active) {
super.setActive(active);
if (active) {
- refreshLayout();
}
}
}
\ No newline at end of file
*/
public class ModularDistBaseElem extends DistParentElem {
+ final static public String AETHER_CATEGORY_BASE = "categoryBase";
final static public String AETHER_BINARIES_TYPE = "binaries";
final static public String AETHER_DEP_TYPE = "dep";
private String type;
// initialize current object
try {
NodeIterator ni = getDistVersions();
- while (ni.hasNext()) {
+ while (ni != null && ni.hasNext()) {
Node curNode = ni.nextNode();
addChild(new ModularDistVersionElem(this, curNode
.getProperty(SlcNames.SLC_ARTIFACT_VERSION)
public NodeIterator getDistVersions() {
try {
+ if (AETHER_CATEGORY_BASE.equals(type))
+ return null;
+
QueryManager queryManager = artifactBase.getSession()
.getWorkspace().getQueryManager();
QueryObjectModelFactory factory = queryManager.getQOMFactory();
if (isConnected())
return currSession.getRootNode().hasNodes();
else
- return false;
+ return true;
} catch (RepositoryException re) {
throw new ArgeoException(
"Unexpected error while checking children node existence",
} else {
// initialize current object
try {
+ // Lazy connect the first time we retrieve children
if (currSession == null)
- return null;
- else {
- // Retrieve already existing distribution
- Query groupQuery = currSession
- .getWorkspace()
- .getQueryManager()
- .createQuery(
- "select * from ["
- + SlcTypes.SLC_MODULAR_DISTRIBUTION
- + "]", Query.JCR_SQL2);
- NodeIterator distributions = groupQuery.execute()
- .getNodes();
- distribs: while (distributions.hasNext()) {
- Node currDist = distributions.nextNode();
- Node distBase = currDist.getParent().getParent();
- if (!distBase.isNodeType(SlcTypes.SLC_ARTIFACT_BASE))
- continue distribs;
- String groupId = distBase.getProperty(
- SlcNames.SLC_GROUP_ID).getString();
- String artifactId = distBase.getProperty(
- SlcNames.SLC_ARTIFACT_ID).getString();
+ login();
- String name;
- String type;
- if (ModularDistBaseElem.AETHER_BINARIES_TYPE
- .equals(artifactId)) {
- name = groupId;
- type = ModularDistBaseElem.AETHER_BINARIES_TYPE;
- } else {
- name = artifactId;
- type = ModularDistBaseElem.AETHER_DEP_TYPE;
- }
- if (getChildByName(name) == null)
- addChild(new ModularDistBaseElem(
- WorkspaceElem.this, name, distBase, type));
- }
- // Add empty group base that have been marked as relevant
- groupQuery = currSession
- .getWorkspace()
- .getQueryManager()
- .createQuery(
- "select * from ["
- + SlcTypes.SLC_RELEVANT_CATEGORY
- + "]", Query.JCR_SQL2);
- distributions = groupQuery.execute().getNodes();
- while (distributions.hasNext()) {
- Node distBase = distributions.nextNode();
- String groupBaseId = distBase.getProperty(
- SlcNames.SLC_GROUP_BASE_ID).getString();
- if (getChildByName(groupBaseId) == null)
- addChild(new ModularDistBaseElem(
- WorkspaceElem.this, groupBaseId, distBase,
- ModularDistBaseElem.AETHER_BINARIES_TYPE));
+ // Retrieve already existing distribution
+ Query groupQuery = currSession
+ .getWorkspace()
+ .getQueryManager()
+ .createQuery(
+ "select * from ["
+ + SlcTypes.SLC_MODULAR_DISTRIBUTION
+ + "]", Query.JCR_SQL2);
+ NodeIterator distributions = groupQuery.execute().getNodes();
+ distribs: while (distributions.hasNext()) {
+ Node currDist = distributions.nextNode();
+ Node distBase = currDist.getParent().getParent();
+ if (!distBase.isNodeType(SlcTypes.SLC_ARTIFACT_BASE))
+ continue distribs;
+ String groupId = distBase
+ .getProperty(SlcNames.SLC_GROUP_ID).getString();
+ String artifactId = distBase.getProperty(
+ SlcNames.SLC_ARTIFACT_ID).getString();
+
+ String name;
+ String type;
+ if (ModularDistBaseElem.AETHER_BINARIES_TYPE
+ .equals(artifactId)) {
+ name = groupId;
+ type = ModularDistBaseElem.AETHER_BINARIES_TYPE;
+ } else {
+ name = artifactId;
+ type = ModularDistBaseElem.AETHER_DEP_TYPE;
}
+ if (getChildByName(name) == null)
+ addChild(new ModularDistBaseElem(WorkspaceElem.this,
+ name, distBase, type));
+ }
+ // Add empty group base that have been marked as relevant
+ groupQuery = currSession
+ .getWorkspace()
+ .getQueryManager()
+ .createQuery(
+ "select * from ["
+ + SlcTypes.SLC_RELEVANT_CATEGORY + "]",
+ Query.JCR_SQL2);
+ distributions = groupQuery.execute().getNodes();
+ while (distributions.hasNext()) {
+ Node distBase = distributions.nextNode();
+ String groupBaseId = distBase.getProperty(
+ SlcNames.SLC_GROUP_BASE_ID).getString();
+ if (getChildByName(groupBaseId) == null)
+ addChild(new ModularDistBaseElem(WorkspaceElem.this,
+ groupBaseId, distBase,
+ ModularDistBaseElem.AETHER_CATEGORY_BASE));
}
return super.getChildren();
} catch (RepositoryException e) {
getLog().trace("Refresh result list");
viewer.refresh();
}
-
}
public void setSession(Session session) {