use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.
the class DefaultView method userDroppedTopComponents.
@Override
public void userDroppedTopComponents(ModeView modeView, TopComponentDraggable draggable, int index) {
if (DEBUG) {
// NOI18N
debugLog("User dropped TopComponent's to index=" + index);
}
ModeAccessor modeAccessor = (ModeAccessor) hierarchy.getAccessorForView(modeView);
ModeImpl mode = getModeForModeAccessor(modeAccessor);
// #37127 Refine the index if the TC is moving inside the mode.
if (draggable.isTopComponentTransfer()) {
int position = Arrays.asList(modeAccessor.getOpenedTopComponents()).indexOf(draggable.getTopComponent());
if (position > -1 && position <= index) {
index--;
}
}
controllerHandler.userDroppedTopComponents(mode, draggable, index);
}
use of org.netbeans.core.windows.ModeImpl 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;
}
use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.
the class GroupsManager method createMode.
private ModeImpl createMode(ModeConfig config) {
WindowManagerImpl wmi = WindowManagerImpl.getInstance();
ModeImpl res = wmi.createMode(config.name, config.kind, config.state, false, config.constraints);
Rectangle absBounds = config.bounds == null ? new Rectangle() : config.bounds;
Rectangle relBounds = config.relativeBounds == null ? new Rectangle() : config.relativeBounds;
Rectangle bounds = PersistenceHandler.computeBounds(false, false, absBounds.x, absBounds.y, absBounds.width, absBounds.height, relBounds.x / 100.0F, relBounds.y / 100.0F, relBounds.width / 100.0F, relBounds.height / 100.0F);
res.setBounds(bounds);
res.setFrameState(config.frameState);
res.setMinimized(config.minimized);
return res;
}
use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.
the class TabbedHandler method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (e instanceof TabActionEvent) {
TabActionEvent tae = (TabActionEvent) e;
String cmd = tae.getActionCommand();
if (TabbedContainer.COMMAND_SELECT.equals(cmd)) {
return;
}
tae.consume();
if (TabbedContainer.COMMAND_CLOSE == cmd) {
// == test is safe here
TopComponent tc = tabbed.getTopComponentAt(tae.getTabIndex());
if (tc != null && modeView != null) {
modeView.getController().userClosedTopComponent(modeView, tc);
} else {
Logger.getLogger(TabbedHandler.class.getName()).warning("TopComponent to be closed is null at index " + tae.getTabIndex());
}
} else if (TabbedContainer.COMMAND_POPUP_REQUEST == cmd) {
handlePopupMenuShowing(tae.getMouseEvent(), tae.getTabIndex());
} else if (TabbedContainer.COMMAND_MAXIMIZE == cmd) {
handleMaximization(tae);
} else if (TabbedContainer.COMMAND_CLOSE_ALL == cmd) {
ActionUtils.closeAllDocuments(true);
} else if (TabbedContainer.COMMAND_CLOSE_ALL_BUT_THIS == cmd) {
TopComponent tc = tabbed.getTopComponentAt(tae.getTabIndex());
ActionUtils.closeAllExcept(tc, true);
// Pin button handling here
} else if (TabbedContainer.COMMAND_ENABLE_AUTO_HIDE.equals(cmd)) {
if (Switches.isTopComponentSlidingEnabled() && tabbed.getComponent().isShowing()) {
TopComponent tc = tabbed.getTopComponentAt(tae.getTabIndex());
// prepare slide operation
Component tabbedComp = tabbed.getComponent();
String side = WindowManagerImpl.getInstance().guessSlideSide(tc);
SlideOperation operation = SlideOperationFactory.createSlideIntoEdge(tabbedComp, side, true);
operation.setStartBounds(new Rectangle(tabbedComp.getLocationOnScreen(), tabbedComp.getSize()));
operation.prepareEffect();
modeView.getController().userEnabledAutoHide(modeView, tc);
modeView.getController().userTriggeredSlideIntoEdge(modeView, operation);
}
} else if (TabbedContainer.COMMAND_MINIMIZE_GROUP.equals(cmd)) {
if (Switches.isModeSlidingEnabled()) {
TopComponent tc = tabbed.getTopComponentAt(0);
WindowManagerImpl wm = WindowManagerImpl.getInstance();
ModeImpl mode = (ModeImpl) wm.findMode(tc);
if (null != mode) {
wm.userMinimizedMode(mode);
}
}
} else if (TabbedContainer.COMMAND_RESTORE_GROUP.equals(cmd)) {
String nameOfModeToRestore = tae.getGroupName();
if (null != nameOfModeToRestore) {
TopComponent tc = tabbed.getTopComponentAt(0);
WindowManagerImpl wm = WindowManagerImpl.getInstance();
ModeImpl slidingMode = (ModeImpl) wm.findMode(tc);
ModeImpl modeToRestore = (ModeImpl) wm.findMode(nameOfModeToRestore);
if (null != modeToRestore && null != slidingMode) {
wm.userRestoredMode(slidingMode, modeToRestore);
}
}
} else if (TabbedContainer.COMMAND_CLOSE_GROUP.equals(cmd)) {
if (Switches.isModeClosingEnabled()) {
TopComponent tc = tabbed.getTopComponentAt(0);
WindowManagerImpl wm = WindowManagerImpl.getInstance();
ModeImpl mode = (ModeImpl) wm.findMode(tc);
if (null != mode) {
wm.userClosedMode(mode);
}
}
}
} else if (e instanceof SlideBarActionEvent) {
// slide bar commands
SlideBarActionEvent sbe = (SlideBarActionEvent) e;
String cmd = sbe.getActionCommand();
if (SlideBar.COMMAND_POPUP_REQUEST.equals(cmd)) {
handlePopupMenuShowing(sbe.getMouseEvent(), sbe.getTabIndex());
} else if (SlideBar.COMMAND_SLIDE_IN.equals(cmd)) {
modeView.getController().userTriggeredSlideIn(modeView, sbe.getSlideOperation());
} else if (SlideBar.COMMAND_SLIDE_RESIZE.equals(cmd)) {
modeView.getController().userResizedSlidingWindow(modeView, sbe.getSlideOperation());
} else if (SlideBar.COMMAND_SLIDE_OUT.equals(cmd)) {
// when the call comes from the change of tehmodel rather than user clicking,
// ignore activation requests.
// #48539
SlideOperation op = new ProxySlideOperation(sbe.getSlideOperation(), ignoreChange);
modeView.getController().userTriggeredSlideOut(modeView, op);
} else if (SlideBar.COMMAND_DISABLE_AUTO_HIDE.equals(cmd)) {
TopComponent tc = tabbed.getTopComponentAt(sbe.getTabIndex());
modeView.getController().userDisabledAutoHide(modeView, tc);
} else if (SlideBar.COMMAND_MAXIMIZE == cmd) {
TopComponent tc = tabbed.getTopComponentAt(sbe.getTabIndex());
MaximizeWindowAction mwa = new MaximizeWindowAction(tc);
if (mwa.isEnabled())
mwa.actionPerformed(e);
}
}
}
use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.
the class Model method createItems.
private static Item[] createItems(boolean documentsOnly) {
WindowManagerImpl wmi = WindowManagerImpl.getInstance();
TopComponent[] windows = wmi.getRecentViewList();
ArrayList<Item> items = new ArrayList<Item>(windows.length);
for (TopComponent tc : windows) {
if (tc == null) {
continue;
}
ModeImpl mode = (ModeImpl) wmi.findMode(tc);
boolean isEditor = null != mode && mode.getKind() == Constants.MODE_KIND_EDITOR;
if (documentsOnly == isEditor) {
items.add(Item.create(tc));
}
}
return items.toArray(new Item[items.size()]);
}
Aggregations