diff -r 477240a96fc6 junit/src/org/netbeans/modules/junit/output/Bundle.properties --- a/junit/src/org/netbeans/modules/junit/output/Bundle.properties Mon Jun 30 14:32:33 2008 +0200 +++ b/junit/src/org/netbeans/modules/junit/output/Bundle.properties Thu Jul 03 13:41:19 2008 +0200 @@ -1,6 +1,6 @@ # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. # -# Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. +# Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved. # # The contents of this file are subject to the terms of either the GNU # General Public License Version 2 only ("GPL") or the Common @@ -23,7 +23,7 @@ # Contributor(s): # # The Original Software is NetBeans. The Initial Developer of the Original -# Software is Sun Microsystems, Inc. Portions Copyright 2006-2007 Sun +# Software is Sun Microsystems, Inc. Portions Copyright 2006-2008 Sun # Microsystems, Inc. All Rights Reserved. # # If you wish your version of this file to be governed by only the CDDL @@ -89,9 +89,13 @@ # {0} .. name of the test method MSG_TestMethodFailed={0} - FAILED MSG_TestMethodError={0} - caused an ERROR +MSG_TestMethodRunning={0} - running... +MSG_TestMethodInterrupted={0} - interrupted MSG_TestMethodPassed_HTML=passed MSG_TestMethodFailed_HTML=FAILED MSG_TestMethodError_HTML=caused an ERROR +MSG_TestMethodRunning_HTML=running... +MSG_TestMethodInterrupted_HTML=interrupted # {0} .. name of the test method, {1} .. elapsed time in seconds MSG_TestMethodPassed_time={0} ({1,number,0.0##} s) diff -r 477240a96fc6 junit/src/org/netbeans/modules/junit/output/JUnitOutputReader.java --- a/junit/src/org/netbeans/modules/junit/output/JUnitOutputReader.java Mon Jun 30 14:32:33 2008 +0200 +++ b/junit/src/org/netbeans/modules/junit/output/JUnitOutputReader.java Thu Jul 03 13:41:19 2008 +0200 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common @@ -75,8 +75,9 @@ import static java.util.Calendar.MILLISECOND; import static java.util.logging.Level.FINER; import static java.util.logging.Level.FINEST; +import static org.netbeans.modules.junit.output.RegexpUtils.ADD_ERROR_PREFIX; +import static org.netbeans.modules.junit.output.RegexpUtils.ADD_FAILURE_PREFIX; import static org.netbeans.modules.junit.output.RegexpUtils.END_OF_TEST_PREFIX; -import static org.netbeans.modules.junit.output.RegexpUtils.NESTED_EXCEPTION_PREFIX; import static org.netbeans.modules.junit.output.RegexpUtils.OUTPUT_DELIMITER_PREFIX; import static org.netbeans.modules.junit.output.RegexpUtils.START_OF_TEST_PREFIX; import static org.netbeans.modules.junit.output.RegexpUtils.TESTCASE_PREFIX; @@ -107,6 +108,11 @@ private static final String XML_FORMATTER_CLASS_NAME = "org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter";//NOI18N + /** + * Does Ant provide detailed information about the currently running test + * and its output? + */ + private boolean testListenerInfoAvailable = false; /** * number of tests to be executed in the current test suite * @@ -172,8 +178,8 @@ /** */ private RegexpUtils regexp = RegexpUtils.getInstance(); - /** */ - private Report topReport; + ///** */ + //private Report topReport; /** */ private Report report; /** */ @@ -236,6 +242,10 @@ progressLogger.finest("VERBOSE: " + msg); //NOI18N } if (msg.startsWith(TEST_LISTENER_PREFIX)) { + if (report == null) { + return; + } + testListenerInfoAvailable = true; String testListenerMsg = msg.substring(TEST_LISTENER_PREFIX.length()); if (testListenerMsg.startsWith(TESTS_COUNT_PREFIX)) { String countStr = testListenerMsg.substring(TESTS_COUNT_PREFIX.length()); @@ -252,27 +262,98 @@ } return; } - if (testListenerMsg.startsWith(START_OF_TEST_PREFIX)) { + + int leftBracketIndex = testListenerMsg.indexOf('('); + if (leftBracketIndex == -1) { + return; + } + + final String shortMsg = testListenerMsg.substring(0, leftBracketIndex); + if (shortMsg.equals(START_OF_TEST_PREFIX)) { + boolean testStarted = false; String restOfMsg = testListenerMsg.substring(START_OF_TEST_PREFIX.length()); - if ((restOfMsg.length() == 0) - || !Character.isLetterOrDigit(restOfMsg.charAt(0))) { + if (restOfMsg.length() == 0) { + testStarted = true; + } else { + char firstChar = restOfMsg.charAt(0); + char lastChar = restOfMsg.charAt(restOfMsg.length() - 1); + if ((firstChar == '(') && (lastChar == ')')) { + testcase = new Report.Testcase(); + testcase.name = restOfMsg.substring(1, restOfMsg.length() - 1); + testcase.timeMillis = Report.Testcase.NOT_FINISHED_YET; + testStarted = true; + } else if (!Character.isLetterOrDigit(firstChar)) { + testStarted = true; + } + } + if (testStarted) { progressLogger.finest("test started"); //NOI18N } return; } - if (testListenerMsg.startsWith(END_OF_TEST_PREFIX)) { + if (shortMsg.equals(END_OF_TEST_PREFIX)) { + boolean testFinished = false; String restOfMsg = testListenerMsg.substring(END_OF_TEST_PREFIX.length()); - if ((restOfMsg.length() == 0) - || !Character.isLetterOrDigit(restOfMsg.charAt(0))) { - progressLogger.finest("test finished"); //NOI18N + if (restOfMsg.length() == 0) { + testFinished = true; + } else { + char firstChar = restOfMsg.charAt(0); + char lastChar = restOfMsg.charAt(restOfMsg.length() - 1); + if ((firstChar == '(') && (lastChar == ')')) { + String name = restOfMsg.substring(1, restOfMsg.length() - 1); + if (name.equals(testcase.name)) { + testFinished = true; + } + } else if (!Character.isLetterOrDigit(firstChar)) { + testFinished = true; + } + } + if (testFinished) { + if (testcase != null) { + testcase.timeMillis = Report.Testcase.TIME_UNKNOWN; + report.reportTest(testcase); + testcase = null; + } executedOneSuiteTests++; if (expectedOneSuiteTests < executedOneSuiteTests) { expectedOneSuiteTests = executedOneSuiteTests; } + progressLogger.finest("test finished"); //NOI18N updateProgress(); } return; } + if (shortMsg.equals(ADD_FAILURE_PREFIX) + || shortMsg.equals(ADD_ERROR_PREFIX)) { + if (testcase == null) { + return; + } + int lastCharIndex = testListenerMsg.length() - 1; + if (testListenerMsg.charAt(lastCharIndex) != ')') { + return; + } + String insideBrackets = testListenerMsg.substring( + shortMsg.length() + 1, + lastCharIndex); + int commaIndex = insideBrackets.indexOf(','); + String testName = (commaIndex == -1) + ? insideBrackets + : insideBrackets.substring(0, commaIndex); + if (!testName.equals(testcase.className)) { + return; + } + testcase.trouble = new Report.Trouble(shortMsg.equals(ADD_ERROR_PREFIX)); + if (commaIndex != -1) { + int errMsgStart; + if (Character.isSpaceChar(insideBrackets.charAt(commaIndex + 1))) { + errMsgStart = commaIndex + 2; + } else { + errMsgStart = commaIndex + 1; + } + testcase.trouble.message = insideBrackets.substring(errMsgStart); + } + } + return; } /* Look for classpaths: */ @@ -312,6 +393,13 @@ progressLogger.finest("NORMAL: " + msg); //NOI18N } + if (testListenerInfoAvailable + && (report != null) && !report.isSuiteFinished() + && (testcase != null)) { + displayOutput(msg, event.getLogLevel() == AntEvent.LOG_WARN); + return; + } + // if (waitingForIssueStatus) { assert testcase != null; @@ -433,6 +521,7 @@ if (matcher.matches()) { assert report != null; + report.markSuiteFinished(); try { report.totalTests = Integer.parseInt(matcher.group(1)); report.failures = Integer.parseInt(matcher.group(2)); @@ -457,7 +546,7 @@ } // // - else { + else if (!testListenerInfoAvailable) { displayOutput(msg, event.getLogLevel() == AntEvent.LOG_WARN); } @@ -736,18 +825,12 @@ // isDeterminateProgress = willBeDeterminateProgress; - Manager.getInstance().testStarted(session, - sessionType); + manager.testStarted(session, sessionType); } /** */ void testTaskFinished() { - if (waitingForIssueStatus) { - assert testcase != null; - - report.reportTest(testcase); - } closePreviousReport(); progressLogger.finer("ACTUAL # OF SUITES: " + executedSuitesCount); @@ -869,8 +952,12 @@ void buildFinished(final AntEvent event) { try { buildFinished(event.getException()); - Manager.getInstance().sessionFinished(session, - sessionType); + + if (report != null) { + closePreviousReport(true); //true ... interrupted + } + + manager.sessionFinished(session, sessionType); } finally { progressHandle.finish(); } @@ -898,21 +985,19 @@ progressHandle.progress(stepMessage); } - Manager.getInstance().displaySuiteRunning(session, - sessionType, - suiteName); + manager.displaySuiteRunning(session, sessionType, suiteName); return report; } /** */ - private void suiteFinished(final Report report) { + private void suiteFinished(final Report report, boolean interrupted) { if (progressLogger.isLoggable(FINER)) { progressLogger.finer("actual # of tests in a suite: " + executedOneSuiteTests); } executedSuitesCount++; - Manager.getInstance().displayReport(session, sessionType, report); + manager.displayReport(session, sessionType, report); } private void buildFinished(final Throwable exception) { @@ -951,7 +1036,7 @@ /** */ private void displayOutput(final String text, final boolean error) { - Manager.getInstance().displayOutput(session, sessionType, text, error); + manager.displayOutput(session, sessionType, text, error); } //-------------------------------------------------------- @@ -959,15 +1044,15 @@ /** */ private boolean tryParsePlainHeader(String testcaseHeader) { + assert report != null; final Matcher matcher = regexp.getTestcaseHeaderPlainPattern() .matcher(testcaseHeader); if (matcher.matches()) { String methodName = matcher.group(1); int timeMillis = regexp.parseTimeMillisNoNFE(matcher.group(2)); - testcase = new Report.Testcase(); + testcase = report.findTest(methodName, true); testcase.className = null; - testcase.name = methodName; testcase.timeMillis = timeMillis; trouble = null; @@ -982,6 +1067,7 @@ /** */ private boolean tryParseBriefHeader(String testcaseHeader) { + assert report != null; final Matcher matcher = regexp.getTestcaseHeaderBriefPattern() .matcher(testcaseHeader); if (matcher.matches()) { @@ -989,9 +1075,8 @@ String clsName = matcher.group(2); boolean error = (matcher.group(3) == null); - testcase = new Report.Testcase(); + testcase = report.findTest(methodName, true); testcase.className = clsName; - testcase.name = methodName; testcase.timeMillis = -1; trouble = (testcase.trouble = new Report.Trouble(error)); @@ -1002,9 +1087,11 @@ } } - /** - */ private void closePreviousReport() { + closePreviousReport(false); + } + + private void closePreviousReport(boolean interrupted) { if (xmlOutputBuffer != null) { try { String xmlOutput = xmlOutputBuffer.toString(); @@ -1019,11 +1106,16 @@ assert false; //should not happen (StringReader) } } else if ((report != null) && (report.resultsDir != null)) { + + if (waitingForIssueStatus) { + assert testcase != null; + report.reportTest(testcase); + } + /* * We have parsed the output but it seems that we also have * an XML report file available - let's use it: */ - File reportFile = new File( report.resultsDir, "TEST-" + report.suiteClassName + ".xml");//NOI18N @@ -1060,7 +1152,7 @@ } } if (report != null) { - suiteFinished(report); + suiteFinished(report, interrupted); } xmlOutputBuffer = null; diff -r 477240a96fc6 junit/src/org/netbeans/modules/junit/output/RegexpUtils.java --- a/junit/src/org/netbeans/modules/junit/output/RegexpUtils.java Mon Jun 30 14:32:33 2008 +0200 +++ b/junit/src/org/netbeans/modules/junit/output/RegexpUtils.java Thu Jul 03 13:41:19 2008 +0200 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common @@ -24,7 +24,7 @@ * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL @@ -152,6 +152,8 @@ static final String START_OF_TEST_PREFIX = "startTest"; //NOI18N /** */ static final String END_OF_TEST_PREFIX = "endTest"; //NOI18N + static final String ADD_FAILURE_PREFIX = "addFailure"; //NOI18N + static final String ADD_ERROR_PREFIX = "addError"; //NOI18N /** * Regexp matching part of a Java task's invocation debug message diff -r 477240a96fc6 junit/src/org/netbeans/modules/junit/output/Report.java --- a/junit/src/org/netbeans/modules/junit/output/Report.java Mon Jun 30 14:32:33 2008 +0200 +++ b/junit/src/org/netbeans/modules/junit/output/Report.java Thu Jul 03 13:41:19 2008 +0200 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common @@ -24,7 +24,7 @@ * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL @@ -47,7 +47,6 @@ import java.util.Collection; import java.util.Collections; import org.netbeans.api.java.classpath.ClassPath; -import org.openide.ErrorManager; import org.openide.filesystems.FileObject; /** @@ -76,7 +75,7 @@ */ int detectedPassedTests; private Collection tests; - private boolean closed = false; + private boolean suiteFinished = false; /** */ @@ -99,6 +98,44 @@ detectedPassedTests++; } } + + /** + * Finds a test having the given name in this {@code Report}. + * If parameter {@code create} is {@code true} and a test of the given + * name did not exist, a new {@code Testcase} is created and is named + * after the given {@code name} parameter. + * + * @param name requested name of the test + * @param create whether a test should be created if it does not exist yet + * @return an existing test of the given name, or {@code null} if it does + * not exist and parameter {@code create} is {@code false}, + * or a newly created {@code Testcase} if test of the given + * name did not exist and parameter {@code create} was {@code true} + */ + Testcase findTest(String name, boolean create) { + if ((tests == null) || tests.isEmpty()) { + return create ? new Testcase(name) : null; + } + + for (Testcase test : tests) { + if (name.equals(test.name)) { + return test; + } + } + return create ? new Testcase(name) : null; + } + + /** + */ + void markSuiteFinished() { + suiteFinished = true; + } + + /** + */ + boolean isSuiteFinished() { + return suiteFinished; + } /** */ @@ -119,6 +156,7 @@ this.elapsedTimeMillis = report.elapsedTimeMillis; this.detectedPassedTests = report.detectedPassedTests; this.tests = report.tests; + this.suiteFinished |= report.suiteFinished; } /** @@ -155,10 +193,15 @@ /** */ static final class Testcase { + static final int TIME_UNKNOWN = -1; + static final int NOT_FINISHED_YET = -2; String className; String name; int timeMillis; Trouble trouble; + + Testcase() {} + Testcase(String name) { this.name = name; } } /** diff -r 477240a96fc6 junit/src/org/netbeans/modules/junit/output/TestMethodNode.java --- a/junit/src/org/netbeans/modules/junit/output/TestMethodNode.java Mon Jun 30 14:32:33 2008 +0200 +++ b/junit/src/org/netbeans/modules/junit/output/TestMethodNode.java Thu Jul 03 13:41:19 2008 +0200 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common @@ -24,7 +24,7 @@ * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL @@ -46,12 +46,34 @@ import org.openide.nodes.Children; import org.openide.util.NbBundle; import org.openide.util.actions.SystemAction; +import static org.netbeans.modules.junit.output.Report.Testcase; /** * * @author Marian Petras */ final class TestMethodNode extends AbstractNode { + + private static final String[] NO_TIME_STATUS_KEYS = new String[] { + null, + "MSG_TestMethodError", //NOI18N + "MSG_TestMethodFailed"}; //NOI18N + private static final String[] TIME_STATUS_KEYS = new String[] { + "MSG_TestMethodPassed_time", //NOI18N + "MSG_TestMethodError_time", //NOI18N + "MSG_TestMethodFailed_time"}; //NOI18N + private static final String STATUS_KEY_INTERRUPTED + = "MSG_TestMethodInterrupted"; //NOI18N + private static final String[] NO_TIME_STATUS_KEYS_HTML = new String[] { + "MSG_TestMethodPassed_HTML", //NOI18N + "MSG_TestMethodError_HTML", //NOI18N + "MSG_TestMethodFailed_HTML"}; //NOI18N + private static final String[] TIME_STATUS_KEYS_HTML = new String[] { + "MSG_TestMethodPassed_HTML_time", //NOI18N + "MSG_TestMethodError_HTML_time", //NOI18N + "MSG_TestMethodFailed_HTML_time"};//NOI18N + private static final String STATUS_KEY_INTERRUPTED_HTML + = "MSG_TestMethodInterrupted_HTML"; //NOI18N /** */ private final Report.Testcase testcase; @@ -82,24 +104,21 @@ setDisplayName(testcase.name); return; } - - String[] noTimeKeys = new String[] { - null, - "MSG_TestMethodError", //NOI18N - "MSG_TestMethodFailed"}; //NOI18N - String[] timeKeys = new String[] { - "MSG_TestMethodPassed_time", //NOI18N - "MSG_TestMethodError_time", //NOI18N - "MSG_TestMethodFailed_time"}; //NOI18N - setDisplayName( - testcase.timeMillis < 0 - ? NbBundle.getMessage(getClass(), - noTimeKeys[status], - testcase.name) - : NbBundle.getMessage(getClass(), - timeKeys[status], - testcase.name, - new Float(testcase.timeMillis/1000f))); + + String bundleKey; + Object[] bundleParams; + if (testcase.timeMillis == Testcase.NOT_FINISHED_YET) { + bundleKey = STATUS_KEY_INTERRUPTED; + bundleParams = new Object[] {testcase.name}; + } else if (testcase.timeMillis == Testcase.TIME_UNKNOWN) { + bundleKey = NO_TIME_STATUS_KEYS[status]; + bundleParams = new Object[] {testcase.name}; + } else { + bundleKey = TIME_STATUS_KEYS[status]; + bundleParams = new Object[] {testcase.name, + new Float(testcase.timeMillis/1000f)}; + } + setDisplayName(NbBundle.getMessage(getClass(), bundleKey, bundleParams)); } /** @@ -109,26 +128,32 @@ final int status = (testcase.trouble == null) ? 0 : testcase.trouble.isError() ? 1 : 2; - String[] noTimeKeys = new String[] { - "MSG_TestMethodPassed_HTML", //NOI18N - "MSG_TestMethodError_HTML", //NOI18N - "MSG_TestMethodFailed_HTML"}; //NOI18N - String[] timeKeys = new String[] { - "MSG_TestMethodPassed_HTML_time", //NOI18N - "MSG_TestMethodError_HTML_time", //NOI18N - "MSG_TestMethodFailed_HTML_time"};//NOI18N + + String bundleKey; + Object bundleParam; + String color = null; + if (testcase.timeMillis == Testcase.NOT_FINISHED_YET) { + bundleKey = STATUS_KEY_INTERRUPTED_HTML; + bundleParam = null; + color = "CE7B00"; //dark orange //NOI18N + } else if (testcase.timeMillis == Testcase.TIME_UNKNOWN) { + bundleKey = NO_TIME_STATUS_KEYS_HTML[status]; + bundleParam = null; + } else { + bundleKey = TIME_STATUS_KEYS_HTML[status]; + bundleParam = new Float(testcase.timeMillis/1000f); + } + if (color == null) { + color = (testcase.trouble != null) ? "FF0000" : "00CC00"; //NOI18N + } - StringBuffer buf = new StringBuffer(60); + StringBuilder buf = new StringBuilder(60); buf.append(testcase.name); buf.append("  "); //NOI18N - buf.append("" : "00CC00'>"); //NOI18N - buf.append(testcase.timeMillis < 0 - ? NbBundle.getMessage(getClass(), - noTimeKeys[status]) - : NbBundle.getMessage(getClass(), - timeKeys[status], - new Float(testcase.timeMillis/1000f))); + buf.append(""); //NOI18N + buf.append((bundleParam == null) + ? NbBundle.getMessage(getClass(), bundleKey) + : NbBundle.getMessage(getClass(), bundleKey, bundleParam)); buf.append(""); //NOI18N return buf.toString(); } diff -r 477240a96fc6 junit/src/org/netbeans/modules/junit/output/XmlOutputParser.java --- a/junit/src/org/netbeans/modules/junit/output/XmlOutputParser.java Mon Jun 30 14:32:33 2008 +0200 +++ b/junit/src/org/netbeans/modules/junit/output/XmlOutputParser.java Thu Jul 03 13:41:19 2008 +0200 @@ -107,6 +107,7 @@ XmlOutputParser parser = new XmlOutputParser(); try { parser.xmlReader.parse(new InputSource(reader)); + parser.report.markSuiteFinished(); } catch (SAXException ex) { String message = ex.getMessage(); int severity = ErrorManager.INFORMATIONAL; diff -r 477240a96fc6 properties/src/org/netbeans/modules/properties/PropertiesLocaleNode.java --- a/properties/src/org/netbeans/modules/properties/PropertiesLocaleNode.java Mon Jun 30 14:32:33 2008 +0200 +++ b/properties/src/org/netbeans/modules/properties/PropertiesLocaleNode.java Thu Jul 03 13:41:19 2008 +0200 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common @@ -43,16 +43,10 @@ import java.awt.Component; import java.awt.datatransfer.Transferable; -import java.awt.Dialog; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.io.IOException; -import java.text.MessageFormat; import java.util.List; import javax.swing.Action; -import javax.swing.JPanel; -import org.openide.actions.*; import org.openide.DialogDescriptor; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -61,6 +55,17 @@ import org.openide.nodes.NodeTransfer; import org.openide.NotifyDescriptor; import org.openide.DialogDisplayer; +import org.openide.actions.CopyAction; +import org.openide.actions.CutAction; +import org.openide.actions.DeleteAction; +import org.openide.actions.EditAction; +import org.openide.actions.FileSystemAction; +import org.openide.actions.NewAction; +import org.openide.actions.OpenAction; +import org.openide.actions.PasteAction; +import org.openide.actions.PropertiesAction; +import org.openide.actions.SaveAsTemplateAction; +import org.openide.actions.ToolsAction; import org.openide.util.actions.SystemAction; import org.openide.util.datatransfer.NewType; import org.openide.util.datatransfer.PasteType; @@ -110,6 +115,7 @@ * * @return array of actions for this node */ + @Override protected SystemAction[] createActions () { return new SystemAction[] { SystemAction.get(EditAction.class), @@ -131,6 +137,7 @@ }; } + @Override public Action getPreferredAction() { return getActions(false)[0]; } @@ -141,13 +148,16 @@ * * @return locale part of name */ + @Override public String getName() { String localeName = "invalid"; // NOI18N if (getFileEntry().getFile().isValid() && !getFileEntry().getFile().isVirtual()) { localeName = Util.getLocaleSuffix (getFileEntry()); - if (localeName.length() > 0) - if (localeName.charAt(0) == PropertiesDataLoader.PRB_SEPARATOR_CHAR) + if (localeName.length() > 0) { + if (localeName.charAt(0) == PropertiesDataLoader.PRB_SEPARATOR_CHAR) { localeName = localeName.substring(1); + } + } } return localeName; } @@ -156,13 +166,16 @@ * * @param name the new name */ + @Override public void setName (String name) { if(!name.startsWith(getFileEntry().getDataObject().getPrimaryFile().getName())) { name = Util.assembleName (getFileEntry().getDataObject().getPrimaryFile().getName(), name); } // new name is same as old one, do nothing - if (name.equals(super.getName())) return; + if (name.equals(super.getName())) { + return; + } super.setName (name); setDisplayName(Util.getLocaleLabel(getFileEntry())); @@ -176,31 +189,40 @@ } /** This node can be renamed. Overrides superclass method. */ + @Override public boolean canRename() { return getFileEntry().isDeleteAllowed (); } /** Returns all the item in addition to "normal" cookies. Overrides superclass method. */ @SuppressWarnings("unchecked") + @Override public T getCookie(Class cls) { - if (cls.isInstance(getFileEntry())) return (T) getFileEntry(); - if (cls == PropertiesLocaleNode.class) return (T) this; + if (cls.isInstance(getFileEntry())) { + return (T) getFileEntry(); + } + if (cls == PropertiesLocaleNode.class) { + return (T) this; + } return super.getCookie(cls); } /** List new types that can be created in this node. Overrides superclass method. * @return new types */ + @Override public NewType[] getNewTypes () { return new NewType[] { new NewType() { /** Getter for name property. */ + @Override public String getName() { return NbBundle.getBundle(PropertiesLocaleNode.class).getString("LAB_NewPropertyAction"); } /** Gets help context. */ + @Override public HelpCtx getHelpCtx() { return new HelpCtx(Util.HELP_ID_ADDING); } @@ -240,16 +262,19 @@ /** Indicates if this node has a customizer. Overrides superclass method. * @return true */ + @Override public boolean hasCustomizer() { return true; } /** Gets node customizer. Overrides superclass method. */ + @Override public Component getCustomizer() { return new LocaleNodeCustomizer((PropertiesFileEntry)getFileEntry()); } /** Creates paste types for this node. Overrides superclass method. */ + @Override protected void createPasteTypes(Transferable t, List s) { super.createPasteTypes(t, s); Element.ItemElem item; @@ -308,6 +333,7 @@ /** Gets name. * @return human presentable name of this paste type. */ + @Override public String getName() { String pasteKey = mode == 1 ? "CTL_PasteKeyValue" : "CTL_PasteKeyNoValue"; return NbBundle.getBundle(PropertiesLocaleNode.class).getString(pasteKey); @@ -321,10 +347,11 @@ public Transferable paste() throws IOException { PropertiesStructure ps = ((PropertiesFileEntry)getFileEntry()).getHandler().getStructure(); String value; - if (mode == MODE_PASTE_WITH_VALUE) + if (mode == MODE_PASTE_WITH_VALUE) { value = item.getValue(); - else + } else { value = ""; + } if (ps != null) { Element.ItemElem newItem = ps.getItem(item.getKey()); if (newItem == null) { @@ -334,8 +361,9 @@ newItem.setValue(value); newItem.setComment(item.getComment()); } - if (node != null) + if (node != null) { node.destroy(); + } } return null;