1 17 18 package org.netbeans.lib.uihandler; 19 20 import java.util.logging.LogRecord ; 21 22 27 public final class ProjectOp { 28 private final String name; 29 private final String type; 30 private final int number; 31 32 private ProjectOp(String name, String type, int number) { 33 this.name = fixName(name, true); 34 this.type = fixName(type, false); 35 this.number = number; 36 } 37 38 private static String fixName(String name, boolean nameOrType) { 39 if (nameOrType && name.indexOf("Maven") >= 0) { 40 return "Maven"; 41 } 42 return name; 43 } 44 45 47 public String getProjectDisplayName() { 48 return name; 49 } 50 51 53 public String getProjectType() { 54 return type; 55 } 56 57 60 public int getDelta() { 61 return number; 62 } 63 64 68 public static ProjectOp valueOf(LogRecord rec) { 69 if ("UI_CLOSED_PROJECTS".equals(rec.getMessage())) { 70 String type = getStringParam(rec, 0, "unknown"); String name = getStringParam(rec, 1, "unknown"); int cnt = Integer.parseInt(getStringParam(rec, 2, "0")); 73 return new ProjectOp(name, type, -cnt); 74 } 75 if ("UI_OPEN_PROJECTS".equals(rec.getMessage())) { 76 String type = getStringParam(rec, 0, "unknown"); String name = getStringParam(rec, 1, "unknown"); int cnt = Integer.parseInt(getStringParam(rec, 2, "0")); 79 return new ProjectOp(name, type, cnt); 80 } 81 return null; 82 } 83 84 private static String getStringParam(LogRecord rec, int index, String def) { 85 if (rec == null) { 86 return def; 87 } 88 Object [] params = rec.getParameters(); 89 if (params == null || params.length <= index) { 90 return def; 91 } 92 if (params[index] instanceof String ) { 93 return (String )params[index]; 94 } 95 return def; 96 } 97 } 98 | Popular Tags |