Java Code Examples for org.openide.filesystems.FileUtil#getConfigObject()
The following examples show how to use
org.openide.filesystems.FileUtil#getConfigObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorOnlyDisplayer.java From netbeans with Apache License 2.0 | 6 votes |
private static boolean setShowEditorToolbar( boolean show ) { boolean res = true; Action toggleEditorToolbar = FileUtil.getConfigObject( "Editors/Actions/toggle-toolbar.instance", Action.class ); //NOI18N if( null != toggleEditorToolbar ) { if( toggleEditorToolbar instanceof Presenter.Menu ) { JMenuItem menuItem = ((Presenter.Menu)toggleEditorToolbar).getMenuPresenter(); if( menuItem instanceof JCheckBoxMenuItem ) { JCheckBoxMenuItem checkBoxMenu = ( JCheckBoxMenuItem ) menuItem; res = checkBoxMenu.isSelected(); if( checkBoxMenu.isSelected() != show ) { try { toggleEditorToolbar.actionPerformed( new ActionEvent( menuItem, 0, "")); //NOII18N } catch( Exception ex ) { //don't worry too much if it isn't working, we're just trying to be helpful here Logger.getLogger( EditorOnlyDisplayer.class.getName()).log( Level.FINE, null, ex ); } } } } } return res; }
Example 2
Source File: Actions.java From netbeans with Apache License 2.0 | 6 votes |
/** * Locates a specific action programmatically. * The action will typically have been registered using {@link ActionRegistration}. * <p>Normally an {@link ActionReference} will suffice to insert the action * into various UI elements (typically using {@link Utilities#actionsForPath}), * but in special circumstances you may need to find a single known action. * This method is just a shortcut for using {@link FileUtil#getConfigObject} * with the correct arguments, plus using {@link AcceleratorBinding#setAccelerator}. * @param category as in {@link ActionID#category} * @param id as in {@link ActionID#id} * @return the action registered under that ID, or null * @throws IllegalArgumentException if a corresponding {@link ActionID} would have been rejected * @since 7.42 */ public static Action forID(String category, String id) throws IllegalArgumentException { // copied from ActionProcessor: if (category.startsWith("Actions/")) { throw new IllegalArgumentException("category should not start with Actions/: " + category); } if (!FQN.matcher(id).matches()) { throw new IllegalArgumentException("id must be valid fully qualified name: " + id); } String path = "Actions/" + category + "/" + id.replace('.', '-') + ".instance"; Action a = FileUtil.getConfigObject(path, Action.class); if (a == null) { return null; } FileObject def = FileUtil.getConfigFile(path); if (def != null) { AcceleratorBinding.setAccelerator(a, def); } return a; }
Example 3
Source File: SnapUtilsTest.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Test public void testAddRemoveAction() throws Exception { AbstractAction realAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { } }; FileObject actionFile = SnapUtils.addAction(realAction, "Test/Action"); assertNotNull(actionFile); assertNotNull(actionFile.getParent()); assertEquals("application/x-nbsettings", actionFile.getMIMEType()); assertEquals("Test/Action", actionFile.getParent().getPath()); assertEquals("instance", actionFile.getExt()); Action action = FileUtil.getConfigObject(actionFile.getPath(), Action.class); assertNotNull(action); assertEquals(TransientAction.class, action.getClass()); assertSame(realAction, ((TransientAction) action).getDelegate()); boolean ok = SnapUtils.removeAction(actionFile); assertEquals(true, ok); action = FileUtil.getConfigObject(actionFile.getPath(), Action.class); assertNull(action); }
Example 4
Source File: ShowMembersAction.java From netbeans with Apache License 2.0 | 5 votes |
static void missingNavigatorAPIHack( @NonNull final ActionEvent ev, @NonNull final JavaSource context, @NullAllowed final JTextComponent target) { final Action openNavigator = FileUtil.getConfigObject( "Actions/Window/org-netbeans-modules-navigator-ShowNavigatorAction.instance", Action.class); if (openNavigator != null) { openNavigator.actionPerformed(ev); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { NavigatorHandler.activateNavigator(); final Collection<? extends NavigatorPanel> panels = getPanels(context); NavigatorPanel cmp = null; for (NavigatorPanel panel : panels) { if (panel.getComponent().getClass() == ClassMemberPanelUI.class) { cmp = panel; break; } } if (cmp != null) { NavigatorHandler.activatePanel(cmp); ((ClassMemberPanelUI)cmp.getComponent()).setContext(context, target); } } }); } }
Example 5
Source File: Intent.java From netbeans with Apache License 2.0 | 5 votes |
private static SortedSet<IntentHandler> getIntentHandlers( Intent intent) { FileObject f = FileUtil.getConfigFile("Services/Intent/Handlers"); if (f == null) { return null; } SortedSet<IntentHandler> candidates = new TreeSet<>(); for (FileObject fo : f.getChildren()) { if ("instance".equals(fo.getExt())) { Object pattern = fo.getAttribute("uriPattern"); Object displayName = fo.getAttribute("displayName"); Object position = fo.getAttribute("position"); Object actions = fo.getAttribute("actions"); if (pattern instanceof String && displayName instanceof String && position instanceof Integer && actions instanceof String) { if (canSupport((String) pattern, (String) actions, intent)) { try { IntentHandler ih = FileUtil.getConfigObject( fo.getPath(), IntentHandler.class); candidates.add(ih); } catch (Exception e) { LOG.log(Level.INFO, "Cannot instantiate handler for " //NOI18N + fo.getPath(), e); } } } else { LOG.log(Level.FINE, "Invalid URI handler {0}", fo.getPath()); } } } return candidates; }
Example 6
Source File: OpenHTMLRegistrationTest.java From netbeans with Apache License 2.0 | 5 votes |
@Test(timeOut = 9000) public void verifyRegistered() { final String path = "Actions/Test/html-test.instance"; final FileObject fo = FileUtil.getConfigFile(path); assertNotNull(fo, "Registration found"); Action a = FileUtil.getConfigObject(path, Action.class); assertNotNull(a, "Action found"); assertEquals(a.getValue(Action.NAME), "Open me!"); assertEquals(fo.getAttribute("class"), OpenHTMLRegistrationTest.class.getCanonicalName(), "Fully qualified name"); assertEquals(fo.getAttribute("method"), "main"); class FOMap extends HashMap<String,Object> { @Override public Object get(Object key) { return fo.getAttribute(key.toString()); } } Pages.R r = new Pages.R(new FOMap()); Object[] arr = r.getTechIds(); assertEquals(arr.length, 3, "Three different ids"); assertEquals(arr[0], "uno"); assertEquals(arr[1], "duo"); assertEquals(arr[2], "tre"); }
Example 7
Source File: SharedClassObjectFactoryTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testSharedClassObject() throws Exception { Shared instance = SharedClassObject.findObject(Shared.class, true); FileObject data = FileUtil.createData(root, "dir/" + Shared.class.getName().replace('.', '-') + ".instance"); Lookup l = Lookups.forPath("dir"); assertSame(instance, l.lookup(Shared.class)); Shared created = FileUtil.getConfigObject(data.getPath(), Shared.class); assertSame("Config file found", instance, created); }
Example 8
Source File: MissingNbInstallationProblemProvider.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Future<Result> resolve() { FutureTask<Result> toRet = new FutureTask<Result>(new Callable<Result>() { @Override public Result call() throws Exception { NotifyDescriptor.Confirmation action = new NotifyDescriptor.Confirmation("You can either define netbeans.installation property in .m2/settings.xml file to point to currently running IDE or open the associated nbm-application project.", "Resolve missing NetBeans platform"); String prop = "Define property"; String open = "Open Application project"; action.setOptions(new Object[] { prop, open, NotifyDescriptor.CANCEL_OPTION}); Object result = DialogDisplayer.getDefault().notify(action); if (prop.equals(result)) { RunIDEInstallationChecker.setRunningIDEAsInstallation(); return Result.create(Status.RESOLVED); } if (open.equals(result)) { final Action act = FileUtil.getConfigObject("Actions/Project/org-netbeans-modules-project-ui-OpenProject.instance", Action.class); if (act != null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { act.actionPerformed(null); } }); } } return Result.create(Status.UNRESOLVED); } }); toRet.run(); return toRet; }
Example 9
Source File: RefactoringPanel.java From netbeans with Apache License 2.0 | 5 votes |
void close() { if (isQuery) { RefactoringPanelContainer.getUsagesComponent().removePanel(this); } else { RefactoringPanelContainer.getRefactoringComponent().removePanel(this); } if(isVisible) { Action action = FileUtil.getConfigObject("Actions/Window/org-netbeans-core-windows-actions-SwitchToRecentDocumentAction.instance", Action.class); //NOI18N if(action != null) { action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null)); } } closeNotify(); }
Example 10
Source File: Utils.java From netbeans with Apache License 2.0 | 5 votes |
public static Action getAcceleratedAction(String path) { // or use Actions.forID Action a = FileUtil.getConfigObject(path, Action.class); FileObject fo = FileUtil.getConfigFile(path); if(fo != null) { AcceleratorBinding.setAccelerator(a, fo); } return a; }
Example 11
Source File: LicenseHeadersPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void btnGlobalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGlobalActionPerformed // TODO add your handling code here: Action action = FileUtil.getConfigObject("Actions/System/org-netbeans-modules-templates-actions-TemplatesAction.instance", Action.class); if (action != null) { System.setProperty("org.netbeans.modules.templates.actions.TemplatesAction.preselect", "Licenses"); action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "perform")); } else { Exceptions.printStackTrace(new Exception("Actions/System/org-netbeans-modules-templates-actions-TemplatesAction.instance not found")); } }
Example 12
Source File: SnapUtilsTest.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Test public void testAddRemoveActionReference() throws Exception { AbstractAction realAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { } }; FileObject actionFile = SnapUtils.addAction(realAction, "Test/Action"); FileObject actionRef1File = SnapUtils.addActionReference(actionFile, "Test/Refs1", 10); assertNotNull(actionRef1File); assertNotNull(actionRef1File.getParent()); assertEquals("Test/Refs1", actionRef1File.getParent().getPath()); assertEquals("shadow", actionRef1File.getExt()); assertEquals("content/unknown", actionRef1File.getMIMEType()); Action refAction = FileUtil.getConfigObject(actionRef1File.getPath(), Action.class); assertNotNull(refAction); assertEquals(TransientAction.class, refAction.getClass()); assertSame(realAction, ((TransientAction) refAction).getDelegate()); boolean ok = SnapUtils.removeActionReference(actionFile); assertEquals(false, ok); ok = SnapUtils.removeActionReference(actionRef1File); assertEquals(true, ok); refAction = FileUtil.getConfigObject(actionRef1File.getPath(), Action.class); assertNull(refAction); }
Example 13
Source File: RecognizeInstanceFilesTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testNullForFolders() throws Exception { FileObject data = FileUtil.createFolder(root, "dir/" + Shared.class.getName().replace('.', '-') + ".instance"); Shared nul = FileUtil.getConfigObject(data.getPath(), Shared.class); assertNull("No object for folders", nul); }
Example 14
Source File: CompletionScrollPane.java From netbeans with Apache License 2.0 | 4 votes |
private void installKeybindings(JTextComponent component) { // Register Escape key registerKeybinding(ACTION_ESCAPE, ESCAPE, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ExtKit.escapeAction, component); // Register up key registerKeybinding(ACTION_COMPLETION_UP, COMPLETION_UP, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), BaseKit.upAction, component); // Register down key registerKeybinding(ACTION_COMPLETION_DOWN, COMPLETION_DOWN, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), BaseKit.downAction, component); // Register PgDn key registerKeybinding(ACTION_COMPLETION_PGDN, COMPLETION_PGDN, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), BaseKit.pageDownAction, component); // Register PgUp key registerKeybinding(ACTION_COMPLETION_PGUP, COMPLETION_PGUP, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), BaseKit.pageUpAction, component); // Register home key registerKeybinding(ACTION_COMPLETION_BEGIN, COMPLETION_BEGIN, KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0), BaseKit.beginLineAction, component); // Register end key registerKeybinding(ACTION_COMPLETION_END, COMPLETION_END, KeyStroke.getKeyStroke(KeyEvent.VK_END, 0), BaseKit.endLineAction, component); Action action = FileUtil.getConfigObject("Actions/Source/org-netbeans-modules-editor-hints-FixAction.instance", Action.class); //NOI18N KeyStroke ks = action != null ? (KeyStroke) action.getValue(Action.ACCELERATOR_KEY) : null; registerKeybinding(ACTION_COMPLETION_SUBITEMS_SHOW, COMPLETION_SUBITEMS_SHOW, ks != null ? ks : KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.ALT_MASK), null, component); }
Example 15
Source File: MainMenuAction.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected Action getGlobalKitAction() { return FileUtil.getConfigObject("Editors/private/GlobalFormatAction.instance", Action.class); }