1 19 package org.netbeans.modules.versioning.system.cvss.ui.actions.update; 20 21 import org.openide.nodes.*; 22 import org.openide.util.NbBundle; 23 import org.openide.filesystems.FileObject; 24 import org.openide.filesystems.FileUtil; 25 import org.openide.loaders.DataObject; 26 import org.openide.loaders.DataObjectNotFoundException; 27 import org.openide.ErrorManager; 28 import org.netbeans.modules.versioning.system.cvss.util.Utils; 29 import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer; 30 31 import java.lang.reflect.InvocationTargetException ; 32 import java.text.MessageFormat ; 33 34 39 class UpdateResultNode extends AbstractNode { 40 41 private DefaultFileInfoContainer info; 42 43 static final String COLUMN_NAME_NAME = "name"; static final String COLUMN_NAME_PATH = "path"; static final String COLUMN_NAME_STATUS = "status"; 47 private final MessageFormat conflictFormat = new MessageFormat ("<font color=\"#FF0000\">{0}</font>"); private final MessageFormat updatedFormat = new MessageFormat ("<font color=\"#0000FF\">{0}</font>"); 50 private String statusDisplayName; 51 private String htmlDisplayName; 52 53 public UpdateResultNode(DefaultFileInfoContainer info) { 54 super(Children.LEAF); 55 this.info = info; 56 initProperties(); 57 refreshHtmlDisplayName(); 58 } 59 60 public DefaultFileInfoContainer getInfo() { 61 return info; 62 } 63 64 public String getName() { 65 return info.getFile().getName(); 66 } 67 68 73 public <T extends Node.Cookie> T getCookie(Class <T> klass) { 74 FileObject fo = FileUtil.toFileObject(info.getFile()); 75 if (fo != null) { 76 try { 77 DataObject dobj = DataObject.find(fo); 78 if (fo.equals(dobj.getPrimaryFile())) { 79 return dobj.getCookie(klass); 80 } 81 } catch (DataObjectNotFoundException e) { 82 } 84 } 85 return super.getCookie(klass); 86 } 87 88 private void initProperties() { 89 Sheet sheet = Sheet.createDefault(); 90 Sheet.Set ps = Sheet.createPropertiesSet(); 91 92 ps.put(new UpdateResultNode.NameProperty()); 93 ps.put(new UpdateResultNode.PathProperty()); 94 ps.put(new UpdateResultNode.StatusProperty()); 95 96 sheet.put(ps); 97 setSheet(sheet); 98 } 99 100 private void refreshHtmlDisplayName() { 101 if (isConflict()) { 102 htmlDisplayName = conflictFormat.format(new Object [] { getName() }); 103 statusDisplayName = NbBundle.getMessage(UpdateResultNode.class, "LBL_Status_Conflict"); } else if (isRemoved()) { 105 htmlDisplayName = getName(); 106 statusDisplayName = NbBundle.getMessage(UpdateResultNode.class, "LBL_Status_Removed"); } else if (isUpdated()) { 108 htmlDisplayName = updatedFormat.format(new Object [] { getName() }); 109 statusDisplayName = NbBundle.getMessage(UpdateResultNode.class, "LBL_Status_Updated"); } else { 111 throw new IllegalStateException ("Unhandled update type: " + info.getType()); } 113 fireDisplayNameChange(htmlDisplayName, htmlDisplayName); 114 } 115 116 public String getHtmlDisplayName() { 117 return htmlDisplayName; 118 } 119 120 private boolean isUpdated() { 121 return "UPG".indexOf(info.getType()) != -1; } 123 124 private boolean isRemoved() { 125 return DefaultFileInfoContainer.PERTINENT_STATE.equals(info.getType()); 126 } 127 128 private boolean isConflict() { 129 return "C".equals(info.getType()); } 131 132 public void refresh() { 133 refreshHtmlDisplayName(); 134 } 135 136 private abstract class SyncFileProperty extends PropertySupport.ReadOnly<String > { 137 138 protected SyncFileProperty(String name, Class <String > type, String displayName, String shortDescription) { 139 super(name, type, displayName, shortDescription); 140 } 141 142 public String toString() { 143 try { 144 return getValue(); 145 } catch (Exception e) { 146 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 147 return e.getLocalizedMessage(); 148 } 149 } 150 } 151 152 private class PathProperty extends UpdateResultNode.SyncFileProperty { 153 154 private String shortPath; 155 156 public PathProperty() { 157 super(COLUMN_NAME_PATH, String .class, NbBundle.getMessage(UpdateResultNode.class, "LBL_Path_Name"), NbBundle.getMessage(UpdateResultNode.class, "LBL_Path_Desc")); shortPath = Utils.getRelativePath(info.getFile()); 159 setValue("sortkey", shortPath + "\t" + UpdateResultNode.this.getName()); } 161 162 public String getValue() throws IllegalAccessException , InvocationTargetException { 163 return shortPath; 164 } 165 } 166 167 private class NameProperty extends UpdateResultNode.SyncFileProperty { 168 169 public NameProperty() { 170 super(COLUMN_NAME_NAME, String .class, NbBundle.getMessage(UpdateResultNode.class, "LBL_Name_Name"), NbBundle.getMessage(UpdateResultNode.class, "LBL_Name_Desc")); setValue("sortkey", UpdateResultNode.this.getName()); } 173 174 public String getValue() throws IllegalAccessException , InvocationTargetException { 175 return UpdateResultNode.this.getDisplayName(); 176 } 177 } 178 179 private final String [] zeros = new String [] { "", "00", "0", "" }; 181 private class StatusProperty extends UpdateResultNode.SyncFileProperty { 182 183 public StatusProperty() { 184 super(COLUMN_NAME_STATUS, String .class, NbBundle.getMessage(UpdateResultNode.class, "LBL_Status_Name"), NbBundle.getMessage(UpdateResultNode.class, "LBL_Status_Desc")); String shortPath = Utils.getRelativePath(info.getFile()); 186 String sortable = info.getType(); 187 setValue("sortkey", zeros[sortable.length()] + sortable + "\t" + shortPath + "\t" + UpdateResultNode.this.getName()); } 189 190 public String getValue() throws IllegalAccessException , InvocationTargetException { 191 return statusDisplayName; 192 } 193 } 194 } 195 | Popular Tags |