1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.syncview; 21 22 import org.openide.*; 23 import org.openide.nodes.*; 24 import org.openide.util.*; 25 import org.openide.util.lookup.Lookups; 26 import org.openide.util.actions.SystemAction; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.FileUtil; 29 import org.openide.loaders.DataObject; 30 import org.openide.loaders.DataObjectNotFoundException; 31 import org.netbeans.modules.versioning.system.cvss.*; 32 import org.netbeans.modules.versioning.system.cvss.util.Utils; 33 import org.netbeans.modules.versioning.system.cvss.ui.actions.diff.DiffAction; 34 import org.netbeans.modules.versioning.system.cvss.ui.actions.diff.ResolveConflictsAction; 35 36 import javax.swing.*; 37 import java.lang.reflect.InvocationTargetException ; 38 import java.io.File ; 39 40 46 public class SyncFileNode extends AbstractNode { 47 48 private CvsFileNode node; 49 50 static final String COLUMN_NAME_NAME = "name"; static final String COLUMN_NAME_PATH = "path"; static final String COLUMN_NAME_STATUS = "status"; static final String COLUMN_NAME_STICKY = "sticky"; 55 private String htmlDisplayName; 56 private String sticky; 57 58 public SyncFileNode(CvsFileNode node) { 59 this(Children.LEAF, node); 60 } 61 62 private SyncFileNode(Children children, CvsFileNode node) { 63 super(children, Lookups.fixed(node.getLookupObjects())); 64 this.node = node; 65 initProperties(); 66 refreshHtmlDisplayName(); 67 } 68 69 public File getFile() { 70 return node.getFile(); 71 } 72 73 public FileInformation getFileInformation() { 74 return node.getInformation(); 75 } 76 77 public String getName() { 78 return node.getName(); 79 } 80 81 public Action getPreferredAction() { 82 if (node.getInformation().getStatus() == FileInformation.STATUS_VERSIONED_CONFLICT) { 83 return SystemAction.get(ResolveConflictsAction.class); 84 } 85 return SystemAction.get(DiffAction.class); 86 } 87 88 93 public Cookie getCookie(Class klass) { 94 FileObject fo = FileUtil.toFileObject(getFile()); 95 if (fo != null) { 96 try { 97 DataObject dobj = DataObject.find(fo); 98 if (fo.equals(dobj.getPrimaryFile())) { 99 return dobj.getCookie(klass); 100 } 101 } catch (DataObjectNotFoundException e) { 102 } 104 } 105 return super.getCookie(klass); 106 } 107 108 private void initProperties() { 109 if (node.getFile().isDirectory()) setIconBaseWithExtension("org/openide/loaders/defaultFolder.gif"); 111 Sheet sheet = Sheet.createDefault(); 112 Sheet.Set ps = Sheet.createPropertiesSet(); 113 114 ps.put(new NameProperty()); 115 ps.put(new PathProperty()); 116 ps.put(new StatusProperty()); 117 ps.put(new StickyProperty()); 118 119 sheet.put(ps); 120 setSheet(sheet); 121 } 122 123 private void refreshHtmlDisplayName() { 124 FileInformation info = node.getInformation(); 125 int status = info.getStatus(); 126 if (status == FileInformation.STATUS_VERSIONED_MERGE) { 128 status = FileInformation.STATUS_VERSIONED_CONFLICT; 129 } 130 htmlDisplayName = CvsVersioningSystem.getInstance().getAnnotator().annotateNameHtml(node.getFile().getName(), info, null); 131 fireDisplayNameChange(node.getName(), node.getName()); 132 } 133 134 public String getHtmlDisplayName() { 135 return htmlDisplayName; 136 } 137 138 public void refresh() { 139 refreshHtmlDisplayName(); 140 } 141 142 147 public String getSticky() { 148 if (sticky == null) { 149 if ((sticky = Utils.getSticky(node.getFile())) == null) { 150 sticky = ""; } else { 152 sticky = sticky.substring(1); 153 } 154 } 155 return sticky == null || sticky.length() == 0 ? "" : sticky; } 157 158 private abstract class SyncFileProperty extends PropertySupport.ReadOnly { 159 160 protected SyncFileProperty(String name, Class type, String displayName, String shortDescription) { 161 super(name, type, displayName, shortDescription); 162 } 163 164 public String toString() { 165 try { 166 return getValue().toString(); 167 } catch (Exception e) { 168 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 169 return e.getLocalizedMessage(); 170 } 171 } 172 } 173 174 private class StickyProperty extends SyncFileProperty { 175 176 public StickyProperty() { 177 super(COLUMN_NAME_STICKY, String .class, NbBundle.getMessage(SyncFileNode.class, "BK2001"), NbBundle.getMessage(SyncFileNode.class, "BK2002")); 178 } 179 180 public Object getValue() { 181 return getSticky(); 182 } 183 } 184 185 private class PathProperty extends SyncFileProperty { 186 187 private String shortPath; 188 189 public PathProperty() { 190 super(COLUMN_NAME_PATH, String .class, NbBundle.getMessage(SyncFileNode.class, "BK2003"), NbBundle.getMessage(SyncFileNode.class, "BK2004")); 191 shortPath = Utils.getRelativePath(node.getFile()); 192 setValue("sortkey", shortPath + "\t" + SyncFileNode.this.getName()); } 194 195 public Object getValue() throws IllegalAccessException , InvocationTargetException { 196 return shortPath; 197 } 198 } 199 200 private class NameProperty extends SyncFileProperty { 201 202 public NameProperty() { 203 super(COLUMN_NAME_NAME, String .class, NbBundle.getMessage(SyncFileNode.class, "BK2005"), NbBundle.getMessage(SyncFileNode.class, "BK2006")); 204 setValue("sortkey", SyncFileNode.this.getName()); } 206 207 public Object getValue() throws IllegalAccessException , InvocationTargetException { 208 return SyncFileNode.this.getDisplayName(); 209 } 210 } 211 212 private static final String [] zeros = new String [] { "", "00", "0", "" }; 214 private class StatusProperty extends SyncFileProperty { 215 216 public StatusProperty() { 217 super(COLUMN_NAME_STATUS, String .class, NbBundle.getMessage(SyncFileNode.class, "BK2007"), NbBundle.getMessage(SyncFileNode.class, "BK2008")); 218 String shortPath = Utils.getRelativePath(node.getFile()); 219 String sortable = Integer.toString(Utils.getComparableStatus(node.getInformation().getStatus())); 220 setValue("sortkey", zeros[sortable.length()] + sortable + "\t" + shortPath + "\t" + SyncFileNode.this.getName()); } 222 223 public Object getValue() throws IllegalAccessException , InvocationTargetException { 224 return node.getInformation().getStatusText(); 225 } 226 } 227 } 228 | Popular Tags |