Search in sources :

Example 16 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class Model method isEditorTCActive.

private static boolean isEditorTCActive() {
    boolean res = true;
    TopComponent tc = TopComponent.getRegistry().getActivated();
    if (null != tc) {
        ModeImpl mode = (ModeImpl) WindowManagerImpl.getInstance().findMode(tc);
        if (null != mode)
            res = mode.getKind() == Constants.MODE_KIND_EDITOR;
    }
    return res;
}
Also used : ModeImpl(org.netbeans.core.windows.ModeImpl) TopComponent(org.openide.windows.TopComponent)

Example 17 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class SlideBar method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (e instanceof TabActionEvent) {
        TabActionEvent tae = (TabActionEvent) e;
        if (TabbedContainer.COMMAND_RESTORE_GROUP.equals(tae.getActionCommand())) {
            String nameOfModeToRestore = tae.getGroupName();
            WindowManagerImpl wm = WindowManagerImpl.getInstance();
            ModeImpl modeToRestore = (ModeImpl) wm.findMode(nameOfModeToRestore);
            if (null != modeToRestore) {
                wm.userRestoredMode(tabbed.getSlidingMode(), modeToRestore);
            }
        }
    }
}
Also used : TabActionEvent(org.netbeans.swing.tabcontrol.event.TabActionEvent) WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) ModeImpl(org.netbeans.core.windows.ModeImpl)

Example 18 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class GroupsManager method closeGroup.

boolean closeGroup(DocumentGroupImpl group) {
    // NOI18N
    TopComponent welcomeTc = WindowManager.getDefault().findTopComponent("Welcome");
    boolean welcomeWasOpened = null != welcomeTc && welcomeTc.isOpened();
    // save the window system first
    Lookup.getDefault().lookup(WindowSystem.class).save();
    // collect documents
    WindowManagerImpl wmi = WindowManagerImpl.getInstance();
    ArrayList<TopComponent> documents = new ArrayList<>(TopComponent.getRegistry().getOpened().size());
    for (TopComponent tc : TopComponent.getRegistry().getOpened()) {
        if (wmi.isEditorTopComponent(tc)) {
            documents.add(tc);
        }
    }
    String name = group.getName();
    File userDir = Places.getUserDirectory();
    // NOI18N
    File root = new File(new File(userDir, "config"), DOCUMENT_GROUPS);
    File groupDir = new File(root, name);
    // remove old data (if any)
    deleteAll(groupDir);
    groupDir.mkdirs();
    FileObject groupFO = FileUtil.toFileObject(groupDir);
    Preferences prefs = getPreferences().node(name);
    try {
        prefs.clear();
    } catch (BackingStoreException ex) {
        LOG.log(Level.INFO, null, ex);
    }
    prefs.put(DISPLAY_NAME, group.toString());
    File configRoot = new File(new File(Places.getUserDirectory(), CONFIG), WINDOWS2_LOCAL);
    File modesRoot = new File(configRoot, MODES);
    for (ModeImpl mode : wmi.getModes()) {
        if (mode.getKind() == Constants.MODE_KIND_EDITOR) {
            String modeName = mode.getName();
            // NOI18N //NOI18N
            FileObject modeFO = FileUtil.toFileObject(new File(modesRoot, modeName + "." + WSMODE));
            if (null == modeFO) {
                continue;
            }
            try {
                modeFO.copy(groupFO, modeName, WSMODE);
            } catch (IOException ex) {
                LOG.log(Level.INFO, null, ex);
                continue;
            }
            StringBuilder sb = new StringBuilder();
            for (String id : mode.getOpenedTopComponentsIDs()) {
                sb.append(id);
                sb.append(ID_SEPARATOR);
            }
            prefs.put(modeName, sb.toString());
        }
    }
    // copy TopComponents
    File componentRoot = new File(configRoot, COMPONENTS);
    for (TopComponent tc : documents) {
        String id = wmi.findTopComponentID(tc);
        if (tc.equals(welcomeTc) && !welcomeWasOpened)
            continue;
        if (tc.getPersistenceType() == TopComponent.PERSISTENCE_NEVER) {
            continue;
        }
        // NOI18N //NOI18N
        FileObject tcFO = FileUtil.toFileObject(new File(componentRoot, id + "." + SETTINGS));
        if (tcFO == null) {
            continue;
        }
        try {
            tcFO.copy(groupFO, id, SETTINGS);
        } catch (IOException ex) {
            LOG.log(Level.INFO, null, ex);
        }
    }
    // TODO save recent view list
    // NOI18N
    getPreferences().put(SEL_GROUP, "");
    return true;
}
Also used : WindowSystem(org.netbeans.core.WindowSystem) WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) ModeImpl(org.netbeans.core.windows.ModeImpl) ArrayList(java.util.ArrayList) BackingStoreException(java.util.prefs.BackingStoreException) IOException(java.io.IOException) FileObject(org.openide.filesystems.FileObject) Preferences(java.util.prefs.Preferences) NbPreferences(org.openide.util.NbPreferences) File(java.io.File) TopComponent(org.openide.windows.TopComponent)

