]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/jcr/utils/NodeViewerComparer.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.eclipse
.ui
.jcr
.utils
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
21 import org
.argeo
.ArgeoException
;
22 import org
.eclipse
.jface
.viewers
.IElementComparer
;
24 /** Compare JCR nodes based on their JCR identifiers, for use in JFace viewers. */
25 public class NodeViewerComparer
implements IElementComparer
{
27 // force comparison on Node IDs only.
28 public boolean equals(Object elementA
, Object elementB
) {
29 if (!(elementA
instanceof Node
) || !(elementB
instanceof Node
)) {
30 return elementA
== null ? elementB
== null : elementA
34 boolean result
= false;
36 String idA
= ((Node
) elementA
).getIdentifier();
37 String idB
= ((Node
) elementB
).getIdentifier();
38 result
= idA
== null ? idB
== null : idA
.equals(idB
);
39 } catch (RepositoryException re
) {
40 throw new ArgeoException("cannot compare nodes", re
);
47 public int hashCode(Object element
) {
48 // TODO enhanced this method.
49 return element
.getClass().toString().hashCode();