Search in sources :

Example 1 with ModeConfig

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

the class WindowManagerImpl method createModeFromXml.

@Override
public Mode createModeFromXml(String xml) {
    try {
        ModeConfig modeConfig = PersistenceManager.getDefault().createModeFromXml(xml);
        ModeImpl mode = createMode(modeConfig);
        addMode(mode, modeConfig);
        return mode;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        return null;
    }
}
Also used : ModeConfig(org.netbeans.core.windows.persistence.ModeConfig) IOException(java.io.IOException)

Example 2 with ModeConfig

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

the class ConfigFactory method createDefaultPropertiesModeConfig.

private static ModeConfig createDefaultPropertiesModeConfig() {
    ModeConfig mc = new ModeConfig();
    // NOI18N
    mc.name = "properties";
    mc.bounds = null;
    mc.relativeBounds = null;
    mc.frameState = -1;
    mc.state = Constants.MODE_STATE_JOINED;
    mc.kind = Constants.MODE_KIND_VIEW;
    mc.constraints = createDefaultPropertiesConstraints();
    // NOI18N
    mc.selectedTopComponentID = "properties";
    mc.permanent = true;
    mc.tcRefConfigs = createDefaultPropertiesTCRefConfigs();
    return mc;
}
Also used : ModeConfig(org.netbeans.core.windows.persistence.ModeConfig)

Example 3 with ModeConfig

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

the class ConfigFactory method createDefaultOutputModeConfig.

private static ModeConfig createDefaultOutputModeConfig() {
    ModeConfig mc = new ModeConfig();
    mc.name = "output";
    mc.bounds = null;
    mc.relativeBounds = null;
    mc.frameState = -1;
    mc.state = Constants.MODE_STATE_JOINED;
    mc.kind = Constants.MODE_KIND_VIEW;
    mc.constraints = createDefaultOutputConstraints();
    mc.selectedTopComponentID = null;
    mc.permanent = true;
    mc.tcRefConfigs = createDefaultOutputTCRefConfigs();
    return mc;
}
Also used : ModeConfig(org.netbeans.core.windows.persistence.ModeConfig)

Example 4 with ModeConfig

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

the class GroupsManager method openGroup.

