use of org.eclipse.ui.IViewPart in project cubrid-manager by CUBRID.
the class CubridWorkbenchContrItem method closeAllEditorAndViewInServer.
/**
* Close all editor and view part related with this CUBRID Manager server
* node,not include query editor
*
* @param serverNode the ICubridNode object
* @param isSaved the boolean value,if can be saved
* @return boolean whether all editors are closed
*/
public static boolean closeAllEditorAndViewInServer(ICubridNode serverNode, boolean isSaved) {
boolean isCloseAll = true;
IWorkbenchPage page = LayoutUtil.getActivePage();
if (page == null) {
return isCloseAll;
}
IEditorReference[] editorRefArr = page.getEditorReferences();
if (editorRefArr != null && editorRefArr.length > 0) {
for (IEditorReference editorRef : editorRefArr) {
try {
IEditorInput editorInput = editorRef.getEditorInput();
if (!(editorInput instanceof ICubridNode)) {
continue;
}
ICubridNode node = ((ICubridNode) editorInput).getServer();
if (node != null && node.getId().equals(serverNode.getId())) {
boolean isClosed = page.closeEditor(editorRef.getEditor(false), isSaved);
if (!isClosed) {
isCloseAll = false;
}
}
} catch (PartInitException e) {
LOGGER.error("", e);
}
}
}
IViewReference[] viewRefArr = page.getViewReferences();
if (viewRefArr != null && viewRefArr.length > 0) {
for (IViewReference viewRef : viewRefArr) {
IViewPart viewPart = viewRef.getView(false);
if (!(viewPart instanceof CubridViewPart)) {
continue;
}
CubridViewPart cubridViewPart = (CubridViewPart) viewPart;
ICubridNode cubridNode = cubridViewPart.getCubridNode();
if (cubridNode == null) {
continue;
}
ICubridNode cubridServerNode = cubridNode.getServer();
if (cubridServerNode.getId().equals(serverNode.getId())) {
page.hideView(viewPart);
}
}
}
return isCloseAll;
}
use of org.eclipse.ui.IViewPart in project cubrid-manager by CUBRID.
the class CubridWorkbenchContrItem method openEditorOrView.
/**
* Open and reopen the editor or view part of this CUBRID node
*
* @param cubridNode the ICubridNode object
*/
public void openEditorOrView(ICubridNode cubridNode) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return;
}
if (cubridNode instanceof ISchemaNode) {
ISchemaNode schemaNode = (ISchemaNode) cubridNode;
if (schemaNode.getDatabase() != null && !schemaNode.getDatabase().isLogined()) {
return;
}
}
//close the editor part that has been open
String editorId = cubridNode.getEditorId();
String viewId = cubridNode.getViewId();
IWorkbenchPart workbenchPart = null;
if (editorId != null && editorId.trim().length() > 0) {
IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, editorId);
if (editorPart != null) {
window.getActivePage().closeEditor(editorPart, false);
}
} else if (viewId != null && viewId.trim().length() > 0) {
IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, viewId);
if (viewPart != null) {
// monitor view part do not need to close and then open
if (MONITOR_VIEWID_LST.contains(viewId)) {
workbenchPart = viewPart;
window.getActivePage().bringToTop(viewPart);
} else {
window.getActivePage().hideView(viewPart);
}
}
}
String nodeType = cubridNode.getType();
ISelectionAction logViewAction = null;
if (NodeType.contains(nodeType, new String[] { CubridNodeType.BROKER_SQL_LOG, CubridNodeType.LOGS_BROKER_ACCESS_LOG, CubridNodeType.LOGS_BROKER_ERROR_LOG, CubridNodeType.LOGS_BROKER_ADMIN_LOG, CubridNodeType.LOGS_SERVER_DATABASE_LOG })) {
logViewAction = (ISelectionAction) ActionManager.getInstance().getAction(LogViewAction.ID);
((LogViewAction) logViewAction).setCubridNode(cubridNode);
} else if (NodeType.contains(nodeType, new String[] { CubridNodeType.LOGS_MANAGER_ACCESS_LOG, CubridNodeType.LOGS_MANAGER_ERROR_LOG })) {
logViewAction = (ISelectionAction) ActionManager.getInstance().getAction(ManagerLogViewAction.ID);
((ManagerLogViewAction) logViewAction).setCubridNode(cubridNode);
}
if (logViewAction != null && logViewAction.isSupported(cubridNode)) {
logViewAction.run();
return;
}
if (!StringUtil.isEmpty(editorId)) {
try {
if (cubridNode instanceof ISchemaNode) {
CubridDatabase database = ((ISchemaNode) cubridNode).getDatabase();
// Judge database is started and open DatabaseDashboardEditor
if (StringUtil.isEqual(editorId, DatabaseDashboardEditor.ID)) {
if (!DbRunningType.CS.equals(database.getRunningType())) {
return;
}
}
// if open the table schema editor,firstly load the schema
if (StringUtil.isEqual(editorId, SchemaInfoEditorPart.ID)) {
SchemaInfo newSchema = database.getDatabaseInfo().getSchemaInfo(cubridNode.getName());
if (newSchema == null) {
CommonUITool.openErrorBox(database.getDatabaseInfo().getErrorMessage());
return;
}
}
}
workbenchPart = window.getActivePage().openEditor(cubridNode, editorId, true, IWorkbenchPage.MATCH_ID & IWorkbenchPage.MATCH_INPUT);
} catch (PartInitException e) {
LOGGER.error("", e);
}
} else if (viewId != null && viewId.trim().length() > 0) {
try {
if (MONITOR_VIEWID_LST.contains(viewId)) {
if (workbenchPart == null) {
String secondId = LayoutUtil.getViewSecondId(cubridNode);
workbenchPart = window.getActivePage().showView(viewId, secondId, IWorkbenchPage.VIEW_CREATE | IWorkbenchPage.VIEW_ACTIVATE | IWorkbenchPage.VIEW_VISIBLE);
window.getActivePage().bringToTop(workbenchPart);
}
} else {
workbenchPart = window.getActivePage().showView(viewId);
}
} catch (Exception e) {
LOGGER.error("", e);
}
}
if (workbenchPart != null) {
LayoutManager.getInstance().getTitleLineContrItem().changeTitleForViewOrEditPart(cubridNode, workbenchPart);
LayoutManager.getInstance().getStatusLineContrItem().changeStuatusLineForViewOrEditPart(cubridNode, workbenchPart);
}
}
use of org.eclipse.ui.IViewPart in project cubrid-manager by CUBRID.
the class CubridTitleLineContrItem method getTitleForViewOrEdit.
/**
*
* Get the title of view or editor(not including query editor)
*
* @param cubridNode the ICubridNode object
* @param workbenchPart the IWorkbenchPart object
* @return String
*/
protected String getTitleForViewOrEdit(ICubridNode cubridNode, IWorkbenchPart workbenchPart) {
StringBuffer titleStrBuffer = new StringBuffer();
if (cubridNode instanceof ISchemaNode) {
ISchemaNode schemaNode = (ISchemaNode) cubridNode;
CubridDatabase database = schemaNode.getDatabase();
titleStrBuffer.append(database.getLabel());
}
String partTitle = "";
if (workbenchPart == null) {
if (null != cubridNode.getViewId()) {
IViewPart viewPart = LayoutUtil.getViewPart(cubridNode, cubridNode.getViewId());
if (viewPart != null) {
partTitle = viewPart.getTitle();
}
}
if (null != cubridNode.getEditorId()) {
IEditorPart editorPart = LayoutUtil.getEditorPart(cubridNode, cubridNode.getEditorId());
if (editorPart != null) {
partTitle = editorPart.getTitle();
}
}
} else {
partTitle = workbenchPart.getTitle();
}
if (partTitle != null && partTitle.trim().length() > 0) {
titleStrBuffer.append(" / " + partTitle);
}
return titleStrBuffer.toString();
}
use of org.eclipse.ui.IViewPart in project sling by apache.
the class StatusLineUtils method getStatusLineManager.
private static IStatusLineManager getStatusLineManager() {
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null) {
return null;
}
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage == null) {
return null;
}
IEditorPart activeEditor = activePage.getActiveEditor();
if (activeEditor != null) {
return activeEditor.getEditorSite().getActionBars().getStatusLineManager();
}
IViewReference[] viewRefs = activePage.getViewReferences();
if (viewRefs != null) {
for (IViewReference aViewRef : viewRefs) {
IViewPart view = aViewRef.getView(false);
if (view != null) {
return view.getViewSite().getActionBars().getStatusLineManager();
}
}
}
IEditorReference[] editorRefs = activePage.getEditorReferences();
if (editorRefs != null) {
for (IEditorReference anEditorRef : editorRefs) {
IEditorPart editor = anEditorRef.getEditor(false);
if (editor != null) {
return editor.getEditorSite().getActionBars().getStatusLineManager();
}
}
}
IWorkbenchPart activePart = activePage.getActivePart();
if (activePart == null) {
return null;
}
IWorkbenchPartSite site = activePart.getSite();
if (site instanceof IEditorSite) {
IEditorSite editorSite = (IEditorSite) site;
return editorSite.getActionBars().getStatusLineManager();
} else if (site instanceof IViewSite) {
IViewSite viewSite = (IViewSite) site;
return viewSite.getActionBars().getStatusLineManager();
} else {
return null;
}
}
use of org.eclipse.ui.IViewPart in project sling by apache.
the class PackageExplorerOpenActionProvider method init.
@Override
public void init(ICommonActionExtensionSite site) {
super.init(site);
action = new OpenFileAction(getActivePage());
ICommonViewerWorkbenchSite workbenchSite = null;
if (site.getViewSite() instanceof ICommonViewerWorkbenchSite)
workbenchSite = (ICommonViewerWorkbenchSite) site.getViewSite();
if (workbenchSite != null) {
if (workbenchSite.getPart() != null && workbenchSite.getPart() instanceof IViewPart) {
IViewPart viewPart = (IViewPart) workbenchSite.getPart();
if (site.getStructuredViewer() instanceof TreeViewer) {
treeViewer = (TreeViewer) site.getStructuredViewer();
treeViewer.addSelectionChangedListener(action);
}
fInViewPart = true;
}
}
}
Aggregations