use of org.eclipse.ui.IWorkbenchPart in project cubrid-manager by CUBRID.
the class ReplicationEditor method createActions.
/**
* @see org.eclipse.gef.ui.parts.GraphicalEditor#createActions()
*/
@SuppressWarnings("unchecked")
protected void createActions() {
super.createActions();
ActionRegistry registry = getActionRegistry();
IAction action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.LEFT);
registry.registerAction(action);
getSelectionActions().add(action.getId());
action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.RIGHT);
registry.registerAction(action);
getSelectionActions().add(action.getId());
action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.CENTER);
registry.registerAction(action);
getSelectionActions().add(action.getId());
action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.MIDDLE);
registry.registerAction(action);
getSelectionActions().add(action.getId());
action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.BOTTOM);
registry.registerAction(action);
getSelectionActions().add(action.getId());
action = new AlignmentAction((IWorkbenchPart) this, PositionConstants.TOP);
registry.registerAction(action);
getSelectionActions().add(action.getId());
action = new EditAction((IWorkbenchPart) this);
registry.registerAction(action);
getSelectionActions().add(action.getId());
}
use of org.eclipse.ui.IWorkbenchPart in project cubrid-manager by CUBRID.
the class EditAction method run.
/**
* @see org.eclipse.jface.action.Action#run()
*/
public void run() {
IWorkbenchPart workbenchPart = this.getWorkbenchPart();
if (!(workbenchPart instanceof ReplicationEditor) || !isEnabled()) {
return;
}
ReplicationEditor replEditor = (ReplicationEditor) workbenchPart;
Shell shell = replEditor.getSite().getShell();
NodePart nodePart = (NodePart) getSelectedObjects().get(0);
if (nodePart.getModel() instanceof MasterNode) {
SetMasterDbInfoWizard wizard = new SetMasterDbInfoWizard((MasterNode) nodePart.getModel());
wizard.setEditable(replEditor.isEditable());
CMWizardDialog dialog = new CMWizardDialog(shell, wizard);
dialog.setPageSize(560, 300);
dialog.open();
} else if (nodePart.getModel() instanceof DistributorNode) {
SetDistributorDbInfoDialog dialog = new SetDistributorDbInfoDialog(shell);
dialog.setDistributor((DistributorNode) nodePart.getModel());
dialog.setEditable(replEditor.isEditable());
dialog.open();
} else if (nodePart.getModel() instanceof SlaveNode) {
SetSlaveDbInfoDialog dialog = new SetSlaveDbInfoDialog(shell);
dialog.setSlave((SlaveNode) nodePart.getModel());
dialog.setEditable(replEditor.isEditable());
dialog.open();
} else if (nodePart.getModel() instanceof HostNode) {
SetHostInfoDialog dialog = new SetHostInfoDialog(shell);
dialog.setHostInfo((HostNode) nodePart.getModel());
dialog.setEditable(replEditor.isEditable());
dialog.open();
}
}
use of org.eclipse.ui.IWorkbenchPart 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.IWorkbenchPart 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.IWorkbenchPart in project sling by apache.
the class JcrPropertiesView method createPartControl.
/**
* This is a callback that will allow us
* to create the viewer and initialize it.
*/
public void createPartControl(Composite parent) {
SyncDirManager.registerUpdateListener(new UpdateHandler() {
@Override
public void syncDirUpdated(SyncDir syncDir) {
refreshContent();
}
});
mainControl = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout(1, true);
mainControl.setLayout(gridLayout);
if (getViewSite() != null) {
titleLabel = new Label(mainControl, SWT.WRAP);
titleLabel.setText("");
GridData data = new GridData(GridData.FILL_HORIZONTAL);
titleLabel.setLayoutData(data);
Label horizontalLine = new Label(mainControl, SWT.SEPARATOR | SWT.HORIZONTAL);
data = new GridData(GridData.FILL_HORIZONTAL);
horizontalLine.setLayoutData(data);
}
Font font;
if (!JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) {
FontData[] fontData = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT).getFontData();
/* title font is 2pt larger than that used in the tabs. */
fontData[0].setHeight(fontData[0].getHeight() + 2);
JFaceResources.getFontRegistry().put(TITLE_FONT, fontData);
}
font = JFaceResources.getFont(TITLE_FONT);
if (titleLabel != null) {
titleLabel.setFont(font);
}
Composite tableParent = new Composite(mainControl, SWT.NONE);
// tableParent.setBackground(new Color(Display.getDefault(), 100,20,180));
GridData tableLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
// shrink to min - table settings will resize to correct ratios
tableLayoutData.widthHint = 1;
tableLayoutData.heightHint = SWT.DEFAULT;
tableParent.setLayoutData(tableLayoutData);
TableColumnLayout tableLayout = new TableColumnLayout() {
@Override
protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
Point p = super.computeSize(composite, wHint, hHint, flushCache);
return new Point(p.x, p.y);
}
};
tableParent.setLayout(tableLayout);
viewer = new TableViewer(tableParent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.HIDE_SELECTION | SWT.FULL_SELECTION);
TableViewerFocusCellManager focusCellManager = new TableViewerFocusCellManager(viewer, new FocusCellOwnerDrawHighlighter(viewer), new CellNavigationStrategy());
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(viewer) {
@Override
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
resetLastValueEdited();
return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED && event.keyCode == SWT.CR) || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;
}
};
int features = ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK;
TableViewerEditor.create(viewer, focusCellManager, actSupport, features);
viewer.getTable().setLinesVisible(true);
viewer.getTable().setHeaderVisible(true);
viewer.setContentProvider(new ViewContentProvider());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
final ISelection selection = event.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection iss = (IStructuredSelection) selection;
if (iss.isEmpty()) {
deleteAction.setEnabled(false);
} else {
deleteAction.setEnabled(true);
}
} else {
deleteAction.setEnabled(false);
}
}
});
CellLabelProvider clp = new JcrCellLabelProvider(viewer);
TableViewerColumn column0 = new TableViewerColumn(viewer, SWT.NONE);
column0.getColumn().setText("Name");
column0.getColumn().setResizable(true);
column0.getColumn().setWidth(200);
tableLayout.setColumnData(column0.getColumn(), new ColumnWeightData(30, 140));
final TableViewerColumn column1 = new TableViewerColumn(viewer, SWT.NONE);
column1.getColumn().setText("Type");
column1.getColumn().setResizable(true);
column1.getColumn().setWidth(300);
column1.setLabelProvider(clp);
tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(10, 80));
final TableViewerColumn column2 = new TableViewerColumn(viewer, SWT.NONE);
column2.getColumn().setText("Value");
column2.getColumn().setResizable(true);
column2.getColumn().setWidth(300);
tableLayout.setColumnData(column2.getColumn(), new ColumnWeightData(70, 220));
final TableViewerColumn column3 = new TableViewerColumn(viewer, SWT.NONE);
column3.getColumn().setText("Protected");
column3.getColumn().setResizable(true);
column3.getColumn().setWidth(300);
column3.setLabelProvider(clp);
tableLayout.setColumnData(column3.getColumn(), new ColumnWeightData(5, 57));
final TableViewerColumn column4 = new TableViewerColumn(viewer, SWT.NONE);
column4.getColumn().setText("Mandatory");
column4.getColumn().setResizable(true);
column4.getColumn().setWidth(300);
column4.setLabelProvider(clp);
tableLayout.setColumnData(column4.getColumn(), new ColumnWeightData(5, 62));
final TableViewerColumn column5 = new TableViewerColumn(viewer, SWT.NONE);
column5.getColumn().setText("Multiple");
column5.getColumn().setResizable(true);
column5.getColumn().setWidth(300);
column5.setLabelProvider(clp);
tableLayout.setColumnData(column5.getColumn(), new ColumnWeightData(5, 82));
final TableViewerColumn column6 = new TableViewerColumn(viewer, SWT.NONE);
column6.getColumn().setText("Auto Created");
column6.getColumn().setResizable(true);
column6.getColumn().setWidth(300);
column6.setLabelProvider(clp);
tableLayout.setColumnData(column6.getColumn(), new ColumnWeightData(5, 77));
column0.setLabelProvider(clp);
column0.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.NAME));
column1.setLabelProvider(clp);
column1.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.TYPE));
column2.setLabelProvider(clp);
column2.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.VALUE));
column5.setEditingSupport(new JcrEditingSupport(this, viewer, ColumnId.MULTIPLE));
// Create the help context id for the viewer's control
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.apache.sling.ide.eclipse-ui.viewer");
makeActions();
hookContextMenu();
hookDoubleClickAction();
contributeToActionBars();
listener = new ISelectionListener() {
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection iss = (IStructuredSelection) selection;
Object firstElem = iss.getFirstElement();
if (firstElem instanceof JcrNode) {
JcrNode jcrNode = (JcrNode) firstElem;
setInput(jcrNode);
return;
}
}
}
};
if (getViewSite() != null) {
getViewSite().getPage().addSelectionListener(listener);
final ISelection selection = getViewSite().getPage().getSelection();
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
listener.selectionChanged(null, selection);
}
});
}
}
Aggregations