boolean openGroup(DocumentGroupImpl group) {
    DocumentGroupImpl current = getCurrentGroup();
    if (null != current && !current.close()) {
        return false;
    }
    // close documents not in our list
    WindowManagerImpl wmi = WindowManagerImpl.getInstance();
    for (TopComponent tc : TopComponent.getRegistry().getOpened()) {
        if (wmi.isEditorTopComponent(tc)) {
            if (!tc.close()) {
                return false;
            }
        }
    }
    // prune empty modes
    ArrayList<ModeImpl> emptyModes = new ArrayList<>(10);
    for (ModeImpl mode : wmi.getModes()) {
        if (mode.isPermanent() || mode.getKind() != Constants.MODE_KIND_EDITOR)
            continue;
        if (mode.getOpenedTopComponentsIDs().isEmpty()) {
            emptyModes.add(mode);
        }
    }
    for (ModeImpl mode : emptyModes) {
        wmi.removeMode(mode);
    }
    String name = group.getName();
    Preferences prefs = getPreferences().node(name);
    File userDir = Places.getUserDirectory();
    // NOI18N
    File root = new File(new File(userDir, "config"), DOCUMENT_GROUPS);
    File groupDir = new File(root, name);
    FileObject groupFO = FileUtil.toFileObject(groupDir);
    if (null != groupFO) {
        // load mode configs
        Map<ModeImpl, ModeConfig> mode2config = new HashMap<>(10);
        Map<String, ModeImpl> tcid2mode = new HashMap<>(50);
        for (FileObject fo : groupFO.getChildren()) {
            if (fo.isData() && WSMODE.equals(fo.getExt())) {
                try {
                    ModeConfig config = WindowManagerParser.loadModeConfigFrom(fo);
                    // NOI18N
                    String idList = prefs.get(config.name, "");
                    if (idList.isEmpty())
                        // ignore empty modes
                        continue;
                    ModeImpl mode = (ModeImpl) wmi.findMode(config.name);
                    if (null == mode) {
                        mode = createMode(config);
                    } else {
                        mode.setConstraints(config.constraints);
                    }
                    mode2config.put(mode, config);
                    String[] ids = idList.split(ID_SEPARATOR);
                    for (String id : ids) {
                        tcid2mode.put(id, mode);
                        mode.addUnloadedTopComponent(id);
                    }
                } catch (IOException ex) {
                    LOG.log(Level.INFO, null, ex);
                }
            }
        }
        DataLoader settingsLoader = null;
        Enumeration<DataLoader> loaders = DataLoaderPool.getDefault().producersOf(InstanceDataObject.class);
        while (loaders.hasMoreElements()) {
            settingsLoader = loaders.nextElement();
        }
        // restore TCs
        Map<String, TopComponent> id2tc = new HashMap<>(50);
        for (FileObject fo : groupFO.getChildren()) {
            if (fo.isData() && SETTINGS.equals(fo.getExt())) {
                DataObject dob;
                try {
                    // for some reason the DataLoader infrastructure insists that the first FileObject is an XMLDataObject
                    // using preferred loader ensures we always get the expected InstanceDataObject with proper instance cookies
                    DataLoaderPool.setPreferredLoader(fo, settingsLoader);
                    dob = DataObject.find(fo);
                    DataLoaderPool.setPreferredLoader(fo, null);
                    InstanceCookie ic = dob.getCookie(InstanceCookie.class);
                    if (null != ic) {
                        TopComponent tc = (TopComponent) ic.instanceCreate();
                        id2tc.put(fo.getName(), tc);
                    } else {
                        // no instance cookie, which means that module which owned top
                        // component is gone or versions of data and module are incompatible
                        String excAnnotation = NbBundle.getMessage(// NOI18N
                        PersistenceManager.class, // NOI18N
                        "EXC_BrokenTCSetting", fo.getName());
                        // resultExc = new SafeException(new IOException(excAnnotation));
                        LOG.log(Level.INFO, // NOI18N
                        "[PersistenceManager.getTopComponentForID]" + " Problem when deserializing TopComponent for tcID:'" + fo.getName() + // NOI18N //NOI18N
                        "'. Reason: " + excAnnotation);
                    }
                } catch (Exception ex) {
                    LOG.log(Level.INFO, null, ex);
                }
            }
        }
        Map<String, String> oldId2newId = new HashMap<>(id2tc.size());
        for (String oldId : id2tc.keySet()) {
            TopComponent tc = id2tc.get(oldId);
            ModeImpl mode = tcid2mode.get(oldId);
            if (null != mode) {
                mode.dockInto(tc);
            }
            tc.open();
            oldId2newId.put(oldId, wmi.findTopComponentID(tc));
        }
        // restore selection in all modes
        for (ModeImpl mode : wmi.getModes()) {
            ModeConfig config = mode2config.get(mode);
            if (null == config)
                continue;
            String selectedId = config.selectedTopComponentID;
            if (null != selectedId)
                selectedId = oldId2newId.get(selectedId);
            if (null != selectedId) {
                if (mode.getOpenedTopComponentsIDs().contains(selectedId)) {
                    TopComponent tc = wmi.findTopComponent(selectedId);
                    if (null != tc)
                        mode.setSelectedTopComponent(tc);
                }
            }
        }
    }
    // TODO restore recent view list
    getPreferences().put(SEL_GROUP, group.getName());
    return true;
}
Also used : WindowManagerImpl(org.netbeans.core.windows.WindowManagerImpl) HashMap(java.util.HashMap) ModeImpl(org.netbeans.core.windows.ModeImpl) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BackingStoreException(java.util.prefs.BackingStoreException) IOException(java.io.IOException) DataLoader(org.openide.loaders.DataLoader) InstanceDataObject(org.openide.loaders.InstanceDataObject) DataObject(org.openide.loaders.DataObject) ModeConfig(org.netbeans.core.windows.persistence.ModeConfig) InstanceCookie(org.openide.cookies.InstanceCookie) 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 5 with ModeConfig

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

the class ConfigFactory method createDefaultEditorModeConfig.

private static ModeConfig createDefaultEditorModeConfig() {
    ModeConfig mc = new ModeConfig();
    mc.name = "editor";
    mc.bounds = null;
    mc.relativeBounds = null;
    mc.frameState = -1;
    mc.state = Constants.MODE_STATE_JOINED;
    mc.kind = Constants.MODE_KIND_EDITOR;
    mc.constraints = createDefaultEditorConstraints();
    mc.selectedTopComponentID = null;
    mc.permanent = true;
    mc.tcRefConfigs = createDefaultEditorTCRefConfigs();
    return mc;
}
Also used : ModeConfig(org.netbeans.core.windows.persistence.ModeConfig)

Aggregations

ModeConfig (org.netbeans.core.windows.persistence.ModeConfig)8 IOException (java.io.IOException)3 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BackingStoreException (java.util.prefs.BackingStoreException)1 Preferences (java.util.prefs.Preferences)1 ModeImpl (org.netbeans.core.windows.ModeImpl)1 WindowManagerImpl (org.netbeans.core.windows.WindowManagerImpl)1 InstanceCookie (org.openide.cookies.InstanceCookie)1 FileObject (org.openide.filesystems.FileObject)1 DataLoader (org.openide.loaders.DataLoader)1 DataObject (org.openide.loaders.DataObject)1 InstanceDataObject (org.openide.loaders.InstanceDataObject)1 NbPreferences (org.openide.util.NbPreferences)1 TopComponent (org.openide.windows.TopComponent)1