1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.history; 21 22 import org.openide.*; 23 import org.openide.nodes.*; 24 import org.openide.util.lookup.Lookups; 25 import org.openide.util.NbBundle; 26 import org.netbeans.lib.cvsclient.command.log.LogInformation; 27 import org.netbeans.modules.versioning.system.cvss.ui.actions.log.SearchHistoryAction; 28 import org.netbeans.modules.versioning.system.cvss.ui.actions.update.GetCleanAction; 29 import org.netbeans.modules.versioning.system.cvss.util.Utils; 30 import org.netbeans.modules.versioning.system.cvss.util.Context; 31 import org.netbeans.modules.versioning.system.cvss.VersionsCache; 32 import org.netbeans.api.project.Project; 33 import org.netbeans.api.project.ProjectUtils; 34 import org.netbeans.api.project.ui.OpenProjects; 35 36 import javax.swing.*; 37 import java.lang.reflect.InvocationTargetException ; 38 import java.awt.event.ActionEvent ; 39 import java.awt.*; 40 import java.io.File ; 41 import java.beans.PropertyEditor ; 42 import java.beans.PropertyEditorSupport ; 43 import java.util.*; 44 import java.util.List ; 45 import java.text.DateFormat ; 46 47 52 class RevisionNode extends AbstractNode { 53 54 static final String COLUMN_NAME_NAME = "name"; static final String COLUMN_NAME_LOCATION = "location"; static final String COLUMN_NAME_DATE = "date"; static final String COLUMN_NAME_USERNAME = "username"; static final String COLUMN_NAME_TAGS = "tags"; static final String COLUMN_NAME_MESSAGE = "message"; 61 private SearchHistoryPanel.DispRevision revision; 62 private SearchHistoryPanel.ResultsContainer container; 63 private String path; 64 65 public RevisionNode(SearchHistoryPanel.ResultsContainer container) { 66 super(new RevisionNodeChildren(container), Lookups.singleton(container)); 67 this.container = container; 68 this.revision = null; 69 this.path = container.getPath(); 70 setName(((SearchHistoryPanel.DispRevision) container.getRevisions().get(0)).getRevision().getLogInfoHeader().getFile().getName()); 71 initProperties(); 72 } 73 74 public RevisionNode(SearchHistoryPanel.DispRevision revision) { 75 super(revision.getChildren() == null ? Children.LEAF : new RevisionNodeChildren(revision), Lookups.fixed(revision)); 76 this.path = revision.getPath(); 77 this.revision = revision; 78 if (revision.getRevision().getNumber() == VersionsCache.REVISION_CURRENT) { 79 setName(NbBundle.getMessage(DiffResultsView.class, "LBL_DiffPanel_LocalCopy")); } else if (revision.isBranchRoot()) { 81 if (revision.getBranchName() != null) { 82 setName(revision.getRevision().getNumber() + " - " + revision.getBranchName()); } else { 84 setName(revision.getRevision().getNumber()); 85 } 86 } else { 87 setName(revision.getRevision().getNumber()); 88 } 89 initProperties(); 90 } 91 92 SearchHistoryPanel.DispRevision getDispRevision() { 93 return revision; 94 } 95 96 LogInformation.Revision getRevision() { 97 return revision.getRevision(); 98 } 99 100 SearchHistoryPanel.ResultsContainer getContainer() { 101 return container; 102 } 103 104 public String getShortDescription() { 105 return path; 106 } 107 108 public Action[] getActions(boolean context) { 109 if (context) return null; 110 if (revision == null || revision.getRevision().getNumber() == VersionsCache.REVISION_CURRENT) { 112 return new Action [0]; 113 } else { 114 return new Action [] { 115 new RollbackAction(), 116 new RollbackChangeAction(), 117 new FindCommitAction(false), 118 new FindCommitAction(true), 119 }; 120 } 121 } 122 123 private void initProperties() { 124 Sheet sheet = Sheet.createDefault(); 125 Sheet.Set ps = Sheet.createPropertiesSet(); 126 127 ps.put(new LocationProperty()); 128 ps.put(new DateProperty()); 129 ps.put(new UsernameProperty()); 130 ps.put(new TagsProperty()); 131 ps.put(new MessageProperty()); 132 133 sheet.put(ps); 134 setSheet(sheet); 135 } 136 137 private abstract class CommitNodeProperty extends PropertySupport.ReadOnly { 138 139 protected CommitNodeProperty(String name, Class type, String displayName, String shortDescription) { 140 super(name, type, displayName, shortDescription); 141 } 142 143 public String toString() { 144 try { 145 return getValue().toString(); 146 } catch (Exception e) { 147 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 148 return e.getLocalizedMessage(); 149 } 150 } 151 152 public PropertyEditor getPropertyEditor() { 153 try { 154 return new RevisionPropertyEditor((String ) getValue()); 155 } catch (Exception e) { 156 return super.getPropertyEditor(); 157 } 158 } 159 } 160 161 private class LocationProperty extends CommitNodeProperty { 162 163 public LocationProperty() { 164 super(COLUMN_NAME_LOCATION, String .class, COLUMN_NAME_LOCATION, COLUMN_NAME_LOCATION); 165 } 166 167 public Object getValue() throws IllegalAccessException , InvocationTargetException { 168 if (container != null) { 169 return path; 170 } else { 171 return ""; } 173 } 174 } 175 176 private class UsernameProperty extends CommitNodeProperty { 177 178 public UsernameProperty() { 179 super(COLUMN_NAME_USERNAME, String .class, COLUMN_NAME_USERNAME, COLUMN_NAME_USERNAME); 180 } 181 182 public Object getValue() throws IllegalAccessException , InvocationTargetException { 183 if (revision != null) { 184 return revision.getRevision().getAuthor(); 185 } else { 186 return ""; } 188 } 189 } 190 191 private class DateProperty extends CommitNodeProperty { 192 193 private String dateString; 194 195 public DateProperty() { 196 super(COLUMN_NAME_DATE, String .class, COLUMN_NAME_DATE, COLUMN_NAME_DATE); 197 dateString = (revision == null || revision.getRevision().getDate() == null) ? "" : DateFormat.getDateTimeInstance().format(revision.getRevision().getDate()); } 199 200 public Object getValue() throws IllegalAccessException , InvocationTargetException { 201 return dateString; 202 } 203 } 204 205 private class TagsProperty extends CommitNodeProperty { 206 207 public TagsProperty() { 208 super(COLUMN_NAME_TAGS, List .class, COLUMN_NAME_TAGS, COLUMN_NAME_TAGS); 209 if (revision != null) setValue("dispRevision", revision); } 211 212 public Object getValue() throws IllegalAccessException , InvocationTargetException { 213 return null; } 215 216 public PropertyEditor getPropertyEditor() { 217 try { 218 return new TagsPropertyEditor(revision); 219 } catch (Exception e) { 220 return super.getPropertyEditor(); 221 } 222 } 223 } 224 225 private class MessageProperty extends CommitNodeProperty { 226 227 public MessageProperty() { 228 super(COLUMN_NAME_MESSAGE, String .class, COLUMN_NAME_MESSAGE, COLUMN_NAME_MESSAGE); 229 } 230 231 public Object getValue() throws IllegalAccessException , InvocationTargetException { 232 if (revision != null) { 233 return revision.getRevision().getMessage(); 234 } else { 235 return ""; } 237 } 238 } 239 240 private class FindCommitAction extends AbstractAction { 241 242 private boolean allProjects; 243 244 public FindCommitAction(boolean allProjects) { 245 this.allProjects = allProjects; 246 if (allProjects) { 247 putValue(Action.NAME, NbBundle.getMessage(RevisionNode.class, "CTL_Action_FindCommitInProjects")); } else { 249 File file = revision.getRevision().getLogInfoHeader().getFile(); 250 Project project = Utils.getProject(file); 251 if (project != null) { 252 String prjName = ProjectUtils.getInformation(project).getDisplayName(); 253 putValue(Action.NAME, NbBundle.getMessage(RevisionNode.class, "CTL_Action_FindCommitInProject", prjName)); } else { 255 putValue(Action.NAME, NbBundle.getMessage(RevisionNode.class, "CTL_Action_FindCommit")); setEnabled(false); 257 } 258 } 259 } 260 261 public void actionPerformed(ActionEvent e) { 262 File file = revision.getRevision().getLogInfoHeader().getFile(); 263 if (allProjects) { 264 Project [] projects = OpenProjects.getDefault().getOpenProjects(); 265 int n = projects.length; 266 SearchHistoryAction.openSearch( 267 (n == 1) ? ProjectUtils.getInformation(projects[0]).getDisplayName() : 268 NbBundle.getMessage(SummaryView.class, "CTL_FindAssociateChanges_OpenProjects_Title", Integer.toString(n)), revision.getRevision().getMessage().trim(), revision.getRevision().getAuthor(), revision.getRevision().getDate()); 270 } else { 271 Project project = Utils.getProject(file); 272 Context context = Utils.getProjectsContext(new Project[] { project }); 273 SearchHistoryAction.openSearch( 274 context, 275 ProjectUtils.getInformation(project).getDisplayName(), 276 revision.getRevision().getMessage().trim(), revision.getRevision().getAuthor(), revision.getRevision().getDate()); 277 } 278 } 279 } 280 281 private class RollbackAction extends AbstractAction { 282 283 public RollbackAction() { 284 putValue(Action.NAME, NbBundle.getMessage(RevisionNode.class, "CTL_Action_RollbackTo", revision.getRevision().getNumber())); } 286 287 public void actionPerformed(ActionEvent e) { 288 File file = revision.getRevision().getLogInfoHeader().getFile(); 289 GetCleanAction.rollback(file, revision.getRevision().getNumber()); 290 } 291 } 292 293 private class RollbackChangeAction extends AbstractAction { 294 295 public RollbackChangeAction() { 296 putValue(Action.NAME, NbBundle.getMessage(RevisionNode.class, "CTL_Action_RollbackChange")); setEnabled(Utils.previousRevision(revision.getRevision().getNumber()) != null); 298 } 299 300 public void actionPerformed(ActionEvent e) { 301 SummaryView.rollbackChanges(new LogInformation.Revision [] { revision.getRevision() }); 302 } 303 } 304 305 private static class RevisionPropertyEditor extends PropertyEditorSupport { 306 307 private static final JLabel renderer = new JLabel(); 308 309 static { 310 renderer.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); 311 } 312 313 public RevisionPropertyEditor(String value) { 314 setValue(value); 315 } 316 317 public void paintValue(Graphics gfx, Rectangle box) { 318 renderer.setForeground(gfx.getColor()); 319 renderer.setText((String ) getValue()); 320 renderer.setBounds(box); 321 renderer.paint(gfx); 322 } 323 324 public boolean isPaintable() { 325 return true; 326 } 327 } 328 329 private static class TagsPropertyEditor extends PropertyEditorSupport { 330 331 private static final JLabel renderer = new JLabel(); 332 333 private SearchHistoryPanel.DispRevision dispRevision; 334 335 static { 336 renderer.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); 337 } 338 339 public TagsPropertyEditor(SearchHistoryPanel.DispRevision revision) { 340 this.dispRevision = revision; 341 } 342 343 public boolean isPaintable() { 344 return true; 345 } 346 347 public void paintValue(Graphics gfx, Rectangle box) { 348 renderer.setForeground(gfx.getColor()); 349 renderer.setBounds(box); 350 351 if (dispRevision == null || dispRevision.getBranches() == null) { 352 renderer.setText(""); } else { 354 List <String > tags = new ArrayList<String >(dispRevision.getBranches()); 355 tags.addAll(dispRevision.getTags()); 356 if (tags.size() > 0) { 357 String tagInfo = "<html>" + tags.get(0); if (tags.size() > 1) { 359 tagInfo += ","; Color foreground = UIManager.getColor("List.selectionForeground"); if (!gfx.getColor().equals(foreground)) { 362 tagInfo += " <a HREF=\"\">...</a>"; } else { 364 StringBuilder sb = new StringBuilder (); 365 sb.append(" <a HREF=\"\" style=\"color:"); sb.append("rgb("); sb.append(foreground.getRed()); 368 sb.append(","); sb.append(foreground.getGreen()); 370 sb.append(","); sb.append(foreground.getBlue()); 372 sb.append(")"); sb.append("\">"); sb.append("..."); sb.append("</a>"); tagInfo += sb.toString(); 377 } 378 } 379 renderer.setText(tagInfo); 380 } else { 381 renderer.setText(""); } 383 } 384 renderer.paint(gfx); 385 } 386 } 387 } 388 | Popular Tags |