X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.jcr.ui.explorer%2Fsrc%2Forg%2Fargeo%2Fjcr%2Fui%2Fexplorer%2Feditors%2FGenericNodeEditorInput.java;fp=org.argeo.jcr.ui.explorer%2Fsrc%2Forg%2Fargeo%2Fjcr%2Fui%2Fexplorer%2Feditors%2FGenericNodeEditorInput.java;h=45e337e5d581bd0b9fff55bca70829a2ca0b1a8d;hb=d33e8191813f561cee96fbbbd3f74737070140d0;hp=0000000000000000000000000000000000000000;hpb=959ea5e8b3cc27eaf6cb31c37d7fc28f2719f6f3;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr.ui.explorer/src/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java b/org.argeo.jcr.ui.explorer/src/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java new file mode 100644 index 000000000..45e337e5d --- /dev/null +++ b/org.argeo.jcr.ui.explorer/src/org/argeo/jcr/ui/explorer/editors/GenericNodeEditorInput.java @@ -0,0 +1,111 @@ +/* + * 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.jcr.ui.explorer.editors; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.argeo.ArgeoException; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPersistableElement; + +/** + * An editor input based the JCR node object. + * */ + +public class GenericNodeEditorInput implements IEditorInput { + private final Node currentNode; + + // cache key properties at creation time to avoid Exception at recoring time + // when the session has been closed + private String path; + private String uid; + private String name; + + public GenericNodeEditorInput(Node currentNode) { + this.currentNode = currentNode; + try { + name = currentNode.getName(); + uid = currentNode.getIdentifier(); + path = currentNode.getPath(); + } catch (RepositoryException re) { + throw new ArgeoException( + "unexpected error while getting node key values at creation time", + re); + } + } + + public Node getCurrentNode() { + return currentNode; + } + + public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + return null; + } + + public boolean exists() { + return true; + } + + public ImageDescriptor getImageDescriptor() { + return null; + } + + public String getName() { + return name; + } + + public String getUid() { + return uid; + } + + public String getToolTipText() { + return path; + } + + public String getPath() { + return path; + } + + public IPersistableElement getPersistable() { + return null; + } + + /** + * equals method based on UID that is unique within a workspace and path of + * the node, thus 2 shared node that have same UID as defined in the spec + * but 2 different pathes will open two distinct editors. + * + * TODO enhance this method to support multirepository and multiworkspace + * environments + */ + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + + GenericNodeEditorInput other = (GenericNodeEditorInput) obj; + if (!getUid().equals(other.getUid())) + return false; + if (!getPath().equals(other.getPath())) + return false; + return true; + } +}