Hi,
I'm new on netbeans RCP. I created my custom TopComponents with some annotations as follow : @ConvertAsProperties( dtd = "-//project.editor.hmi//EditorShape//EN", autostore = false ) @TopComponent.Description( preferredID = "EditorShapeTopComponent", iconBase = "project/editor/shape_24.png", persistenceType = TopComponent.PERSISTENCE_ALWAYS ) //@TopComponent.Registration(mode<mailto://@TopComponent.Registration(mode> = "leftSlidingSide", openAtStartup = true) @ActionID(category = "Window", id = "project.editor.hmi.EditorShapeTopComponent") //@ActionReference(path = "Menu/Window" /*, position = 333 */) @TopComponent.OpenActionRegistration( displayName = "#CTL_EditorShapeAction", preferredID = "EditorShapeTopComponent" ) @Messages({ "CTL_EditorShapeAction=Formes", "CTL_EditorShapeTopComponent=Formes", "HINT_EditorShapeTopComponent=Formes simples importables" }) public final class EditorShapeTopComponent extends TopComponent { ... } I have a configuration file (properties file) in which a parameter tells if the TopComponent must be activated or not. To manage the visibility of the TopComponent, I do that : public GlobalActionContextProxy() { ... WindowManager.getDefault().invokeWhenUIReady(new Runnable() { @Override public void run() { // Hack to force the current Project selection when the application starts up TopComponent tc = WindowManager.getDefault().findTopComponent(PROJECT_LOGICAL_TAB_ID); if (tc != null) { tc.requestActive(); } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // Reads the configuration file. Configuration configuration = CentralLookup.getDefault().lookup(Configuration.class); // Here we check that the parameter is the configuration file is to true. if (configuration.getBoolean("withImages", false) == true) { // Adds to Menu. FileObject menuFolder = FileUtil.getConfigFile("Menu/Window"); try { registerAction(SycloneEditorImagePaletteTopComponent.class, Bundle.LBL_SycloneEditorImagePaletteTopComponent(), new ImageIcon(getClass().getResource("/fr/clemessy/ast/syclone/project/synoptic/editor/img_24.png")), menuFolder, 333); } catch (IOException ex) { Exceptions.printStackTrace(ex); } // Adds to left dock. if (!isTopComponentInUserDirCache(SycloneEditorImagePaletteTopComponent.class)) { SycloneEditorImagePaletteTopComponent tcPalette = new SycloneEditorImagePaletteTopComponent(); Mode leftSideMode = WindowManager.getDefault().findMode("leftSlidingSide"); leftSideMode.dockInto(tcPalette); tcPalette.open(); } } else { // Removes the file from the cache : avoid it to be reopened by the persistence manager. removeTopComponentInUserDirCache(SycloneEditorImagePaletteTopComponent.class); } } }); } }); } The method isTopComponentInUserDirCache is as follow : /** * Checks if a component appears in the userdir cache of Netbeans. * * @param <T> : child class of TopComponent. * @param classType : class type. * @return true if the component is in the cache, false otherwise. */ private <T extends TopComponent> boolean isTopComponentInUserDirCache(final Class<T> classType) { boolean isInCache = false; // Gets the directory which contains cache on Components. Path compDirPath = getUserDirComponentsSettingPath(); // It the directory exists, checks if the component has already been opened. File compDirFile = compDirPath.toFile(); if (compDirFile.exists()) { // Gets the files referencing the component. File[] compFiles = compDirFile.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { StringBuilder filenameMatcher = new StringBuilder("^"); filenameMatcher.append(classType.getSimpleName()); filenameMatcher.append("(_\\d*)?"); filenameMatcher.append(".settings$"); return name != null && name.matches(filenameMatcher.toString()); } }); // If there is at least 1 file, the component has already been opened. if (compFiles != null && compFiles.length > 0) { isInCache = true; } } return isInCache; } With this solution, it seems to work but it is not very clean. And when I change the language, the menu item (linked to the TopComponent), which is read from the cache, is not translated. How could I do it in a cleanest way ? The only reason I don't use annotations on the TopComponent is because I need to tell "open the TopComponent only if it is defined in the configuration file" : is there a way to do it properly ? Thanks, Bastien [http://www.eiffage.com/signature/image.jpg] Cet e-mail et ses ?ventuelles pi?ces jointes peuvent contenir des informations confidentielles et sont exclusivement adress?s au(x) destinataire(s) mentionn?(s) ci-dessus. Toute diffusion, exploitation ou copie sans autorisation de cet e-mail et de ses pi?ces jointes est strictement interdite. Si vous recevez ce message par erreur, merci de le d?truire et d' avertir imm?diatement l'exp?diteur. EIFFAGE d?cline toute responsabilit? si ce message a ?t? modifi? ou falsifi?. This message and any attachments may contain confidential information and are established exclusively for his or its recipients. Any use of this message, for which it was not intended, any distribution or any total or partial publication is prohibited unless previously approved. If you receive this message in error, please destroy it and immediately notify the sender thereof. The EIFFAGE Group declines all responsibility concerning this message if it has been altered or tampered with.