private FragmentTransaction doTabChanged(String tabId, FragmentTransaction ft) { TabInfo newTab = null; for (int i = 0; i < mTabs.size(); i++) { TabInfo tab = mTabs.get(i); if (tab.tag.equals(tabId)) { newTab = tab; } } if (newTab == null) { throw new IllegalStateException("No tab known for tag " + tabId); } if (mLastTab != newTab) { if (ft == null) { ft = mFragmentManager.beginTransaction(); } if (mLastTab != null) { if (mLastTab.fragment != null) { // ft.detach(mLastTab.fragment); ft.hide(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(mContext, newTab.clss.getName(), newTab.args); ft.add(mContainerId, newTab.fragment, newTab.tag); } else { // ft.attach(newTab.fragment); ft.show(newTab.fragment); } } mLastTab = newTab; } return ft; }
@Override public void onTabChanged(String tabId) { TabInfo newTab = mTabs.get(tabId); if (mLastTab != newTab) { FragmentTransaction ft = mActivity.getFragmentManager().beginTransaction(); if (mLastTab != null) { if (mLastTab.fragment != null) { ft.hide(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(mActivity, newTab.clss.getName(), newTab.args); ft.add(mContainerId, newTab.fragment, newTab.tag); // Log.i(LOG_TAG, "onTabChanged with tabId:" + tabId // + ", newTab.fragment is null, newTab.tag is " // + newTab.tag); } else { ft.show(newTab.fragment); // Log.i(LOG_TAG, "onTabChanged with tabId:" + tabId // + ", show fragment success"); } } else { // Log.i(LOG_TAG, "onTabChanged with tabId:" + tabId // + ", newTab is null"); } mLastTab = newTab; ft.commit(); mActivity.getFragmentManager().executePendingTransactions(); } mActivity.onTabChanged(tabId); }
public void insertTab( final VirtualFile file, final Icon icon, final JComponent comp, final String tooltip, final int indexToInsert) { TabInfo tab = myTabs.findInfo(file); if (tab != null) return; tab = new TabInfo(comp) .setText(calcTabTitle(myProject, file)) .setIcon(icon) .setTooltipText(tooltip) .setObject(file) .setTabColor(calcTabColor(myProject, file)) .setDragOutDelegate(myDragOutDelegate); tab.setTestableUi(new MyQueryable(tab)); final DefaultActionGroup tabActions = new DefaultActionGroup(); tabActions.add(new CloseTab(comp, tab)); tab.setTabLabelActions(tabActions, ActionPlaces.EDITOR_TAB); myTabs.addTab(tab, indexToInsert); }
public Fragment getItem(int position) { TabInfo info = mTabs.get(position); if (info.fragment == null) { info.fragment = Fragment.instantiate(mContext, info.clss.getName(), info.args); } return info.fragment; }
@Override public Object instantiateItem(ViewGroup container, int position) { TabInfo tab = tabs.get(position); BaseFragment fragment = (BaseFragment) super.instantiateItem(container, position); tab.fragment = fragment; return fragment; }
@Override public void onCheckedChanged(RadioGroup group, int checkedId) { TabInfo newTab = mTabs.get("" + checkedId); if (mLastTab != newTab) { FragmentTransaction ft = mFragmentManager.beginTransaction(); if (mLastTab != null) { if (mLastTab.fragment != null) { ft.detach(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = (BaseFragment) Fragment.instantiate(group.getContext(), newTab.clss.getName(), newTab.args); ft.add(mContainerId, newTab.fragment, newTab.tag); } else { ft.attach(newTab.fragment); } } mLastTab = newTab; ft.commit(); mFragmentManager.executePendingTransactions(); } }
@Override public Object instantiateItem(ViewGroup container, int position) { TabInfo tab = mTabs.get(position); View root = tab.build(mInflater, mContentContainer, mRootView); container.addView(root); return root; }
public void addTabs(TabInfo... tabInfos) { if (tabInfos == null || tabInfos.length < 1) { return; } for (TabInfo tabInfo : tabInfos) { if (tabInfo == null) { break; } View page = tabInfo.getPage(); View item = tabInfo.getItem(); item.setOnClickListener(onSelectorClickListener); if (page instanceof Pageable) { Pageable pageable = (Pageable) page; pageable.onInit(this); } ViewGroup.LayoutParams itemParams = tabInfo.getItemParams(); if (itemParams == null) { itemBar.addView(item); } else { itemBar.addView(item, itemParams); } adapter.add(page); tabs.add(new Pair<View, View>(item, page)); } onGlobalLayout(); }
@Override public Object instantiateItem(ViewGroup container, int position) { final Fragment fragment = (Fragment) super.instantiateItem(container, position); final TabInfo info = mTabs.get(position); info.tag = fragment.getTag(); // set it here info.fragment = fragment; return fragment; }
@Override public Fragment getItem(int position) { TabInfo info = mTabInfos.get(position); if (info.fragment == null) info.fragment = Fragment.instantiate(mActivity, info._clss.getName(), info._args); return info.fragment; }
@Override public android.support.v4.app.Fragment getItem(int position) { TabInfo info = mTabs.get(position); if (info.fragment == null) { info.fragment = android.support.v4.app.Fragment.instantiate(mContext, info.clss.getName(), info.args); } return info.fragment; }
protected TabInfo getFragmentById(int tabId) { if (mTabs == null) return null; for (int index = 0, count = mTabs.size(); index < count; index++) { TabInfo tab = mTabs.get(index); if (tab.getId() == tabId) { return tab; } } return null; }
@Override public Fragment getItem(int pos) { Fragment fragment = null; if (tabs != null && pos < tabs.size()) { TabInfo tab = tabs.get(pos); if (tab == null) return null; fragment = tab.createFragment(); } return fragment; // return MyPageFragment.create(pos); }
@Override public void mouseReleased(MouseEvent e) { if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) { final TabInfo info = myTabs.findInfo(e); if (info != null) { IdeEventQueue.getInstance().blockNextEvents(e); FileEditorManagerEx.getInstanceEx(myProject) .closeFile((VirtualFile) info.getObject(), myWindow); } } }
@Override public void mouseClicked(MouseEvent e) { if (UIUtil.isActionClick(e, MouseEvent.MOUSE_CLICKED) && (e.isMetaDown() || (!SystemInfo.isMac && e.isControlDown()))) { final TabInfo info = myTabs.findInfo(e); if (info != null && info.getObject() != null) { final VirtualFile vFile = (VirtualFile) info.getObject(); ShowFilePathAction.show(vFile, e); } } }
public void addTab(int radioButtonId, Class<?> clss, String tag, Bundle args) { String tabId = "" + radioButtonId; TabInfo info = new TabInfo(tag, clss, args); info.fragment = (BaseFragment) mFragmentManager.findFragmentByTag(tag); if (info.fragment != null && !info.fragment.isDetached()) { FragmentTransaction ft = mFragmentManager.beginTransaction(); ft.detach(info.fragment); ft.commit(); } mTabs.put(tabId, info); }
public ActionCallback removeTabAt( final int componentIndex, int indexToSelect, boolean transferFocus) { TabInfo toSelect = indexToSelect >= 0 && indexToSelect < myTabs.getTabCount() ? myTabs.getTabAt(indexToSelect) : null; final TabInfo info = myTabs.getTabAt(componentIndex); // removing hidden tab happens on end of drag-out, we've already selected the correct tab for // this case in dragOutStarted if (info.isHidden()) { toSelect = null; } final ActionCallback callback = myTabs.removeTab(info, toSelect, transferFocus); return myProject.isOpen() ? callback : new ActionCallback.Done(); }
@Override protected void publishResults(CharSequence constraint, FilterResults results) { mCurFilterPrefix = constraint; mEntries = (ArrayList<ApplicationsState.AppEntry>) results.values; notifyDataSetChanged(); mTab.updateStorageUsage(); }
@Override public void onAllSizesComputed() { if (mLastSortMode == SORT_ORDER_SIZE) { rebuild(false); } mTab.updateStorageUsage(); }
@Override public void dragOutStarted(MouseEvent mouseEvent, TabInfo info) { final TabInfo previousSelection = info.getPreviousSelection(); final Image img = myTabs.getComponentImage(info); info.setHidden(true); if (previousSelection != null) { myTabs.select(previousSelection, true); } myFile = (VirtualFile) info.getObject(); Presentation presentation = new Presentation(info.getText()); presentation.setIcon(info.getIcon()); mySession = getDockManager() .createDragSession( mouseEvent, new DockableEditor(img, myFile, presentation, myWindow)); }
public static TabInfo getTabInfoByIndex(int index) { TabInfo info = null; if (sTabInfoList != null && index >= 0 && index < sTabInfoList.size()) { final int size = sTabInfoList.size(); for (int i = 0; i < size; i++) { TabInfo t = sTabInfoList.get(i); if (t.getTabbarIndex() == index) { info = t; break; } } if (info == null) { // sTabInfoList裏的TabInfo沒有設置index的話,按list的順序取得. info = sTabInfoList.get(index); } } return info; }
public List<SwitchTarget> getTargets(final boolean onlyVisible, boolean originalProvider) { final ArrayList<SwitchTarget> result = new ArrayList<SwitchTarget>(); TabInfo selected = myTabs.getSelectedInfo(); new AwtVisitor(selected.getComponent()) { @Override public boolean visit(Component component) { if (component instanceof JBTabs) { JBTabs tabs = (JBTabs) component; if (tabs != myTabs) { result.addAll(tabs.getTargets(onlyVisible, false)); return true; } } return false; } }; return result; }
public void addTab(final TabHost.TabSpec tabSpec, final Class<?> clss, final Bundle args) { tabSpec.setContent(new DummyTabFactory(mActivity)); final String tag = tabSpec.getTag(); final TabInfo info = new TabInfo(tag, clss, args); // Check to see if we already have a fragment for this tab, probably // from a previously saved state. If so, deactivate it, because our // initial state is that a tab isn't shown. info.fragment = mActivity.getSupportFragmentManager().findFragmentByTag(tag); if (info.fragment != null && !info.fragment.isDetached()) { final FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction(); ft.detach(info.fragment); ft.commit(); } mTabs.put(tag, info); mTabHost.addTab(tabSpec); }
public SwitchTarget getCurrentTarget() { TabInfo selected = myTabs.getSelectedInfo(); final Ref<SwitchTarget> targetRef = new Ref<SwitchTarget>(); new AwtVisitor(selected.getComponent()) { @Override public boolean visit(Component component) { if (component instanceof JBTabs) { JBTabs tabs = (JBTabs) component; if (tabs != myTabs) { targetRef.set(tabs.getCurrentTarget()); return true; } } return false; } }; return targetRef.get(); }
@Override public void dragOutCancelled(TabInfo source) { source.setHidden(false); if (mySession != null) { mySession.cancel(); } myFile = null; mySession = null; }
public void close() { TabInfo selected = myTabs.getTargetInfo(); if (selected == null) return; final VirtualFile file = (VirtualFile) selected.getObject(); final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject); AsyncResult<EditorWindow> window = mgr.getActiveWindow(); window.doWhenDone( new AsyncResult.Handler<EditorWindow>() { @Override public void run(EditorWindow wnd) { if (wnd != null) { if (wnd.findFileComposite(file) != null) { mgr.closeFile(file, wnd); } } } }); }
public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) { tabSpec.setContent(new DummyTabFactory(mContext)); String tag = tabSpec.getTag(); TabInfo info = new TabInfo(tag, clss, args); if (mAttached) { // If we are already attached to the window, then check to make // sure this tab's fragment is inactive if it exists. This shouldn't // normally happen. info.fragment = mFragmentManager.findFragmentByTag(tag); if (info.fragment != null && !info.fragment.isDetached()) { FragmentTransaction ft = mFragmentManager.beginTransaction(); ft.detach(info.fragment); ft.commit(); } } mTabs.add(info); addTab(tabSpec); }
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); String currentTab = getCurrentTabTag(); // Go through all tabs and make sure their fragments match // the correct state. FragmentTransaction ft = null; for (int i = 0; i < mTabs.size(); i++) { TabInfo tab = mTabs.get(i); tab.fragment = mFragmentManager.findFragmentByTag(tab.tag); // if (tab.fragment != null && !tab.fragment.isDetached()) { if (tab.fragment != null) { if (tab.tag.equals(currentTab)) { // The fragment for this tab is already there and // active, and it is what we really want to have // as the current tab. Nothing to do. mLastTab = tab; } else { // This fragment was restored in the active state, // but is not the current tab. Deactivate it. if (ft == null) { ft = mFragmentManager.beginTransaction(); } // ft.detach(tab.fragment); ft.hide(tab.fragment); } } } // We are now ready to go. Make sure we are switched to the // correct tab. mAttached = true; ft = doTabChanged(currentTab, ft); if (ft != null) { ft.commit(); mFragmentManager.executePendingTransactions(); } }
public void updateCurrentTab(int position) { TabInfo tab = mTabs.get(position); mCurTab = tab; // Put things in the correct paused/resumed state. if (mActivityResumed) { mCurTab.build(mInflater, mContentContainer, mRootView); mCurTab.resume(mSortOrder); } else { mCurTab.pause(); } for (int i = 0; i < mTabs.size(); i++) { TabInfo t = mTabs.get(i); if (t != mCurTab) { t.pause(); } } mCurTab.updateStorageUsage(); updateOptionsMenu(); final Activity host = getActivity(); if (host != null) { host.invalidateOptionsMenu(); } }
public void onTabChanged(String tabId) { TabInfo newTab = mTabs.get(tabId); if (mLastTab != newTab) { FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction(); if (mLastTab != null) { if (mLastTab.fragment != null) { ft.detach(mLastTab.fragment); } } if (newTab != null) { if (newTab.fragment == null) { newTab.fragment = Fragment.instantiate(mActivity, newTab.clss.getName(), newTab.args); ft.add(mContainerId, newTab.fragment, newTab.tag); } else { ft.attach(newTab.fragment); } } mLastTab = newTab; ft.commit(); mActivity.getSupportFragmentManager().executePendingTransactions(); } }