Example 19 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class CloseAllButThisAction method obtainTC.

private TopComponent obtainTC() {
    TopComponent res = tc;
    if (null == res) {
        WindowManagerImpl wmi = WindowManagerImpl.getInstance();
        String[] ids = wmi.getRecentViewIDList();
        for (String tcId : ids) {
            ModeImpl mode = wmi.findModeForOpenedID(tcId);
            if (mode == null || mode.getKind() != Constants.MODE_KIND_EDITOR) {
                continue;
            }
            res = wmi.findTopComponent(tcId);
            break;
        }
    }
    if (null == res)
        res = TopComponent.getRegistry().getActivated();
    return res;
}
Also used : WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) ModeImpl(org.netbeans.core.windows.ModeImpl) TopComponent(org.openide.windows.TopComponent)

Example 20 with ModeImpl

use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.

the class CloseAllButThisAction method run.

@Override
public void run() {
    TopComponent tc = obtainTC();
    WindowManagerImpl wmi = WindowManagerImpl.getInstance();
    ModeImpl mode = (ModeImpl) wmi.findMode(tc);
    boolean areOtherDocs;
    if (isContext) {
        areOtherDocs = mode.getOpenedTopComponents().size() > 1;
    } else {
        areOtherDocs = wmi.getEditorTopComponents().length > 1;
    }
    setEnabled(mode != null && mode.getKind() == Constants.MODE_KIND_EDITOR && areOtherDocs && Switches.isEditorTopComponentClosingEnabled());
}
Also used : WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) ModeImpl(org.netbeans.core.windows.ModeImpl) TopComponent(org.openide.windows.TopComponent)

Aggregations

ModeImpl (org.netbeans.core.windows.ModeImpl)60 TopComponent (org.openide.windows.TopComponent)35 WindowManagerImpl (org.netbeans.core.windows.WindowManagerImpl)22 ArrayList (java.util.ArrayList)5 IOException (java.io.IOException)3 List (java.util.List)3 FileObject (org.openide.filesystems.FileObject)3 Component (java.awt.Component)2 File (java.io.File)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 BackingStoreException (java.util.prefs.BackingStoreException)2 Preferences (java.util.prefs.Preferences)2 WindowSystem (org.netbeans.core.WindowSystem)2 ModeStructureSnapshot (org.netbeans.core.windows.ModeStructureSnapshot)2 TopComponentTracker (org.netbeans.core.windows.TopComponentTracker)2 MultiSplitPane (org.netbeans.core.windows.view.ui.MultiSplitPane)2 TabActionEvent (org.netbeans.swing.tabcontrol.event.TabActionEvent)2 NbPreferences (org.openide.util.NbPreferences)2