use of org.openide.util.NbBundle.Messages in project netbeans-rcp-lite by outersky.
the class MultiViewCloneableEditor method canCloseElement.
@Messages({ "# {0} - file name", "MSG_SaveModified=File {0} is modified. Save?", "MSG_SaveModified_no_name=File is modified. Save?" })
@Override
public CloseOperationState canCloseElement() {
final CloneableEditorSupport sup = getLookup().lookup(CloneableEditorSupport.class);
Enumeration<CloneableTopComponent> en = getReference().getComponents();
if (en.hasMoreElements()) {
en.nextElement();
if (en.hasMoreElements()) {
// at least two is OK
return CloseOperationState.STATE_OK;
}
}
Savable sav = getLookup().lookup(Savable.class);
if (sav != null) {
AbstractAction save = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
sup.saveDocument();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
};
try {
if (sav.getClass().getMethod("toString").getDeclaringClass() != Object.class) {
save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified(sav));
} else {
Logger.getLogger(MultiViewCloneableEditor.class.getName()).log(Level.WARNING, "Need to override toString() to contain the file name in o.n.api.action.Savable {0} with lookup {1}", new Object[] { sav.getClass(), getLookup().lookupAll(Object.class) });
Node n = getLookup().lookup(Node.class);
if (n != null) {
// #201696: compatibility fallback.
save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified(n.getDisplayName()));
} else {
save.putValue(Action.LONG_DESCRIPTION, Bundle.MSG_SaveModified_no_name());
}
}
} catch (NoSuchMethodException x) {
assert false : x;
}
return MultiViewFactory.createUnsafeCloseState("editor", save, null);
}
return CloseOperationState.STATE_OK;
}
use of org.openide.util.NbBundle.Messages in project netbeans-rcp-lite by outersky.
the class ExplorerManager method readObject.
/**
* Deserializes the view and initializes it
* @serialData see writeObject
*/
@Messages({ "# {0} - name of old node", "EXC_handle_failed=Could not restore Explorer window; the root node \"{0}\" could not be restored correctly." })
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
// perform initialization
init();
// read the first object in the stream
Object firstObject = ois.readObject();
if (firstObject != this) {
// use old version of deserialization
readObjectOld((Node.Handle) firstObject, ois);
return;
}
// work with get fields
ObjectInputStream.GetField fields = ois.readFields();
// read root handle
// NOI18N
Node.Handle h = (Node.Handle) fields.get("root", null);
// System.err.println("reading: " + h);
// NOI18N
final String rootName = (String) fields.get("rootName", null);
// System.err.println("reading: " + rootName);
if (h == null) {
// root handle was not persistent:
throw new SafeException(new IOException("Could not restore Explorer window; the root node \"" + rootName + "\" is not persistent; override Node.getHandle to fix"));
// NOI18N
} else {
// NOI18N
String[] exploredCtx = (String[]) fields.get("explored", null);
// NOI18N
Object[] selPaths = (Object[]) fields.get("selected", null);
try {
Node root = h.getNode();
if (root == null) {
// NOI18N
throw new IOException("Node.Handle.getNode (for " + rootName + ") should not return null");
}
restoreSelection(root, exploredCtx, Arrays.asList(selPaths));
} catch (IOException ioe) {
SafeException safe = new SafeException(ioe);
if (!Utilities.compareObjects(ioe.getMessage(), ioe.getLocalizedMessage())) {
Exceptions.attachLocalizedMessage(safe, EXC_handle_failed(rootName));
}
throw safe;
}
}
}
use of org.openide.util.NbBundle.Messages in project netbeans-rcp-lite by outersky.
the class Janitor method cleanupAction.
@Messages({ "TIT_CONFIRM_CLEANUP=Confirm Cleanup", "# {0} - the dirname to be cleaned up", "TXT_CONFIRM_CLEANUP=Remove user and cache data for NetBeans {0}?", "# {0} - the dirname to be cleaned up", "LBL_CLEANUP=Removing user and cache dirs of {0}" })
static ActionListener cleanupAction(String name) {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
JanitorPanel panel = new JanitorPanel(Bundle.TXT_CONFIRM_CLEANUP(name));
DialogDescriptor descriptor = new DialogDescriptor(panel, Bundle.TIT_CONFIRM_CLEANUP(), true, DialogDescriptor.YES_NO_OPTION, DialogDescriptor.YES_OPTION, null);
if (DialogDescriptor.YES_OPTION == DialogDisplayer.getDefault().notify(descriptor)) {
JANITOR_RP.post(() -> {
try (ProgressHandle handle = ProgressHandle.createHandle(Bundle.LBL_CLEANUP(name))) {
handle.start();
deleteDir(getUserDir(name));
deleteDir(getCacheDir(name));
}
});
}
Janitor.setEnabled(panel.isEnabledOnStartup());
Notification nf = CLEANUP_TASKS.get(this);
if (nf != null) {
nf.clear();
}
}
};
}
use of org.openide.util.NbBundle.Messages in project netbeans-rcp-lite by outersky.
the class SystemFileSystem method log.
@Messages({ "# {0} - type", "# {1} - path to the file", "# {2} - file object itself", "# {3} - event itself", "LOG_FILE_EVENT=File event {0}, file {1}" })
private static void log(String type, FileEvent fe) {
if (LOG.isLoggable(Level.FINER)) {
LogRecord r = new LogRecord(Level.FINER, "LOG_FILE_EVENT");
r.setLoggerName(LOG.getName());
r.setParameters(new Object[] { type, fe.getFile().getPath(), fe.getFile(), fe });
r.setResourceBundle(NbBundle.getBundle(SystemFileSystem.class));
LOG.log(r);
}
}
use of org.openide.util.NbBundle.Messages in project netbeans-rcp-lite by outersky.
the class NbEvents method logged.
/**
* Handle a logged event.
* CAREFUL that this is called synchronously, usually within a write
* mutex or other sensitive environment. So do not call anything
* blocking (like TM.notify) directly. TM.setStatusText and printing
* to console are fine, as well as performance logging.
*/
@Messages({ "MSG_start_load_boot_modules=Loading core...", "MSG_finish_load_boot_modules=Loading core...done.", "MSG_start_auto_restore=Loading modules...", "MSG_finish_auto_restore=Done loading modules.", "MSG_start_enable_modules=Turning on modules...", "TEXT_finish_enable_modules=Turning on modules:", "# {0} = startlevel", "MSG_startlevelinfo=, startlevel={0}", "MSG_finish_enable_modules=Turning on modules...done.", "MSG_start_disable_modules=Turning off modules...", "TEXT_finish_disable_modules=Turning off modules:", "MSG_finish_disable_modules=Turning off modules...done.", "# {0} - file name ", "TEXT_start_deploy_test_module=Deploying test module in {0} ...", "TEXT_finish_deploy_test_module=Finished deploying test module.", "MSG_failed_install_new=Warning - could not install some modules:", "# {0} - module display name", "MSG_failed_install_new_unexpected=Warning - could not install module {0}", "MSG_start_read=Reading module storage...", "MSG_finish_read=Reading module storage...done.", "MSG_restore=Starting modules...", "# #13806: might have been installed before and uninstalled.", "# {0} - module display name", "MSG_install=Installing {0}", "# {0} - module display name", "TEXT_install=Installing new module: {0}", "# {0} - module display name", "MSG_update=Starting a new version of {0}", "# {0} - module display name", "TEXT_update=Updating module: {0}", "# {0} - module display name", "MSG_uninstall=Stopping {0}", "MSG_load_section=Loading modules...", "MSG_load_layers=Loading module services...", "# {0} - path to expected module JAR", "TEXT_missing_jar_file=Warning: the module {0} could not be found, ignoring...", "# {0} - module display name", "TEXT_cant_delete_enabled_autoload=The module {0} could not be deleted as it was an autoload or eager module and still in use.", "# {0} - module display name", "# {1} - property name in XML", "# {2} - value on disk in XML", "# {3} - actual value", "TEXT_misc_prop_mismatch=An attempt was made to change the property {1} of the module {0} in the system/Modules folder.\nThe actual value is \"{3}\" but it was changed on disk to read \"{2}\".\nThis property cannot be changed while the IDE is running, so this attempt had no effect.", "# {0} - JAR file name", "TEXT_patch=Module patch or custom extension: {0}" })
@Override
protected void logged(final String message, Object[] args) {
if (message.equals(PERF_TICK)) {
StartLog.logProgress((String) args[0]);
} else if (message.equals(PERF_START)) {
StartLog.logStart((String) args[0]);
} else if (message.equals(PERF_END)) {
StartLog.logEnd((String) args[0]);
} else if (message.equals(START_CREATE_BOOT_MODULE)) {
org.netbeans.core.startup.Splash.getInstance().increment(1);
} else if (message.equals(START_LOAD_BOOT_MODULES)) {
setStatusText(MSG_start_load_boot_modules());
// NOI18N
StartLog.logStart("ModuleSystem.loadBootModules");
} else if (message.equals(START_LOAD)) {
// NOI18N
StartLog.logStart("NbInstaller.load");
} else if (message.equals(FINISH_LOAD_BOOT_MODULES)) {
setStatusText(MSG_finish_load_boot_modules());
// NOI18N
StartLog.logEnd("ModuleSystem.loadBootModules");
} else if (message.equals(FINISH_LOAD)) {
// NOI18N
StartLog.logEnd("NbInstaller.load");
} else if (message.equals(START_AUTO_RESTORE)) {
Set<?> modules = (Set) args[0];
if (!modules.isEmpty()) {
setStatusText(MSG_start_auto_restore());
}
} else if (message.equals(FINISH_AUTO_RESTORE)) {
setStatusText(MSG_finish_auto_restore());
} else if (message.equals(START_ENABLE_MODULES)) {
setStatusText(MSG_start_enable_modules());
} else if (message.equals(FINISH_ENABLE_MODULES)) {
List<Module> modules = NbCollections.checkedListByCopy((List) args[0], Module.class, true);
if (!modules.isEmpty()) {
logger.log(Level.INFO, TEXT_finish_enable_modules());
dumpModulesList(modules);
}
setStatusText(MSG_finish_enable_modules());
// NOI18N
StartLog.logEnd("ModuleManager.enable");
} else if (message.equals(START_DISABLE_MODULES)) {
setStatusText(MSG_start_disable_modules());
} else if (message.equals(FINISH_DISABLE_MODULES)) {
List<Module> modules = NbCollections.checkedListByCopy((List<?>) args[0], Module.class, true);
if (!modules.isEmpty()) {
logger.log(Level.INFO, TEXT_finish_disable_modules());
dumpModulesList(modules);
}
setStatusText(MSG_finish_disable_modules());
} else if (message.equals(START_DEPLOY_TEST_MODULE)) {
// No need to print anything. ModuleSystem.deployTestModule prints
// its own stuff (it needs to be printed synchronously to console
// in order to appear in the output window). But status text is OK.
// Fix for IZ#81566 - I18N: need to localize status messages for module dev
String msg = TEXT_start_deploy_test_module((File) args[0]);
setStatusText(msg);
} else if (message.equals(FINISH_DEPLOY_TEST_MODULE)) {
// Fix for IZ#81566 - I18N: need to localize status messages for module dev
setStatusText(TEXT_finish_deploy_test_module());
} else if (message.equals(FAILED_INSTALL_NEW)) {
Set<Module> modules = NbCollections.checkedSetByCopy((Set) args[0], Module.class, true);
{
StringBuilder buf = new StringBuilder(MSG_failed_install_new());
NbProblemDisplayer.problemMessagesForModules(buf, modules, false);
// #123669
buf.append('\n');
logger.log(Level.INFO, buf.toString());
}
{
StringBuilder buf = new StringBuilder(MSG_failed_install_new());
NbProblemDisplayer.problemMessagesForModules(buf, modules, true);
String msg = buf.toString();
notify(msg, true);
}
setStatusText("");
} else if (message.equals(FAILED_INSTALL_NEW_UNEXPECTED)) {
Module m = (Module) args[0];
List<Module> modules = new ArrayList<Module>();
modules.add(m);
modules.addAll(NbCollections.checkedSetByCopy((Set) args[1], Module.class, true));
// ignore args[2]: InvalidException
{
StringBuilder buf = new StringBuilder(MSG_failed_install_new_unexpected(m.getDisplayName()));
NbProblemDisplayer.problemMessagesForModules(buf, modules, false);
buf.append('\n');
logger.log(Level.INFO, buf.toString());
}
{
notify(NbProblemDisplayer.messageForProblem(m, m.getProblems().iterator().next(), true), true);
}
setStatusText("");
} else if (message.equals(START_READ)) {
setStatusText(MSG_start_read());
// NOI18N
StartLog.logStart("ModuleList.readInitial");
} else if (message.equals(MODULES_FILE_SCANNED)) {
moduleCount = (Integer) args[0];
Splash.getInstance().addToMaxSteps(Math.max(moduleCount + moduleCount / 2 - 100, 0));
} else if (message.equals(MODULES_FILE_PROCESSED)) {
Splash.getInstance().increment(1);
if (StartLog.willLog()) {
// NOI18N
StartLog.logProgress("module " + args[0] + " processed");
}
} else if (message.equals(FINISH_READ)) {
if (moduleCount < 100) {
Splash.getInstance().increment(moduleCount - 100);
}
setStatusText(MSG_finish_read());
// NOI18N
StartLog.logEnd("ModuleList.readInitial");
} else if (message.equals(RESTORE)) {
// Don't look for display name. Just takes too long.
setStatusText(MSG_restore());
if (++counter < moduleCount / 2) {
Splash.getInstance().increment(1);
}
} else if (message.equals(INSTALL)) {
// Nice to see the real title; not that common, after all.
setStatusText(MSG_install(((Module) args[0]).getDisplayName()));
logger.log(Level.INFO, TEXT_install(((Module) args[0]).getDisplayName()));
} else if (message.equals(UPDATE)) {
setStatusText(MSG_update(((Module) args[0]).getDisplayName()));
logger.log(Level.INFO, TEXT_update(((Module) args[0]).getDisplayName()));
} else if (message.equals(UNINSTALL)) {
setStatusText(MSG_uninstall(((Module) args[0]).getDisplayName()));
} else if (message.equals(LOAD_SECTION)) {
// Again avoid finding display name now.
setStatusText(MSG_load_section());
if (++counter < moduleCount / 4) {
Splash.getInstance().increment(1);
}
} else if (message.equals(LOAD_LAYERS)) {
setStatusText(MSG_load_layers());
} else if (message.equals(WRONG_CLASS_LOADER)) {
if (!Boolean.getBoolean("netbeans.moduleitem.dontverifyclassloader") && Util.err.isLoggable(Level.WARNING)) {
// NOI18N
Class<?> clazz = (Class) args[1];
// Message for developers, no need for I18N.
StringBuilder b = new StringBuilder();
// NOI18N
b.append("The module ").append(((Module) args[0]).getDisplayName()).append(" loaded the class ").append(clazz.getName()).append("\n");
// NOI18N
b.append("from the wrong classloader. The expected classloader was ").append(args[2]).append("\n");
// NOI18N
b.append("whereas it was actually loaded from ").append(clazz.getClassLoader()).append("\n");
// NOI18N
b.append("Usually this means that some classes were in the startup classpath.\n");
// NOI18N
b.append("To suppress this message, run with: -J-Dnetbeans.moduleitem.dontverifyclassloader=true");
Util.err.warning(b.toString());
}
} else if (message.equals(EXTENSION_MULTIPLY_LOADED)) {
// Developer-oriented message, no need for I18N.
logger.log(Level.WARNING, "The extension {0} may be multiply loaded by modules: {1}; see: http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/classpath.html#class-path", new Object[] { (File) args[0], (Set<?>) args[1] });
} else if (message.equals(MISSING_JAR_FILE)) {
File jar = (File) args[0];
Level level = Boolean.FALSE.equals(args[1]) ? Level.FINE : Level.INFO;
logger.log(level, TEXT_missing_jar_file(jar.getAbsolutePath()));
} else if (message.equals(CANT_DELETE_ENABLED_AUTOLOAD)) {
Module m = (Module) args[0];
logger.log(Level.INFO, TEXT_cant_delete_enabled_autoload(m.getDisplayName()));
} else if (message.equals(MISC_PROP_MISMATCH)) {
// XXX does this really need to be logged to the user?
// Or should it just be sent quietly to the log file?
Module m = (Module) args[0];
String prop = (String) args[1];
Object onDisk = args[2];
Object inMem = args[3];
logger.log(Level.INFO, TEXT_misc_prop_mismatch(m.getDisplayName(), prop, onDisk, inMem));
} else if (message.equals(PATCH)) {
File f = (File) args[0];
logger.log(Level.INFO, TEXT_patch(f.getAbsolutePath()));
}
// XXX other messages?
}
Aggregations