1 19 20 package org.netbeans.modules.subversion.ui.status; 21 22 import java.io.IOException ; 23 import org.openide.*; 24 import org.openide.nodes.*; 25 import org.openide.util.*; 26 import org.openide.util.lookup.Lookups; 27 import org.openide.util.actions.SystemAction; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.loaders.DataObject; 31 import org.openide.loaders.DataObjectNotFoundException; 32 import org.netbeans.modules.subversion.SvnFileNode; 33 import org.netbeans.modules.subversion.FileInformation; 34 import org.netbeans.modules.subversion.Subversion; 35 import org.netbeans.modules.subversion.ui.update.ResolveConflictsAction; 36 import org.netbeans.modules.subversion.ui.diff.DiffAction; 37 import org.netbeans.modules.subversion.util.SvnUtils; 38 39 import javax.swing.*; 40 import java.lang.reflect.InvocationTargetException ; 41 import java.io.File ; 42 43 49 public class SyncFileNode extends AbstractNode { 50 51 private SvnFileNode node; 52 53 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_BRANCH = "branch"; 58 private String htmlDisplayName; 59 60 private RequestProcessor.Task repoload; 61 62 private final VersioningPanel panel; 63 64 public SyncFileNode(SvnFileNode node, VersioningPanel _panel) { 65 this(Children.LEAF, node, _panel); 66 67 } 68 69 private SyncFileNode(Children children, SvnFileNode node, VersioningPanel _panel) { 70 super(children, Lookups.fixed(node.getLookupObjects())); 71 this.node = node; 72 this.panel = _panel; 73 initProperties(); 74 refreshHtmlDisplayName(); 75 } 76 77 public File getFile() { 78 return node.getFile(); 79 } 80 81 public FileInformation getFileInformation() { 82 return node.getInformation(); 83 } 84 85 public String getName() { 86 return node.getName(); 87 } 88 89 public Action getPreferredAction() { 90 if (node.getInformation().getStatus() == FileInformation.STATUS_VERSIONED_CONFLICT) { 91 return SystemAction.get(ResolveConflictsAction.class); 92 } 93 return SystemAction.get(DiffAction.class); 94 } 95 96 101 public Cookie getCookie(Class klass) { 102 FileObject fo = FileUtil.toFileObject(getFile()); 103 if (fo != null) { 104 try { 105 DataObject dobj = DataObject.find(fo); 106 if (fo.equals(dobj.getPrimaryFile())) { 107 return dobj.getCookie(klass); 108 } 109 } catch (DataObjectNotFoundException e) { 110 } 112 } 113 return super.getCookie(klass); 114 } 115 116 private void initProperties() { 117 if (node.getFile().isDirectory()) setIconBaseWithExtension("org/openide/loaders/defaultFolder.gif"); 119 Sheet sheet = Sheet.createDefault(); 120 Sheet.Set ps = Sheet.createPropertiesSet(); 121 122 ps.put(new NameProperty()); 123 ps.put(new PathProperty()); 124 ps.put(new StatusProperty()); 125 ps.put(new BranchProperty()); 126 127 sheet.put(ps); 128 setSheet(sheet); 129 } 130 131 private void refreshHtmlDisplayName() { 132 FileInformation info = node.getInformation(); 133 int status = info.getStatus(); 134 if (status == FileInformation.STATUS_VERSIONED_MERGE) { 136 status = FileInformation.STATUS_VERSIONED_CONFLICT; 137 } 138 htmlDisplayName = Subversion.getInstance().getAnnotator().annotateNameHtml(node.getFile().getName(), info, null); 139 fireDisplayNameChange(node.getName(), node.getName()); 140 } 141 142 public String getHtmlDisplayName() { 143 return htmlDisplayName; 144 } 145 146 public void refresh() { 147 refreshHtmlDisplayName(); 148 } 149 150 private abstract class SyncFileProperty extends org.openide.nodes.PropertySupport.ReadOnly { 151 152 protected SyncFileProperty(String name, Class type, String displayName, String shortDescription) { 153 super(name, type, displayName, shortDescription); 154 } 155 156 public String toString() { 157 try { 158 return getValue().toString(); 159 } catch (Exception e) { 160 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 161 return e.getLocalizedMessage(); 162 } 163 } 164 } 165 166 private class BranchProperty extends SyncFileProperty { 167 168 public BranchProperty() { 169 super(COLUMN_NAME_BRANCH, String .class, NbBundle.getMessage(SyncFileNode.class, "BK2001"), NbBundle.getMessage(SyncFileNode.class, "BK2002")); } 171 172 public Object getValue() { 173 String copyName = SvnUtils.getCopy(node.getFile()); 174 return copyName == null ? "" : copyName; 175 } 176 } 177 178 private class PathProperty extends SyncFileProperty { 179 180 private String shortPath; 181 182 public PathProperty() { 183 super(COLUMN_NAME_PATH, String .class, NbBundle.getMessage(SyncFileNode.class, "BK2003"), NbBundle.getMessage(SyncFileNode.class, "BK2004")); setValue("sortkey", "\u65000\t" + SyncFileNode.this.getName()); } 186 187 public Object getValue() throws IllegalAccessException , InvocationTargetException { 188 if (shortPath == null) { 189 Runnable run = new Runnable () { 190 public void run() { 191 shortPath = SvnUtils.getRelativePath(node.getFile()); 192 if (shortPath == null) { 193 shortPath = org.openide.util.NbBundle.getMessage(SyncFileNode.class, "LBL_Location_NotInRepository"); } 195 setValue("sortkey", shortPath + "\t" + SyncFileNode.this.getName()); SwingUtilities.invokeLater(new Runnable () { 198 public void run() { 199 firePropertyChange(COLUMN_NAME_PATH, null, null); 200 } 201 }); 202 } 203 }; 204 repoload = Subversion.getInstance().getRequestProcessor().post(run); 205 return org.openide.util.NbBundle.getMessage(SyncFileNode.class, "LBL_RepositoryPath_LoadingProgress"); } 207 return shortPath; 208 } 209 } 210 211 public void destroy() throws IOException { 213 super.destroy(); 214 if (repoload != null) { 215 repoload.cancel(); 216 } 217 } 218 219 private class NameProperty extends SyncFileProperty { 220 221 public NameProperty() { 222 super(COLUMN_NAME_NAME, String .class, NbBundle.getMessage(SyncFileNode.class, "BK2005"), NbBundle.getMessage(SyncFileNode.class, "BK2006")); setValue("sortkey", SyncFileNode.this.getName()); } 225 226 public Object getValue() throws IllegalAccessException , InvocationTargetException { 227 return SyncFileNode.this.getDisplayName(); 228 } 229 } 230 231 private static final String [] zeros = new String [] { "", "00", "0", "" }; 233 private class StatusProperty extends SyncFileProperty { 234 235 public StatusProperty() { 236 super(COLUMN_NAME_STATUS, String .class, NbBundle.getMessage(SyncFileNode.class, "BK2007"), NbBundle.getMessage(SyncFileNode.class, "BK2008")); String shortPath = "path"; String sortable = Integer.toString(SvnUtils.getComparableStatus(node.getInformation().getStatus())); 239 setValue("sortkey", zeros[sortable.length()] + sortable + "\t" + shortPath + "\t" + SyncFileNode.this.getName()); } 241 242 public Object getValue() throws IllegalAccessException , InvocationTargetException { 243 FileInformation finfo = node.getInformation(); 244 finfo.getEntry(node.getFile()); int mask = panel.getDisplayStatuses(); 246 return finfo.getStatusText(mask); 247 } 248 } 249 } 250 | Popular Tags |