001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.subversion.ui.diff;
042:
043: import org.openide.nodes.AbstractNode;
044: import org.openide.nodes.Children;
045: import org.openide.nodes.Sheet;
046: import org.openide.nodes.PropertySupport;
047: import org.openide.util.lookup.Lookups;
048: import org.netbeans.modules.subversion.FileInformation;
049: import org.netbeans.modules.subversion.Subversion;
050: import org.netbeans.modules.subversion.util.SvnUtils;
051: import org.tigris.subversion.svnclientadapter.SVNClientException;
052:
053: import javax.swing.*;
054: import java.lang.reflect.InvocationTargetException;
055: import java.util.logging.Level;
056:
057: /**
058: * Visible in the Search History Diff view.
059: *
060: * @author Maros Sandor
061: */
062: class DiffNode extends AbstractNode {
063:
064: static final String COLUMN_NAME_NAME = "name";
065: static final String COLUMN_NAME_PROPERTY = "property";
066: static final String COLUMN_NAME_STATUS = "status";
067: static final String COLUMN_NAME_LOCATION = "location";
068:
069: private final Setup setup;
070: private String htmlDisplayName;
071: private int displayStatuses;
072:
073: public DiffNode(Setup setup, int displayStatuses) {
074: super (Children.LEAF, Lookups.singleton(setup));
075: this .setup = setup;
076: this .displayStatuses = displayStatuses;
077: setName(setup.getBaseFile().getName());
078: initProperties();
079: refreshHtmlDisplayName();
080: }
081:
082: private void refreshHtmlDisplayName() {
083: FileInformation info = setup.getInfo();
084: int status = info.getStatus();
085: // Special treatment: Mergeable status should be annotated as Conflict in Versioning view according to UI spec
086: if (status == FileInformation.STATUS_VERSIONED_MERGE) {
087: status = FileInformation.STATUS_VERSIONED_CONFLICT;
088: }
089: htmlDisplayName = Subversion.getInstance().getAnnotator()
090: .annotateNameHtml(setup.getBaseFile().getName(), info,
091: null);
092: fireDisplayNameChange(htmlDisplayName, htmlDisplayName);
093: }
094:
095: public String getHtmlDisplayName() {
096: return htmlDisplayName;
097: }
098:
099: public Setup getSetup() {
100: return setup;
101: }
102:
103: public Action[] getActions(boolean context) {
104: if (context)
105: return null;
106: return new Action[0];
107: }
108:
109: private void initProperties() {
110: Sheet sheet = Sheet.createDefault();
111: Sheet.Set ps = Sheet.createPropertiesSet();
112:
113: ps.put(new NameProperty());
114: ps.put(new LocationProperty());
115: ps.put(new StatusProperty());
116: if (setup.getPropertyName() != null) {
117: ps.put(new PropertyNameProperty());
118: }
119:
120: sheet.put(ps);
121: setSheet(sheet);
122: }
123:
124: private abstract class DiffNodeProperty extends
125: PropertySupport.ReadOnly {
126:
127: protected DiffNodeProperty(String name, Class type,
128: String displayName, String shortDescription) {
129: super (name, type, displayName, shortDescription);
130: }
131:
132: public String toString() {
133: try {
134: return getValue().toString();
135: } catch (Exception e) {
136: Subversion.LOG.log(Level.INFO, null, e);
137: return e.getLocalizedMessage();
138: }
139: }
140: }
141:
142: private class NameProperty extends DiffNodeProperty {
143:
144: public NameProperty() {
145: super (COLUMN_NAME_NAME, String.class, COLUMN_NAME_NAME,
146: COLUMN_NAME_NAME);
147: }
148:
149: public Object getValue() throws IllegalAccessException,
150: InvocationTargetException {
151: return DiffNode.this .getName();
152: }
153: }
154:
155: private class PropertyNameProperty extends DiffNodeProperty {
156:
157: public PropertyNameProperty() {
158: super (COLUMN_NAME_PROPERTY, String.class,
159: COLUMN_NAME_PROPERTY, COLUMN_NAME_PROPERTY);
160: }
161:
162: public Object getValue() throws IllegalAccessException,
163: InvocationTargetException {
164: return setup.getPropertyName();
165: }
166: }
167:
168: private class LocationProperty extends DiffNodeProperty {
169:
170: private String location;
171:
172: public LocationProperty() {
173: super (COLUMN_NAME_LOCATION, String.class,
174: COLUMN_NAME_LOCATION, COLUMN_NAME_LOCATION);
175: try {
176: location = SvnUtils
177: .getRelativePath(setup.getBaseFile());
178: } catch (SVNClientException e) {
179: location = "";
180: }
181: setValue("sortkey", location + "\t"
182: + DiffNode.this .getName()); // NOI18N
183: }
184:
185: public Object getValue() throws IllegalAccessException,
186: InvocationTargetException {
187: return location;
188: }
189: }
190:
191: private static final String[] zeros = new String[] { "", "00", "0",
192: "" }; // NOI18N
193:
194: private class StatusProperty extends DiffNodeProperty {
195:
196: public StatusProperty() {
197: super (COLUMN_NAME_STATUS, String.class, COLUMN_NAME_STATUS,
198: COLUMN_NAME_STATUS);
199: String shortPath = null;
200: try {
201: shortPath = SvnUtils.getRelativePath(setup
202: .getBaseFile());
203: } catch (SVNClientException e) {
204: shortPath = "";
205: }
206: String sortable = Integer.toString(SvnUtils
207: .getComparableStatus(setup.getInfo().getStatus()));
208: setValue("sortkey", zeros[sortable.length()] + sortable
209: + "\t" + shortPath + "\t"
210: + DiffNode.this .getName().toUpperCase()); // NOI18N
211: }
212:
213: public Object getValue() throws IllegalAccessException,
214: InvocationTargetException {
215: FileInformation finfo = setup.getInfo();
216: finfo.getEntry(setup.getBaseFile()); // XXX not interested in return value, side effect loads ISVNStatus structure
217: return finfo.getStatusText(displayStatuses);
218: }
219: }
220: }
|