提交 ae85993a 编写于 作者: J jurgen

Editor model refactoring

上级 290b82c8
......@@ -21,6 +21,7 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.graphics.Image;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPEvent;
import org.jkiss.dbeaver.model.runtime.DBRProcessListener;
......@@ -121,7 +122,7 @@ public class DBNDataSource extends DBNDatabaseNode implements IAdaptable
}
@Override
public boolean initializeNode(DBRProgressMonitor monitor, DBRProcessListener onFinish)
public boolean initializeNode(@Nullable DBRProgressMonitor monitor, DBRProcessListener onFinish)
{
if (dataSource == null) {
return false;
......
......@@ -40,12 +40,10 @@ public class NavigatorHandlerLinkEditor extends AbstractHandler {
if (activePart instanceof NavigatorViewBase) {
if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
if (editorInput != null) {
DBNNode dbnNode = editorInput.getTreeNode();
if (dbnNode != null) {
NavigatorViewBase view = (NavigatorViewBase)activePart;
view.showNode(dbnNode);
}
DBNNode dbnNode = editorInput.getNavigatorNode();
if (dbnNode != null) {
NavigatorViewBase view = (NavigatorViewBase)activePart;
view.showNode(dbnNode);
}
} else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
IFile editorFile = ((ProjectFileEditorInput)activeEditor.getEditorInput()).getFile();
......
......@@ -147,7 +147,7 @@ public class NavigatorHandlerObjectOpen extends NavigatorHandlerObjectBase imple
} catch (PartInitException e) {
continue;
}
if (editorInput instanceof EntityEditorInput && ((EntityEditorInput) editorInput).getTreeNode() == selectedNode) {
if (editorInput instanceof EntityEditorInput && ((EntityEditorInput) editorInput).getNavigatorNode() == selectedNode) {
final IEditorPart editor = ref.getEditor(true);
if (editor instanceof IFolderContainer) {
// Activate default folder
......
......@@ -53,7 +53,7 @@ public class DatabaseEditorAdapterFactory implements IAdapterFactory
if (adaptableObject instanceof IEditorPart) {
IEditorInput editorInput = ((IEditorPart) adaptableObject).getEditorInput();
if (editorInput instanceof IDatabaseEditorInput) {
DBNNode node = ((IDatabaseEditorInput) editorInput).getTreeNode();
DBNNode node = ((IDatabaseEditorInput) editorInput).getNavigatorNode();
if (node != null) {
DBSObject object = ((DBSWrapper)node).getObject();
if (object != null && adapterType.isAssignableFrom(object.getClass())) {
......
......@@ -134,7 +134,7 @@ public abstract class DatabaseEditorInput<NODE extends DBNDatabaseNode> implemen
}
@Override
public NODE getTreeNode()
public NODE getNavigatorNode()
{
return node;
}
......@@ -198,7 +198,7 @@ public abstract class DatabaseEditorInput<NODE extends DBNDatabaseNode> implemen
if (propertySource == null) {
propertySource = new PropertySourceEditable(
getCommandContext(),
getTreeNode(),
getNavigatorNode(),
getDatabaseObject());
propertySource.collectProperties();
}
......
......@@ -28,7 +28,6 @@ import org.eclipse.ui.IMemento;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.core.DBeaverCore;
import org.jkiss.dbeaver.core.DBeaverUI;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.navigator.DBNDataSource;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
......@@ -68,7 +67,7 @@ public class DatabaseEditorInputFactory implements IElementFactory
}
@Override
public IAdaptable createElement(IMemento memento)
public IAdaptable createElement(IMemento memento)
{
// Get the node path.
final String inputClass = memento.getString(TAG_CLASS);
......@@ -174,7 +173,7 @@ public class DatabaseEditorInputFactory implements IElementFactory
// Detached - nothing to save
return;
}
DBNDatabaseNode node = input.getTreeNode();
DBNDatabaseNode node = input.getNavigatorNode();
memento.putString(TAG_CLASS, input.getClass().getName());
memento.putString(TAG_DATA_SOURCE, context.getDataSource().getContainer().getId());
memento.putString(TAG_NODE, node.getNodeItemPath());
......
......@@ -38,7 +38,7 @@ public class DatabaseEditorListener implements IDBNListener
DatabaseEditorListener(IDatabaseEditor databaseEditor) {
this.databaseEditor = databaseEditor;
// Acquire datasource
dataSourceContainer = databaseEditor.getEditorInput().getTreeNode().getDataSourceContainer();
dataSourceContainer = databaseEditor.getEditorInput().getNavigatorNode().getDataSourceContainer();
if (dataSourceContainer != null) {
dataSourceContainer.acquire(databaseEditor);
}
......@@ -60,7 +60,7 @@ public class DatabaseEditorListener implements IDBNListener
public DBNNode getTreeNode()
{
return databaseEditor.getEditorInput().getTreeNode();
return databaseEditor.getEditorInput().getNavigatorNode();
}
@Override
......
......@@ -33,7 +33,7 @@ import java.util.Collection;
*/
public interface IDatabaseEditorInput extends IEditorInput, DBPContextProvider {
DBNDatabaseNode getTreeNode();
DBNDatabaseNode getNavigatorNode();
DBSObject getDatabaseObject();
......
......@@ -152,19 +152,16 @@ public class EntityEditor extends MultiPageDatabaseEditor
GlobalContributorManager.getInstance().removeContributor(entry.getValue(), entry.getKey());
}
actionContributors.clear();
//final DBPDataSource dataSource = getDataSource();
// if (getCommandContext() != null && getCommandContext().isDirty()) {
// getCommandContext().resetChanges();
// }
if (commandListener != null && getCommandContext() != null) {
getCommandContext().removeCommandListener(commandListener);
DBECommandContext commandContext = getCommandContext();
if (commandListener != null && commandContext != null) {
commandContext.removeCommandListener(commandListener);
commandListener = null;
}
super.dispose();
if (getDatabaseObject() != null) {
getCommandContext().resetChanges();
if (getDatabaseObject() != null && commandContext != null) {
commandContext.resetChanges();
// // Remove all non-persisted objects
// for (DBPObject object : getCommandContext().getEditedObjects()) {
// if (object instanceof DBPPersistedObject && !((DBPPersistedObject)object).isPersisted()) {
......@@ -240,8 +237,9 @@ public class EntityEditor extends MultiPageDatabaseEditor
if (previewResult == IDialogConstants.PROCEED_ID) {
Throwable error = null;
final DBECommandContext commandContext = getCommandContext();
try {
getCommandContext().saveChanges(monitorWrapper);
commandContext.saveChanges(monitorWrapper);
} catch (DBException e) {
error = e;
}
......@@ -258,14 +256,14 @@ public class EntityEditor extends MultiPageDatabaseEditor
// Refresh underlying node
// It'll refresh database object and all it's descendants
// So we'll get actual data from database
final DBNDatabaseNode treeNode = getEditorInput().getTreeNode();
final DBNDatabaseNode treeNode = getEditorInput().getNavigatorNode();
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
try {
treeNode.refreshNode(monitor, getCommandContext());
treeNode.refreshNode(monitor, commandContext);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
......@@ -301,8 +299,9 @@ public class EntityEditor extends MultiPageDatabaseEditor
public void undoChanges()
{
if (getCommandContext() != null && getCommandContext().getUndoCommand() != null) {
if (!getDatabaseObject().isPersisted() && getCommandContext().getUndoCommands().size() == 1) {
DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.getUndoCommand() != null) {
if (!getDatabaseObject().isPersisted() && commandContext.getUndoCommands().size() == 1) {
//getSite().getPage().closeEditor(this, true);
//return;
// Undo of last command in command context will close editor
......@@ -316,25 +315,27 @@ public class EntityEditor extends MultiPageDatabaseEditor
return;
}
}
getCommandContext().undoCommand();
commandContext.undoCommand();
firePropertyChange(IEditorPart.PROP_DIRTY);
}
}
public void redoChanges()
{
if (getCommandContext() != null && getCommandContext().getRedoCommand() != null) {
getCommandContext().redoCommand();
DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.getRedoCommand() != null) {
commandContext.redoCommand();
firePropertyChange(IEditorPart.PROP_DIRTY);
}
}
public int showChanges(boolean allowSave)
{
if (getCommandContext() == null) {
DBECommandContext commandContext = getCommandContext();
if (commandContext == null) {
return IDialogConstants.CANCEL_ID;
}
Collection<? extends DBECommand> commands = getCommandContext().getFinalCommands();
Collection<? extends DBECommand> commands = commandContext.getFinalCommands();
StringBuilder script = new StringBuilder();
for (DBECommand command : commands) {
try {
......@@ -421,7 +422,7 @@ public class EntityEditor extends MultiPageDatabaseEditor
hasPropertiesEditor = addEditorTab(defaultEditor);
}
if (hasPropertiesEditor) {
DBNNode node = getEditorInput().getTreeNode();
DBNNode node = getEditorInput().getNavigatorNode();
int propEditorIndex = getPageCount() - 1;
setPageText(propEditorIndex, CoreMessages.editors_entity_properties_text);
setPageToolTip(propEditorIndex, node.getNodeType() + CoreMessages.editors_entity_properties_tooltip_suffix);
......@@ -430,7 +431,7 @@ public class EntityEditor extends MultiPageDatabaseEditor
/*
if (!mainAdded) {
try {
DBNNode node = getEditorInput().getTreeNode();
DBNNode node = getEditorInput().getNavigatorNode();
int index = addPage(new ObjectPropertiesEditor(node), getEditorInput());
setPageText(index, "Properties");
if (node instanceof DBNDatabaseNode) {
......@@ -490,7 +491,7 @@ public class EntityEditor extends MultiPageDatabaseEditor
tabs.addAll(collectTabs(monitor));
}
};
DBNDatabaseNode node = getEditorInput().getTreeNode();
DBNDatabaseNode node = getEditorInput().getNavigatorNode();
try {
if (node.needsInitialization()) {
DBeaverUI.runInProgressService(tabsCollector);
......@@ -577,7 +578,7 @@ public class EntityEditor extends MultiPageDatabaseEditor
getSite().getShell(),
DBeaverPreferences.CONFIRM_ENTITY_EDIT_CLOSE,
ConfirmationDialog.QUESTION_WITH_CANCEL,
getEditorInput().getTreeNode().getNodeName());
getEditorInput().getNavigatorNode().getNodeName());
if (result == IDialogConstants.YES_ID) {
// getWorkbenchPart().getSite().getPage().saveEditor(this, false);
return ISaveablePart2.YES;
......@@ -648,7 +649,7 @@ public class EntityEditor extends MultiPageDatabaseEditor
List<TabInfo> tabs = new ArrayList<TabInfo>();
// Add all nested folders as tabs
DBNDatabaseNode node = getEditorInput().getTreeNode();
DBNDatabaseNode node = getEditorInput().getNavigatorNode();
if (node instanceof DBNDataSource &&
(node.getDataSourceContainer() == null || !node.getDataSourceContainer().isConnected()))
{
......@@ -776,7 +777,7 @@ public class EntityEditor extends MultiPageDatabaseEditor
if (hasPropertiesEditor) {
// Update main editor image
setPageImage(0, getEditorInput().getTreeNode().getNodeIconDefault());
setPageImage(0, getEditorInput().getNavigatorNode().getNodeIconDefault());
}
}
......@@ -807,7 +808,7 @@ public class EntityEditor extends MultiPageDatabaseEditor
infoGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
infoGroup.setLayout(new RowLayout());
DBNDatabaseNode node = getEditorInput().getTreeNode();
DBNDatabaseNode node = getEditorInput().getNavigatorNode();
List<DBNDatabaseNode> nodeList = new ArrayList<DBNDatabaseNode>();
for (DBNNode n = node; n != null; n = n.getParentNode()) {
......@@ -851,7 +852,7 @@ public class EntityEditor extends MultiPageDatabaseEditor
@Override
public DBNNode getRootNode() {
return getEditorInput().getTreeNode();
return getEditorInput().getNavigatorNode();
}
@Nullable
......
......@@ -44,7 +44,7 @@ public class EntityEditorInput extends DatabaseEditorInput<DBNDatabaseNode>
{
StringBuilder toolTip = new StringBuilder();
for (DBNNode node = getTreeNode(); node != null; node = node.getParentNode()) {
for (DBNNode node = getNavigatorNode(); node != null; node = node.getParentNode()) {
if (node instanceof DBSFolder) {
continue;
}
......
......@@ -40,7 +40,7 @@ public class FolderEditor extends SinglePageDatabaseEditor<FolderEditorInput> im
@Override
public void createPartControl(Composite parent)
{
itemControl = new ItemListControl(parent, SWT.NONE, this.getSite(), getEditorInput().getTreeNode(), null);
itemControl = new ItemListControl(parent, SWT.NONE, this.getSite(), getEditorInput().getNavigatorNode(), null);
itemControl.createProgressPanel();
itemControl.loadData();
getSite().setSelectionProvider(itemControl.getSelectionProvider());
......@@ -48,7 +48,7 @@ public class FolderEditor extends SinglePageDatabaseEditor<FolderEditorInput> im
@Override
public DBNNode getRootNode() {
return getEditorInput().getTreeNode();
return getEditorInput().getNavigatorNode();
}
@Nullable
......
......@@ -88,7 +88,7 @@ public class ObjectPropertiesEditor extends AbstractDatabaseObjectEditor<DBSObje
pageControl = new ObjectEditorPageControl(parent, SWT.SHEET, this);
pageControl.setShowDivider(true);
DBNNode node = getEditorInput().getTreeNode();
DBNNode node = getEditorInput().getNavigatorNode();
Composite container = new Composite(pageControl, SWT.NONE);
GridLayout gl = new GridLayout(1, false);
......@@ -379,7 +379,7 @@ public class ObjectPropertiesEditor extends AbstractDatabaseObjectEditor<DBSObje
private void makeDatabaseEditorTabs(final IDatabaseEditor part, final List<FolderInfo> tabList)
{
final DBNDatabaseNode node = part.getEditorInput().getTreeNode();
final DBNDatabaseNode node = part.getEditorInput().getNavigatorNode();
final DBSObject object = node.getObject();
// Collect tabs from navigator tree model
......
......@@ -18,7 +18,6 @@
package org.jkiss.dbeaver.ui.editors.object;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorDescriptor;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseObject;
import org.jkiss.dbeaver.ui.editors.DatabaseEditorInput;
......@@ -35,7 +34,7 @@ public class ObjectEditorInput extends DatabaseEditorInput<DBNDatabaseObject>
@Override
public ImageDescriptor getImageDescriptor()
{
DBNDatabaseObject node = getTreeNode();
DBNDatabaseObject node = getNavigatorNode();
// IEditorDescriptor editorDescriptor = node.getEditorDescriptor();
// if (editorDescriptor != null) {
// return editorDescriptor.getImageDescriptor();
......@@ -47,7 +46,7 @@ public class ObjectEditorInput extends DatabaseEditorInput<DBNDatabaseObject>
@Override
public String getToolTipText()
{
return getTreeNode().getMeta().getDescription();
return getNavigatorNode().getMeta().getDescription();
}
}
\ No newline at end of file
......@@ -113,7 +113,7 @@ public abstract class TargetPrefPage extends PreferencePage implements IWorkbenc
if (containerNode == null) {
IDatabaseEditorInput dbInput = (IDatabaseEditorInput) element.getAdapter(IDatabaseEditorInput.class);
if (dbInput != null) {
DBNNode dbNode = dbInput.getTreeNode();
DBNNode dbNode = dbInput.getNavigatorNode();
if (dbNode instanceof DBNDataSource) {
containerNode = (DBNDataSource)dbNode;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册