count++;
}
- if (log.isDebugEnabled())
- log.debug("Count " + count);
+ if (log.isTraceEnabled())
+ log.trace("Translated workspace name length: " + count
+ + " (name: " + enteredName + " )");
if (count > 60) {
ErrorFeedback.show("Workspace name '" + enteredName
import org.argeo.slc.client.ui.dist.model.RepoElem;
import org.argeo.slc.client.ui.dist.model.WkspGroupElem;
import org.argeo.slc.client.ui.dist.model.WorkspaceElem;
+import org.argeo.slc.client.ui.dist.utils.NameVersionComparator;
+import org.argeo.slc.client.ui.dist.utils.VersionComparator;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
/** Specific comparator to enhance Distribution tree browsers */
public class DistTreeComparator extends ViewerComparator {
+ private VersionComparator vc = new VersionComparator();
+ private NameVersionComparator nvc = new NameVersionComparator();
+
public int category(Object element) {
if (element instanceof RepoElem)
if (((RepoElem) element).inHome())
s2 = e2.toString();
}
- if (e1 instanceof WorkspaceElem || e1 instanceof ModularDistVersionElem)
+ if (e1 instanceof WorkspaceElem)
+ // Reverse order for nameversions
+ return nvc.compare(viewer, s2, s1);
+ else if (e1 instanceof ModularDistVersionElem)
// Reverse order for versions
- return s2.compareTo(s1);
+ return vc.compare(viewer, s2, s1);
else
return s1.compareTo(s2);
}
import org.argeo.slc.client.ui.dist.PrivilegedJob;
import org.argeo.slc.client.ui.dist.commands.DeleteArtifacts;
import org.argeo.slc.client.ui.dist.commands.OpenModuleEditor;
-import org.argeo.slc.client.ui.dist.utils.NodeViewerComparator;
+import org.argeo.slc.client.ui.dist.utils.DistNodeViewerComparator;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
import org.eclipse.core.runtime.IProgressMonitor;
private DistWorkspaceEditor formEditor;
private FormToolkit tk;
- private NodeViewerComparator comparator;
+ private DistNodeViewerComparator comparator;
private TableViewer viewer;
// private Composite header;
});
col.getColumn().addSelectionListener(getSelectionAdapter(2));
propertiesList.add(SLC_BUNDLE_VERSION);
- propertyTypesList.add(PropertyType.STRING);
+ propertyTypesList.add(DistNodeViewerComparator.VERSION_TYPE);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
viewer.setContentProvider(new DistributionsContentProvider());
getSite().setSelectionProvider(viewer);
- comparator = new NodeViewerComparator(2,
- NodeViewerComparator.ASCENDING, propertiesList,
+ comparator = new DistNodeViewerComparator(2,
+ DistNodeViewerComparator.ASCENDING, propertiesList,
propertyTypesList);
viewer.setComparator(comparator);
import org.argeo.slc.client.ui.dist.DistImages;
import org.argeo.slc.client.ui.dist.commands.OpenModuleEditor;
import org.argeo.slc.client.ui.dist.utils.AbstractHyperlinkListener;
-import org.argeo.slc.client.ui.dist.utils.NodeViewerComparator;
+import org.argeo.slc.client.ui.dist.utils.DistNodeViewerComparator;
import org.argeo.slc.client.ui.specific.OpenJcrFile;
import org.argeo.slc.client.ui.specific.OpenJcrFileCmdId;
import org.argeo.slc.jcr.SlcNames;
// private Node modularDistributionBase;
// This page widgets
- private NodeViewerComparator comparator;
+ private DistNodeViewerComparator comparator;
private TableViewer viewer;
private FormToolkit tk;
private Text filterTxt;
});
col.getColumn().addSelectionListener(getSelectionAdapter(2));
propertiesList.add(SLC_VERSION);
- propertyTypesList.add(PropertyType.STRING);
+ propertyTypesList.add(DistNodeViewerComparator.VERSION_TYPE);
// Exists in workspace
col = new TableViewerColumn(viewer, SWT.NONE);
viewer.setContentProvider(new DistributionsContentProvider());
getSite().setSelectionProvider(viewer);
- comparator = new NodeViewerComparator(2,
- NodeViewerComparator.ASCENDING, propertiesList,
+ comparator = new DistNodeViewerComparator(2,
+ DistNodeViewerComparator.ASCENDING, propertiesList,
propertyTypesList);
viewer.setComparator(comparator);
import org.argeo.slc.client.ui.dist.DistPlugin;
import org.argeo.slc.client.ui.dist.commands.OpenGenerateBinariesWizard;
import org.argeo.slc.client.ui.dist.commands.OpenModuleEditor;
-import org.argeo.slc.client.ui.dist.utils.NodeViewerComparator;
+import org.argeo.slc.client.ui.dist.utils.DistNodeViewerComparator;
import org.argeo.slc.jcr.SlcNames;
import org.argeo.slc.jcr.SlcTypes;
import org.argeo.slc.repo.RepoConstants;
private Session session;
// This page widgets
- private NodeViewerComparator comparator;
+ private DistNodeViewerComparator comparator;
private TableViewer viewer;
private FormToolkit tk;
private Text filterTxt;
viewer.setContentProvider(new DistributionsContentProvider());
getSite().setSelectionProvider(viewer);
- comparator = new NodeViewerComparator(0,
- NodeViewerComparator.ASCENDING, propertiesList,
+ comparator = new DistNodeViewerComparator(0,
+ DistNodeViewerComparator.ASCENDING, propertiesList,
propertyTypesList);
viewer.setComparator(comparator);
+++ /dev/null
-package org.argeo.slc.client.ui.dist.utils;
-
-import org.argeo.eclipse.ui.TreeParent;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-
-/**
- * Enable comparison of two names with form org.argeo.slc-1.2.x
- */
-
-public class ArtifactNamesComparator extends ViewerComparator {
-
- @Override
- public int category(Object element) {
- if (element instanceof String) {
- int lastInd = ((String) element).lastIndexOf('-');
- if (lastInd > 0)
- return 10;
- }
- // unvalid names always last
- return 5;
- }
-
- @Override
- public int compare(Viewer viewer, Object e1, Object e2) {
- int cat1 = category(e1);
- int cat2 = category(e2);
-
- if (cat1 != cat2) {
- return cat1 - cat2;
- }
-
- int result = 0;
-
- String s1, s2;
-
- if (e1 instanceof TreeParent) {
- s1 = ((TreeParent) e1).getName();
- s2 = ((TreeParent) e2).getName();
- } else {
- s1 = e1.toString();
- s2 = e2.toString();
- }
-
-
- int i1 = s1.lastIndexOf('-');
- int i2 = s2.lastIndexOf('-');
-
-
- // Specific cases, unvalid Strings
- if (i1 <0)
- if (i2 <0)
- return s1.compareTo(s2);
- else
- return 1;
- else
- if (i2 <0)
- return -1;
-
- String aPref = s1.substring(0, s1.lastIndexOf('-'));
- String aSuf = s1.substring(s1.lastIndexOf('-'));
-
- String bPref = s2.substring(0, s2.lastIndexOf('-'));
- String bSuf = s2.substring(s2.lastIndexOf('-'));
-
- result = aPref.compareTo(bPref);
- if (result != 0)
- return result;
- else
- return bSuf.compareTo(aSuf);
-
- }
-}
\ 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.utils;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.GenericTableComparator;
+import org.eclipse.jface.viewers.Viewer;
+
+/** Add ability to order by name version and version */
+public class DistNodeViewerComparator extends GenericTableComparator {
+ private final static Log log = LogFactory
+ .getLog(DistNodeViewerComparator.class);
+
+ // Jcr property type goes to 12
+ public final static int NAME_VERSION_TYPE = 100;
+ public final static int VERSION_TYPE = 101;
+
+ protected List<String> propertiesList;
+ protected List<Integer> propertyTypesList;
+ protected Integer propertyType;
+ protected String property;
+
+ private NameVersionComparator nvc = new NameVersionComparator();
+ private VersionComparator vc = new VersionComparator();
+
+ public DistNodeViewerComparator(int defaultColIndex, int defaultDirection,
+ List<String> propertiesList, List<Integer> propertyTypesList) {
+ super(defaultColIndex, defaultDirection);
+ this.propertiesList = propertiesList;
+ this.propertyTypesList = propertyTypesList;
+ this.propertyIndex = defaultColIndex;
+ this.propertyType = propertyTypesList.get(defaultColIndex);
+ this.property = propertiesList.get(defaultColIndex);
+ setColumn(defaultColIndex);
+ }
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ int rc = 0;
+ long lc = 0;
+
+ try {
+ Node n1 = (Node) e1;
+ Node n2 = (Node) e2;
+
+ Value v1 = null;
+ Value v2 = null;
+ if (n1.hasProperty(property))
+ v1 = n1.getProperty(property).getValue();
+ if (n2.hasProperty(property))
+ v2 = n2.getProperty(property).getValue();
+
+ if (v2 == null && v1 == null)
+ return 0;
+ else if (v2 == null)
+ return -1;
+ else if (v1 == null)
+ return 1;
+
+ switch (propertyType) {
+ case NAME_VERSION_TYPE:
+ rc = nvc.compare(viewer, v1.getString(), v2.getString());
+ break;
+ case VERSION_TYPE:
+ rc = vc.compare(viewer, v1.getString(), v2.getString());
+ break;
+ case PropertyType.STRING:
+ rc = v1.getString().compareTo(v2.getString());
+ break;
+ case PropertyType.BOOLEAN:
+ boolean b1 = v1.getBoolean();
+ boolean b2 = v2.getBoolean();
+ if (b1 == b2)
+ rc = 0;
+ else
+ // we assume true is greater than false
+ rc = b1 ? 1 : -1;
+ break;
+ case PropertyType.DATE:
+ Calendar c1 = v1.getDate();
+ Calendar c2 = v2.getDate();
+ if (c1 == null || c2 == null)
+ log.trace("undefined date");
+ lc = c1.getTimeInMillis() - c2.getTimeInMillis();
+ if (lc < Integer.MIN_VALUE)
+ // rc = Integer.MIN_VALUE;
+ rc = -1;
+ else if (lc > Integer.MAX_VALUE)
+ // rc = Integer.MAX_VALUE;
+ rc = 1;
+ else
+ rc = (int) lc;
+ break;
+ case PropertyType.LONG:
+ long l1;
+ long l2;
+ // FIXME sometimes an empty string is set instead of the id
+ try {
+ l1 = v1.getLong();
+ } catch (ValueFormatException ve) {
+ l1 = 0;
+ }
+ try {
+ l2 = v2.getLong();
+ } catch (ValueFormatException ve) {
+ l2 = 0;
+ }
+
+ lc = l1 - l2;
+ if (lc < Integer.MIN_VALUE)
+ // rc = Integer.MIN_VALUE;
+ rc = -1;
+ else if (lc > Integer.MAX_VALUE)
+ // rc = Integer.MAX_VALUE;
+ rc = 1;
+ else
+ rc = (int) lc;
+ break;
+ case PropertyType.DECIMAL:
+ BigDecimal bd1 = v1.getDecimal();
+ BigDecimal bd2 = v2.getDecimal();
+ rc = bd1.compareTo(bd2);
+ break;
+ default:
+ throw new ArgeoException(
+ "Unimplemented comparaison for PropertyType "
+ + propertyType);
+ }
+
+ // If descending order, flip the direction
+ if (direction == DESCENDING) {
+ rc = -rc;
+ }
+
+ } catch (RepositoryException re) {
+ throw new ArgeoException("Unexpected error "
+ + "while comparing nodes", re);
+ }
+ return rc;
+ }
+
+ @Override
+ public void setColumn(int column) {
+ if (column == this.propertyIndex) {
+ // Same column as last sort; toggle the direction
+ direction = 1 - direction;
+ } else {
+ // New column; do a descending sort
+ this.propertyIndex = column;
+ this.propertyType = propertyTypesList.get(column);
+ this.property = propertiesList.get(column);
+ direction = ASCENDING;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.client.ui.dist.utils;
+
+import org.argeo.eclipse.ui.TreeParent;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+
+/**
+ * Enable comparison of two names version string with form org.argeo.slc-1.2.x.
+ * with following rules and assumptions:
+ * <ul>
+ * <li>
+ * Names are ordered using Lexicographical order</li>
+ * <li>
+ * Version are parsed and compared segment by segment; doing best effort to
+ * convert major, minor and micro to integer and compare them as such (to have
+ * 0.1 < 0.9 < 0.10 not 0.1 < 0.10 < 0.9).</li>
+ * <li>Version should not contain any dash (-), version segments should be
+ * separated by dots (.)</li>
+ * </ul>
+ */
+
+public class NameVersionComparator extends ViewerComparator {
+
+ private VersionComparator vc = new VersionComparator();
+
+ @Override
+ public int category(Object element) {
+ if (element instanceof String) {
+ int lastInd = ((String) element).lastIndexOf('-');
+ if (lastInd > 0)
+ return 10;
+ }
+ // unvalid names always last
+ return 5;
+ }
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ int cat1 = category(e1);
+ int cat2 = category(e2);
+
+ if (cat1 != cat2) {
+ return cat1 - cat2;
+ }
+
+ int result = 0;
+
+ String s1, s2;
+
+ if (e1 instanceof TreeParent) {
+ s1 = ((TreeParent) e1).getName();
+ s2 = ((TreeParent) e2).getName();
+ } else {
+ s1 = e1.toString();
+ s2 = e2.toString();
+ }
+
+ int i1 = s1.lastIndexOf('-');
+ int i2 = s2.lastIndexOf('-');
+
+ // Specific cases, unvalid Strings
+ if (i1 < 0)
+ if (i2 < 0)
+ return s1.compareTo(s2);
+ else
+ return 1;
+ else if (i2 < 0)
+ return -1;
+
+ String aName = s1.substring(0, s1.lastIndexOf('-'));
+ String aVersion = s1.substring(s1.lastIndexOf('-'));
+
+ String bName = s2.substring(0, s2.lastIndexOf('-'));
+ String bVersion = s2.substring(s2.lastIndexOf('-'));
+
+ result = aName.compareTo(bName);
+ if (result != 0)
+ return result;
+ else
+ return vc.compare(viewer, aVersion, bVersion);
+ }
+}
\ 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.utils;
-
-import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.PropertyType;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.GenericTableComparator;
-import org.eclipse.jface.viewers.Viewer;
-
-public class NodeViewerComparator extends GenericTableComparator {
- private final static Log log = LogFactory
- .getLog(NodeViewerComparator.class);
-
- protected List<String> propertiesList;
- protected List<Integer> propertyTypesList;
- protected Integer propertyType;
- protected String property;
-
- public NodeViewerComparator(int defaultColIndex, int defaultDirection,
- List<String> propertiesList, List<Integer> propertyTypesList) {
- super(defaultColIndex, defaultDirection);
- this.propertiesList = propertiesList;
- this.propertyTypesList = propertyTypesList;
- this.propertyIndex = defaultColIndex;
- this.propertyType = propertyTypesList.get(defaultColIndex);
- this.property = propertiesList.get(defaultColIndex);
- setColumn(defaultColIndex);
- }
-
- @Override
- public int compare(Viewer viewer, Object e1, Object e2) {
- int rc = 0;
- long lc = 0;
-
- try {
- Node n1 = (Node) e1;
- Node n2 = (Node) e2;
-
- Value v1 = null;
- Value v2 = null;
- if (n1.hasProperty(property))
- v1 = n1.getProperty(property).getValue();
- if (n2.hasProperty(property))
- v2 = n2.getProperty(property).getValue();
-
- if (v2 == null && v1 == null)
- return 0;
- else if (v2 == null)
- return -1;
- else if (v1 == null)
- return 1;
-
- switch (propertyType) {
- case PropertyType.STRING:
- rc = v1.getString().compareTo(v2.getString());
- break;
- case PropertyType.BOOLEAN:
- boolean b1 = v1.getBoolean();
- boolean b2 = v2.getBoolean();
- if (b1 == b2)
- rc = 0;
- else
- // we assume true is greater than false
- rc = b1 ? 1 : -1;
- break;
- case PropertyType.DATE:
- Calendar c1 = v1.getDate();
- Calendar c2 = v2.getDate();
- if (c1 == null || c2 == null)
- log.trace("undefined date");
- lc = c1.getTimeInMillis() - c2.getTimeInMillis();
- if (lc < Integer.MIN_VALUE)
- // rc = Integer.MIN_VALUE;
- rc = -1;
- else if (lc > Integer.MAX_VALUE)
- // rc = Integer.MAX_VALUE;
- rc = 1;
- else
- rc = (int) lc;
- break;
- case PropertyType.LONG:
- long l1;
- long l2;
- // FIXME sometimes an empty string is set instead of the id
- try {
- l1 = v1.getLong();
- } catch (ValueFormatException ve) {
- l1 = 0;
- }
- try {
- l2 = v2.getLong();
- } catch (ValueFormatException ve) {
- l2 = 0;
- }
-
- lc = l1 - l2;
- if (lc < Integer.MIN_VALUE)
- // rc = Integer.MIN_VALUE;
- rc = -1;
- else if (lc > Integer.MAX_VALUE)
- // rc = Integer.MAX_VALUE;
- rc = 1;
- else
- rc = (int) lc;
- break;
- case PropertyType.DECIMAL:
- BigDecimal bd1 = v1.getDecimal();
- BigDecimal bd2 = v2.getDecimal();
- rc = bd1.compareTo(bd2);
- break;
- default:
- throw new ArgeoException(
- "Unimplemented comparaison for PropertyType "
- + propertyType);
- }
-
- // If descending order, flip the direction
- if (direction == DESCENDING) {
- rc = -rc;
- }
-
- } catch (RepositoryException re) {
- throw new ArgeoException("Unexpected error "
- + "while comparing nodes", re);
- }
- return rc;
- }
-
- @Override
- public void setColumn(int column) {
- if (column == this.propertyIndex) {
- // Same column as last sort; toggle the direction
- direction = 1 - direction;
- } else {
- // New column; do a descending sort
- this.propertyIndex = column;
- this.propertyType = propertyTypesList.get(column);
- this.property = propertiesList.get(column);
- direction = ASCENDING;
- }
- }
-}
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.client.ui.dist.utils;
+
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+
+/**
+ * Enable comparison of two version string with form "1.2.5.qualifier" with
+ * following rules and assumptions:
+ * <ul>
+ * <li>
+ * Version are parsed and compared segment by segment; doing best effort to
+ * convert major, minor and micro to integer and compare them as such (to have
+ * 0.1 < 0.9 < 0.10 not 0.1 < 0.10 < 0.9).</li>
+ * <li>Version should not contain any dash (-), version segments should be
+ * separated by dots (.)</li>
+ * </ul>
+ */
+
+public class VersionComparator extends ViewerComparator {
+
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ String s1 = (String) e1;
+ String s2 = (String) e2;
+ return compareVersion(s1, s2);
+ }
+
+ /**
+ * Enable comparison of two versions of the form
+ * "major.minor.micro.qualifier". We assume the separator is always a "."
+ * and make best effort to convert major, minor and micro to int.
+ */
+ private int compareVersion(String v1, String v2) {
+ String[] t1 = v1.split("\\.");
+ String[] t2 = v2.split("\\.");
+
+ for (int i = 0; i < t1.length && i < t2.length; i++) {
+ int result = compareToken(t1[i], t2[i]);
+ if (result != 0)
+ return result;
+ }
+ if (t1.length > t2.length)
+ return 1;
+ else if (t1.length < t2.length)
+ return -1;
+ else
+ return 0;
+ }
+
+ private int compareToken(String t1, String t2) {
+ if (t1 == null && t2 == null)
+ return 0;
+ else if (t1 == null)
+ return -1;
+ else if (t2 == null)
+ return 1;
+
+ Integer i1 = null, i2 = null;
+ try {
+ i1 = new Integer(t1);
+ i2 = new Integer(t2);
+ } catch (NumberFormatException nfe) {
+ // the format is not valid we silently compare as String
+ return t1.compareTo(t2);
+ }
+ return i1.compareTo(i2);
+ }
+}
\ No newline at end of file