提交 717004d3 编写于 作者: S serge-rider

dbeaver#9732 ERD plugin split

上级 7c7d2d90
......@@ -34,6 +34,7 @@
<plugin id="org.jkiss.dbeaver.cmp.simple" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.data.transfer" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.tasks.native" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.erd.model" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<!-- GIS -->
<plugin id="org.jkiss.dbeaver.data.gis" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
......
......@@ -50,7 +50,7 @@
<plugin id="org.jkiss.dbeaver.ui.editors.xml" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ui.navigator" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ui.search" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ext.erd" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.erd.ui" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ext.ui.colortheme" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.ext.ui.locks" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
<plugin id="org.jkiss.dbeaver.tasks.ui" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
......
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Vendor: %Bundle-Vendor
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.jkiss.dbeaver.erd.model;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Release-Date: 20200831
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.core.expressions,
org.jkiss.dbeaver.model
Bundle-ClassPath: .
Export-Package: org.jkiss.dbeaver.erd.model
Automatic-Module-Name: org.jkiss.dbeaver.erd.model
Bundle-Vendor = JKISS
Bundle-Name = DBeaver ERD Model
source.. = src/
output.. = target/classes/
bin.includes = .,\
META-INF/,\
OSGI-INF/,\
plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.2"?>
<!--
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<plugin>
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions="erd"
id="org.jkiss.dbeaver.erd"
name="%content-type.org.jkiss.dbeaver.erd.name"
priority="normal"/>
</extension>
</plugin>
......@@ -8,7 +8,7 @@
<version>1.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>org.jkiss.dbeaver.ext.erd</artifactId>
<version>2.0.142-SNAPSHOT</version>
<artifactId>org.jkiss.dbeaver.erd.model</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 13, 2004
*/
package org.jkiss.dbeaver.erd.model;
public class ERDModel {
}
......@@ -2,8 +2,8 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Vendor: %Bundle-Vendor
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.jkiss.dbeaver.ext.erd;singleton:=true
Bundle-Version: 2.0.142.qualifier
Bundle-SymbolicName: org.jkiss.dbeaver.erd.ui;singleton:=true
Bundle-Version: 3.0.0.qualifier
Bundle-Release-Date: 20200831
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Activator: org.jkiss.dbeaver.ext.erd.ERDActivator
......@@ -15,8 +15,11 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.ide,
org.eclipse.ui.views,
org.eclipse.gef;visibility:=reexport,
org.jkiss.dbeaver.core,
org.jkiss.dbeaver.ui
org.jkiss.dbeaver.model,
org.jkiss.dbeaver.erd.model,
org.jkiss.dbeaver.ui,
org.jkiss.dbeaver.ui.editors.base,
org.jkiss.dbeaver.ui.navigator
Bundle-ClassPath: .
Export-Package: org.jkiss.dbeaver.ext.erd,
org.jkiss.dbeaver.ext.erd.command,
......@@ -26,4 +29,4 @@ Export-Package: org.jkiss.dbeaver.ext.erd,
org.jkiss.dbeaver.ext.erd.model,
org.jkiss.dbeaver.ext.erd.part,
org.jkiss.dbeaver.ext.erd.policy
Automatic-Module-Name: org.jkiss.dbeaver.ext.erd
Automatic-Module-Name: org.jkiss.dbeaver.erd.ui
Bundle-Vendor = JKISS
Bundle-Name = DBeaver ER Diagram
Bundle-Name = DBeaver ERD UI
extension-point.org.jkiss.dbeaver.ext.erd.export.format.name = Workbench handlers
......
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
Bundle-Name = DBeaver ER Diagramm
colorDefinition.org.jkiss.dbeaver.erd.diagram.attributes.background.description = Hintergrundfarbe des Attributnamens
colorDefinition.org.jkiss.dbeaver.erd.diagram.attributes.background.label = Hintergrundfarbe des Attributs
colorDefinition.org.jkiss.dbeaver.erd.diagram.attributes.foreground.description = Vordergrundfarbe des Attributnamens
......
# Copyright (C) 2012 Roberto Rossi (impiastro@gmail.com)
Bundle-Name = DBeaver Diagramma ER
editor.erd.name = Diagramma ER
editor.erd.description = Diagramma Entit\u00E0 Relazioni
......
# Copyright (C) 2019 Seongbae Chang (dorbae.io@gmail.com)
#Bundle-Vendor = JKISS
#Bundle-Name = DBeaver ER Diagram
#extension-point.org.jkiss.dbeaver.ext.erd.export.format.name = Workbench handlers
editor.erd.name=\uC5D4\uD2F0\uD2F0 \uAD00\uACC4\uB3C4
editor.erd.description=\uC5D4\uD2F0\uD2F0 \uAD00\uACC4\uB3C4
editor.org.jkiss.dbeaver.ext.erd.editor.ERDEditorStandalone.name = ERD \uD3B8\uC9D1\uAE30
......
Bundle-Name = DBeaver ER Diagram
Bundle-Vendor = JKISS
colorDefinition.org.jkiss.dbeaver.erd.diagram.attributes.background.description = Fundo do nome do atributo
colorDefinition.org.jkiss.dbeaver.erd.diagram.attributes.background.label = Atributos de fundo
colorDefinition.org.jkiss.dbeaver.erd.diagram.attributes.foreground.description = Nome do atributo em primeiro plano
......
# Copyright (C) 2017 Liu, Yuanyuan (liuyuanyuan@highgo.com)
Bundle-Vendor = JKISS
Bundle-Name = DBeaver ER Diagram
extension-point.org.jkiss.dbeaver.ext.erd.export.format.name = Workbench handlers
editor.erd.name = ER \u56FE
editor.erd.description = \u5B9E\u4F53\u5173\u7CFB\u56FE
editor.org.jkiss.dbeaver.ext.erd.editor.ERDEditorStandalone.name = ERD \u7F16\u8F91\u5668
......
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jkiss.dbeaver</groupId>
<artifactId>plugins</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>org.jkiss.dbeaver.erd.ui</artifactId>
<version>3.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jkiss.dbeaver.model.impl.preferences.BundlePreferenceStore;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.osgi.framework.BundleContext;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* The activator class controls the plug-in life cycle
*/
public class ERDActivator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.jkiss.dbeaver.ext.erd";
// The shared instance
private static ERDActivator plugin;
private static ResourceBundle resourceBundle;
private DBPPreferenceStore preferences;
/**
* The constructor
*/
public ERDActivator() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
preferences = new BundlePreferenceStore(getBundle());
try {
resourceBundle = ResourceBundle.getBundle(ERDMessages.BUNDLE_NAME);
} catch (MissingResourceException x) {
resourceBundle = null;
}
// Switch off D3D because of Sun XOR painting bug
// See http://www.jgraph.com/forum/viewtopic.php?t=4066
System.setProperty("sun.java2d.d3d", Boolean.FALSE.toString()); //$NON-NLS-1$
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static ERDActivator getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
/**
* Returns the plugin's resource bundle,
* @return core resource bundle
*/
public static ResourceBundle getResourceBundle()
{
return resourceBundle;
}
public DBPPreferenceStore getPreferences() {
return preferences;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.jkiss.dbeaver.model.impl.preferences.BundlePreferenceStore;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.osgi.framework.BundleContext;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* The activator class controls the plug-in life cycle
*/
public class ERDActivator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.jkiss.dbeaver.ext.erd";
// The shared instance
private static ERDActivator plugin;
private static ResourceBundle resourceBundle;
private DBPPreferenceStore preferences;
/**
* The constructor
*/
public ERDActivator() {
}
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
preferences = new BundlePreferenceStore(getBundle());
try {
resourceBundle = ResourceBundle.getBundle(ERDMessages.BUNDLE_NAME);
} catch (MissingResourceException x) {
resourceBundle = null;
}
// Switch off D3D because of Sun XOR painting bug
// See http://www.jgraph.com/forum/viewtopic.php?t=4066
System.setProperty("sun.java2d.d3d", Boolean.FALSE.toString()); //$NON-NLS-1$
}
@Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static ERDActivator getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
/**
* Returns the plugin's resource bundle,
* @return core resource bundle
*/
public static ResourceBundle getResourceBundle()
{
return resourceBundle;
}
public DBPPreferenceStore getPreferences() {
return preferences;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd;
import org.eclipse.draw2d.PrintFigureOperation;
import org.jkiss.dbeaver.model.struct.DBSEntityConstraintType;
/**
* ERD constants
*/
public class ERDConstants {
public static final String ERD_CONTROL_ID = "org.jkiss.dbeaver.erd.ERDEditor";
public static final String PREF_PRINT_PAGE_MODE = "erd.print.page-mode";
public static final String PREF_PRINT_MARGIN_TOP = "erd.print.margin-top";
public static final String PREF_PRINT_MARGIN_BOTTOM = "erd.print.margin-bottom";
public static final String PREF_PRINT_MARGIN_LEFT = "erd.print.margin-left";
public static final String PREF_PRINT_MARGIN_RIGHT = "erd.print.margin-right";
public static final int PRINT_MODE_DEFAULT = PrintFigureOperation.TILE;
public static final int PRINT_MARGIN_DEFAULT = 0;
public static final String PROP_DIAGRAM_FONT = "org.jkiss.dbeaver.erd.diagram.font";
public static final String PREF_DIAGRAM_SHOW_VIEWS = "erd.diagram.show.views";
public static final String PREF_DIAGRAM_SHOW_PARTITIONS = "erd.diagram.show.partitions";
public static final String PREF_DIAGRAM_CHANGE_BORDER_COLORS = "erd.diagram.change.borders.colors";
public static final String PREF_DIAGRAM_CHANGE_HEADER_COLORS = "erd.diagram.change.header.colors";
public static final String PREF_GRID_ENABLED = "erd.grid.enabled";
public static final String PREF_GRID_SNAP_ENABLED = "erd.grid.snap";
public static final String PREF_GRID_WIDTH = "erd.grid.width";
public static final String PREF_GRID_HEIGHT = "erd.grid.height";
public static final String PREF_ATTR_VISIBILITY = "erd.attr.visibility";
public static final String PREF_ATTR_STYLES = "erd.attr.styles";
public static final String COLOR_ERD_DIAGRAM_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.background";
public static final String COLOR_ERD_ENTITY_PRIMARY_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.entity.primary.background";
public static final String COLOR_ERD_ENTITY_ASSOCIATION_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.entity.association.background";
public static final String COLOR_ERD_ENTITY_REGULAR_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.entity.regular.background";
public static final String COLOR_ERD_ENTITY_NAME_FOREGROUND = "org.jkiss.dbeaver.erd.diagram.entity.name.foreground";
public static final String COLOR_ERD_LINES_FOREGROUND = "org.jkiss.dbeaver.erd.diagram.lines.foreground";
public static final String COLOR_ERD_ATTR_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.attributes.background";
public static final String COLOR_ERD_ATTR_FOREGROUND = "org.jkiss.dbeaver.erd.diagram.attributes.foreground";
public static final String COLOR_ERD_NOTE_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.notes.background";
public static final String COLOR_ERD_NOTE_FOREGROUND = "org.jkiss.dbeaver.erd.diagram.notes.foreground";
public static final String COLOR_ERD_BORDERS_COLOR_1 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.1"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_2 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.2"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_3 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.3"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_4 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.4"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_5 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.5"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_6 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.6"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_7 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.7"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_1 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.1"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_2 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.2"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_3 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.3"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_4 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.4"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_5 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.5"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_6 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.6"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_7 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.7"; //$NON-NLS-1$
public static final String ICON_LOCATION_PREFIX = "platform:/plugin/" + ERDActivator.PLUGIN_ID + "/icons/";
public static final int DEFAULT_NOTE_BORDER_WIDTH = 1;
public static final int DEFAULT_ENTITY_BORDER_WIDTH = 2;
public static DBSEntityConstraintType CONSTRAINT_LOGICAL_FK = new DBSEntityConstraintType("erdkey", "Logical Key", null, true, false, false, true);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd;
import org.eclipse.draw2d.PrintFigureOperation;
import org.jkiss.dbeaver.model.struct.DBSEntityConstraintType;
/**
* ERD constants
*/
public class ERDConstants {
public static final String ERD_CONTROL_ID = "org.jkiss.dbeaver.erd.ERDEditor";
public static final String PREF_PRINT_PAGE_MODE = "erd.print.page-mode";
public static final String PREF_PRINT_MARGIN_TOP = "erd.print.margin-top";
public static final String PREF_PRINT_MARGIN_BOTTOM = "erd.print.margin-bottom";
public static final String PREF_PRINT_MARGIN_LEFT = "erd.print.margin-left";
public static final String PREF_PRINT_MARGIN_RIGHT = "erd.print.margin-right";
public static final int PRINT_MODE_DEFAULT = PrintFigureOperation.TILE;
public static final int PRINT_MARGIN_DEFAULT = 0;
public static final String PROP_DIAGRAM_FONT = "org.jkiss.dbeaver.erd.diagram.font";
public static final String PREF_DIAGRAM_SHOW_VIEWS = "erd.diagram.show.views";
public static final String PREF_DIAGRAM_SHOW_PARTITIONS = "erd.diagram.show.partitions";
public static final String PREF_DIAGRAM_CHANGE_BORDER_COLORS = "erd.diagram.change.borders.colors";
public static final String PREF_DIAGRAM_CHANGE_HEADER_COLORS = "erd.diagram.change.header.colors";
public static final String PREF_GRID_ENABLED = "erd.grid.enabled";
public static final String PREF_GRID_SNAP_ENABLED = "erd.grid.snap";
public static final String PREF_GRID_WIDTH = "erd.grid.width";
public static final String PREF_GRID_HEIGHT = "erd.grid.height";
public static final String PREF_ATTR_VISIBILITY = "erd.attr.visibility";
public static final String PREF_ATTR_STYLES = "erd.attr.styles";
public static final String COLOR_ERD_DIAGRAM_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.background";
public static final String COLOR_ERD_ENTITY_PRIMARY_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.entity.primary.background";
public static final String COLOR_ERD_ENTITY_ASSOCIATION_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.entity.association.background";
public static final String COLOR_ERD_ENTITY_REGULAR_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.entity.regular.background";
public static final String COLOR_ERD_ENTITY_NAME_FOREGROUND = "org.jkiss.dbeaver.erd.diagram.entity.name.foreground";
public static final String COLOR_ERD_LINES_FOREGROUND = "org.jkiss.dbeaver.erd.diagram.lines.foreground";
public static final String COLOR_ERD_ATTR_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.attributes.background";
public static final String COLOR_ERD_ATTR_FOREGROUND = "org.jkiss.dbeaver.erd.diagram.attributes.foreground";
public static final String COLOR_ERD_NOTE_BACKGROUND = "org.jkiss.dbeaver.erd.diagram.notes.background";
public static final String COLOR_ERD_NOTE_FOREGROUND = "org.jkiss.dbeaver.erd.diagram.notes.foreground";
public static final String COLOR_ERD_BORDERS_COLOR_1 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.1"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_2 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.2"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_3 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.3"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_4 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.4"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_5 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.5"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_6 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.6"; //$NON-NLS-1$
public static final String COLOR_ERD_BORDERS_COLOR_7 = "org.jkiss.dbeaver.ui.presentation.erd.borders.color.7"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_1 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.1"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_2 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.2"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_3 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.3"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_4 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.4"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_5 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.5"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_6 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.6"; //$NON-NLS-1$
public static final String COLOR_ERD_HEADER_COLOR_7 = "org.jkiss.dbeaver.ui.presentation.erd.headers.color.7"; //$NON-NLS-1$
public static final String ICON_LOCATION_PREFIX = "platform:/plugin/" + ERDActivator.PLUGIN_ID + "/icons/";
public static final int DEFAULT_NOTE_BORDER_WIDTH = 1;
public static final int DEFAULT_ENTITY_BORDER_WIDTH = 2;
public static DBSEntityConstraintType CONSTRAINT_LOGICAL_FK = new DBSEntityConstraintType("erdkey", "Logical Key", null, true, false, false, true);
}
package org.jkiss.dbeaver.ext.erd;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.jkiss.dbeaver.model.impl.preferences.BundlePreferenceStore;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.utils.PrefUtils;
public class ERDPreferencesInitializer extends AbstractPreferenceInitializer {
public ERDPreferencesInitializer() {
}
@Override
public void initializeDefaultPreferences() {
// Init default preferences
DBPPreferenceStore store = new BundlePreferenceStore(ERDActivator.getDefault().getBundle());
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_DIAGRAM_SHOW_VIEWS, true);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_DIAGRAM_SHOW_PARTITIONS, false);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_DIAGRAM_CHANGE_BORDER_COLORS, true);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_DIAGRAM_CHANGE_HEADER_COLORS, true);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_PAGE_MODE, ERDConstants.PRINT_MODE_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_MARGIN_TOP, ERDConstants.PRINT_MARGIN_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_MARGIN_BOTTOM, ERDConstants.PRINT_MARGIN_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_MARGIN_LEFT, ERDConstants.PRINT_MARGIN_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_MARGIN_RIGHT, ERDConstants.PRINT_MARGIN_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_GRID_ENABLED, false);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_GRID_SNAP_ENABLED, true);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_GRID_WIDTH, 20);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_GRID_HEIGHT, 20);
}
package org.jkiss.dbeaver.ext.erd;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.jkiss.dbeaver.model.impl.preferences.BundlePreferenceStore;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.utils.PrefUtils;
public class ERDPreferencesInitializer extends AbstractPreferenceInitializer {
public ERDPreferencesInitializer() {
}
@Override
public void initializeDefaultPreferences() {
// Init default preferences
DBPPreferenceStore store = new BundlePreferenceStore(ERDActivator.getDefault().getBundle());
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_DIAGRAM_SHOW_VIEWS, true);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_DIAGRAM_SHOW_PARTITIONS, false);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_DIAGRAM_CHANGE_BORDER_COLORS, true);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_DIAGRAM_CHANGE_HEADER_COLORS, true);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_PAGE_MODE, ERDConstants.PRINT_MODE_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_MARGIN_TOP, ERDConstants.PRINT_MARGIN_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_MARGIN_BOTTOM, ERDConstants.PRINT_MARGIN_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_MARGIN_LEFT, ERDConstants.PRINT_MARGIN_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_PRINT_MARGIN_RIGHT, ERDConstants.PRINT_MARGIN_DEFAULT);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_GRID_ENABLED, false);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_GRID_SNAP_ENABLED, true);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_GRID_WIDTH, 20);
PrefUtils.setDefaultPreferenceValue(store, ERDConstants.PREF_GRID_HEIGHT, 20);
}
}
\ No newline at end of file
#navigator
action_diagram_layout_name=Arrange Diagram
wizard_diagram_create_title=Diagram Create Wizard
#part
column_=Column
entity_diagram_=Entity Diagram
part_note_title=Note
pref_page_erd_checkbox_grid_enabled=Grid Enabled
pref_page_erd_checkbox_snap_to_grid=Snap To Grid
pref_page_erd_combo_page_mode=Page Mode
pref_page_erd_group_grid=Grid
pref_page_erd_group_print=Print
pref_page_erd_item_fit_height=Fit Height
pref_page_erd_item_fit_page=Fit Page
pref_page_erd_item_fit_width=Fit Width
pref_page_erd_item_tile=Tile
pref_page_erd_spinner_grid_height=Grid Height
pref_page_erd_spinner_grid_width=Grid Width
pref_page_erd_spinner_margin_bottom=Margin Bottom
pref_page_erd_spinner_margin_left=Margin Left
pref_page_erd_spinner_margin_right=Margin Right
pref_page_erd_spinner_margin_top=Margin Top
wizard_page_diagram_create_description=Manage diagram content.
wizard_page_diagram_create_group_settings=Settings
wizard_page_diagram_create_label_init_content=Initial content (optional)
wizard_page_diagram_create_name=Create new diagram
wizard_page_diagram_create_title=Create new diagram
## ERD editor action item control ##
erd_attribute_visibility_selection_item_all=All
erd_attribute_visibility_selection_item_any_keys=Any keys
erd_attribute_visibility_selection_item_none=None
erd_attribute_visibility_selection_item_primary_key=Primary key
erd_editor_control_action_toggle_grid = Toggle Grid
erd_editor_control_action_refresh_diagram = Refresh Diagram
erd_editor_control_action_save_external_format = Save diagram in external format
erd_editor_control_action_print_diagram = Print Diagram
erd_editor_control_action_configuration = Configuration
erd_preference_page_title_attribute_style=Attribute styles
erd_preference_page_title_attributes_visibility=Attributes visibility
erd_preference_page_title_diagram_contents=Diagram contents
erd_preference_page_title_shows_views=Show views
erd_preference_page_title_shows_partitions=Show partitions
erd_preference_page_title_color_pref = Color settings
erd_preference_page_title_change_border_colors = Colorize other connections
erd_preference_page_title_change_header_colors = Colorize other schemas
## ERD editor action item control ##
erd_tool_color_action_text_set_color=Set color
erd_tool_color_action_tip_text_set_figure_color=Set figure color
erd_tool_create_connection = Connection
erd_tool_create_connection_tip = Create logical connection (foreign key)
erd_tool_create_note = Note
erd_tool_create_note_tip = Create diagram note
erd_tool_create_default = Note
erd_tool_set_text_text_bring_to_front=Bring to front
erd_tool_set_text_text_send_to_back=Send to back
erd_tool_set_text_tip_text_bring_to_front=Bring to front
erd_tool_set_text_tip_text_send_to_back=Send to back
erd_view_style_selection_item_comments=Comments
erd_view_style_selection_item_data_types=Data Types
erd_view_style_selection_item_fully_qualified_names=Fully qualified names
erd_view_style_selection_item_icons=Icons
erd_view_style_selection_item_nullability=Nullability
menu_view_style = View Styles
menu_attribute_visibility = Show Attributes
menu_attribute_visibility_default = All Entities
menu_attribute_visibility_entity = Selected Entity
#navigator
action_diagram_layout_name=Arrange Diagram
wizard_diagram_create_title=Diagram Create Wizard
#part
column_=Column
entity_diagram_=Entity Diagram
part_note_title=Note
pref_page_erd_checkbox_grid_enabled=Grid Enabled
pref_page_erd_checkbox_snap_to_grid=Snap To Grid
pref_page_erd_combo_page_mode=Page Mode
pref_page_erd_group_grid=Grid
pref_page_erd_group_print=Print
pref_page_erd_item_fit_height=Fit Height
pref_page_erd_item_fit_page=Fit Page
pref_page_erd_item_fit_width=Fit Width
pref_page_erd_item_tile=Tile
pref_page_erd_spinner_grid_height=Grid Height
pref_page_erd_spinner_grid_width=Grid Width
pref_page_erd_spinner_margin_bottom=Margin Bottom
pref_page_erd_spinner_margin_left=Margin Left
pref_page_erd_spinner_margin_right=Margin Right
pref_page_erd_spinner_margin_top=Margin Top
wizard_page_diagram_create_description=Manage diagram content.
wizard_page_diagram_create_group_settings=Settings
wizard_page_diagram_create_label_init_content=Initial content (optional)
wizard_page_diagram_create_name=Create new diagram
wizard_page_diagram_create_title=Create new diagram
## ERD editor action item control ##
erd_attribute_visibility_selection_item_all=All
erd_attribute_visibility_selection_item_any_keys=Any keys
erd_attribute_visibility_selection_item_none=None
erd_attribute_visibility_selection_item_primary_key=Primary key
erd_editor_control_action_toggle_grid = Toggle Grid
erd_editor_control_action_refresh_diagram = Refresh Diagram
erd_editor_control_action_save_external_format = Save diagram in external format
erd_editor_control_action_print_diagram = Print Diagram
erd_editor_control_action_configuration = Configuration
erd_preference_page_title_attribute_style=Attribute styles
erd_preference_page_title_attributes_visibility=Attributes visibility
erd_preference_page_title_diagram_contents=Diagram contents
erd_preference_page_title_shows_views=Show views
erd_preference_page_title_shows_partitions=Show partitions
erd_preference_page_title_color_pref = Color settings
erd_preference_page_title_change_border_colors = Colorize other connections
erd_preference_page_title_change_header_colors = Colorize other schemas
## ERD editor action item control ##
erd_tool_color_action_text_set_color=Set color
erd_tool_color_action_tip_text_set_figure_color=Set figure color
erd_tool_create_connection = Connection
erd_tool_create_connection_tip = Create logical connection (foreign key)
erd_tool_create_note = Note
erd_tool_create_note_tip = Create diagram note
erd_tool_create_default = Note
erd_tool_set_text_text_bring_to_front=Bring to front
erd_tool_set_text_text_send_to_back=Send to back
erd_tool_set_text_tip_text_bring_to_front=Bring to front
erd_tool_set_text_tip_text_send_to_back=Send to back
erd_view_style_selection_item_comments=Comments
erd_view_style_selection_item_data_types=Data Types
erd_view_style_selection_item_fully_qualified_names=Fully qualified names
erd_view_style_selection_item_icons=Icons
erd_view_style_selection_item_nullability=Nullability
menu_view_style = View Styles
menu_attribute_visibility = Show Attributes
menu_attribute_visibility_default = All Entities
menu_attribute_visibility_entity = Selected Entity
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
* Copyright (C) 2011-2012 Eugene Fradkin (eugene.fradkin@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 23, 2004
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.jface.action.Action;
import org.jkiss.dbeaver.ext.erd.ERDActivator;
import org.jkiss.dbeaver.ext.erd.ERDMessages;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
/**
* Action to toggle the layout between manual and automatic
*
* @author Serge Rider
*/
public class DiagramLayoutAction extends Action
{
private ERDEditorPart editor;
public DiagramLayoutAction(ERDEditorPart editor)
{
super(ERDMessages.action_diagram_layout_name, ERDActivator.getImageDescriptor("icons/arrangeall.png")); //$NON-NLS-2$
this.editor = editor;
}
@Override
public void run()
{
//editor.get
editor.getDiagramPart().rearrangeDiagram();
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
* Copyright (C) 2011-2012 Eugene Fradkin (eugene.fradkin@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 23, 2004
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.jface.action.Action;
import org.jkiss.dbeaver.ext.erd.ERDActivator;
import org.jkiss.dbeaver.ext.erd.ERDMessages;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
/**
* Action to toggle the layout between manual and automatic
*
* @author Serge Rider
*/
public class DiagramLayoutAction extends Action
{
private ERDEditorPart editor;
public DiagramLayoutAction(ERDEditorPart editor)
{
super(ERDMessages.action_diagram_layout_name, ERDActivator.getImageDescriptor("icons/arrangeall.png")); //$NON-NLS-2$
this.editor = editor;
}
@Override
public void run()
{
//editor.get
editor.getDiagramPart().rearrangeDiagram();
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 23, 2004
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.jface.action.Action;
import org.jkiss.dbeaver.ext.erd.ERDMessages;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
/**
* Action to toggle the layout between manual and automatic
*
* @author Serge Rider
*/
public class DiagramRefreshAction extends Action
{
private ERDEditorPart editor;
public DiagramRefreshAction(ERDEditorPart editor)
{
super(ERDMessages.erd_editor_control_action_refresh_diagram, DBeaverIcons.getImageDescriptor(UIIcon.REFRESH));
this.editor = editor;
}
@Override
public void run()
{
//editor.get
editor.refreshDiagram(true, true);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 23, 2004
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.jface.action.Action;
import org.jkiss.dbeaver.ext.erd.ERDMessages;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
import org.jkiss.dbeaver.ui.DBeaverIcons;
import org.jkiss.dbeaver.ui.UIIcon;
/**
* Action to toggle the layout between manual and automatic
*
* @author Serge Rider
*/
public class DiagramRefreshAction extends Action
{
private ERDEditorPart editor;
public DiagramRefreshAction(ERDEditorPart editor)
{
super(ERDMessages.erd_editor_control_action_refresh_diagram, DBeaverIcons.getImageDescriptor(UIIcon.REFRESH));
this.editor = editor;
}
@Override
public void run()
{
//editor.get
editor.refreshDiagram(true, true);
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 23, 2004
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.jface.action.Action;
import org.jkiss.dbeaver.ext.erd.ERDActivator;
import org.jkiss.dbeaver.ext.erd.ERDConstants;
import org.jkiss.dbeaver.ext.erd.ERDMessages;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.utils.PrefUtils;
/**
* Action to toggle the layout between manual and automatic
*
* @author Serge Rider
*/
public class DiagramToggleGridAction extends Action
{
public DiagramToggleGridAction()
{
super(ERDMessages.erd_editor_control_action_toggle_grid, ERDActivator.getImageDescriptor("icons/layer_grid.png"));
}
@Override
public void run()
{
final DBPPreferenceStore store = ERDActivator.getDefault().getPreferences();
final boolean gridEnabled = store.getBoolean(ERDConstants.PREF_GRID_ENABLED);
store.setValue(ERDConstants.PREF_GRID_ENABLED, !gridEnabled);
PrefUtils.savePreferenceStore(store);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 23, 2004
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.jface.action.Action;
import org.jkiss.dbeaver.ext.erd.ERDActivator;
import org.jkiss.dbeaver.ext.erd.ERDConstants;
import org.jkiss.dbeaver.ext.erd.ERDMessages;
import org.jkiss.dbeaver.model.preferences.DBPPreferenceStore;
import org.jkiss.dbeaver.utils.PrefUtils;
/**
* Action to toggle the layout between manual and automatic
*
* @author Serge Rider
*/
public class DiagramToggleGridAction extends Action
{
public DiagramToggleGridAction()
{
super(ERDMessages.erd_editor_control_action_toggle_grid, ERDActivator.getImageDescriptor("icons/layer_grid.png"));
}
@Override
public void run()
{
final DBPPreferenceStore store = ERDActivator.getDefault().getPreferences();
final boolean gridEnabled = store.getBoolean(ERDConstants.PREF_GRID_ENABLED);
store.setValue(ERDConstants.PREF_GRID_ENABLED, !gridEnabled);
PrefUtils.savePreferenceStore(store);
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.gef.ui.actions.DeleteAction;
import org.eclipse.ui.IWorkbenchPart;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
/**
* DatabaseEditorPropertyTester
*/
public class ERDEditorPropertyTester extends PropertyTester
{
public static final String NAMESPACE = "org.jkiss.dbeaver.ext.erd.editor";
public static final String PROP_CAN_UNDO = "canUndo";
public static final String PROP_CAN_REDO = "canRedo";
public static final String PROP_CAN_DELETE = "canDelete";
public static final String PROP_EDITABLE = "editable";
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof ERDEditorPart)) {
return false;
}
ERDEditorPart erdEditor = (ERDEditorPart) receiver;
switch (property) {
case PROP_CAN_UNDO:
return erdEditor.getCommandStack().canUndo();
case PROP_CAN_REDO:
return erdEditor.getCommandStack().canRedo();
case PROP_EDITABLE:
return !erdEditor.isReadOnly();
case PROP_CAN_DELETE:
DeleteAction deleteAction = new DeleteAction((IWorkbenchPart) erdEditor);
deleteAction.update();
return deleteAction.isEnabled();
}
return false;
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.gef.ui.actions.DeleteAction;
import org.eclipse.ui.IWorkbenchPart;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
/**
* DatabaseEditorPropertyTester
*/
public class ERDEditorPropertyTester extends PropertyTester
{
public static final String NAMESPACE = "org.jkiss.dbeaver.ext.erd.editor";
public static final String PROP_CAN_UNDO = "canUndo";
public static final String PROP_CAN_REDO = "canRedo";
public static final String PROP_CAN_DELETE = "canDelete";
public static final String PROP_EDITABLE = "editable";
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (!(receiver instanceof ERDEditorPart)) {
return false;
}
ERDEditorPart erdEditor = (ERDEditorPart) receiver;
switch (property) {
case PROP_CAN_UNDO:
return erdEditor.getCommandStack().canUndo();
case PROP_CAN_REDO:
return erdEditor.getCommandStack().canRedo();
case PROP_EDITABLE:
return !erdEditor.isReadOnly();
case PROP_CAN_DELETE:
DeleteAction deleteAction = new DeleteAction((IWorkbenchPart) erdEditor);
deleteAction.update();
return deleteAction.isEnabled();
}
return false;
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.gef.ui.actions.DeleteAction;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerDelete extends AbstractHandler {
public ERDHandlerDelete() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && !editor.isReadOnly()) {
DeleteAction deleteAction = new DeleteAction((IWorkbenchPart) editor);
deleteAction.update();
if (deleteAction.isEnabled()) {
deleteAction.run();
}
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.gef.ui.actions.DeleteAction;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerDelete extends AbstractHandler {
public ERDHandlerDelete() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && !editor.isReadOnly()) {
DeleteAction deleteAction = new DeleteAction((IWorkbenchPart) editor);
deleteAction.update();
if (deleteAction.isEnabled()) {
deleteAction.run();
}
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.commands.Command;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
import org.jkiss.dbeaver.ext.erd.model.DiagramObjectCollector;
import org.jkiss.dbeaver.ext.erd.model.ERDEntity;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.struct.DBSObjectContainer;
import org.jkiss.dbeaver.model.struct.rdb.DBSTable;
import org.jkiss.dbeaver.ui.dnd.DatabaseObjectTransfer;
import org.jkiss.utils.CommonUtils;
import java.util.Collection;
import java.util.List;
public class ERDHandlerPaste extends AbstractHandler {
public ERDHandlerPaste() {
}
@Override
public boolean isEnabled()
{
final Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getFromClipboard();
if (objects == null || CommonUtils.isEmpty(objects)) {
return false;
}
for (DBPNamedObject object : objects) {
if (object instanceof DBSTable || object instanceof DBSObjectContainer) {
return true;
}
}
return false;
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && !editor.isReadOnly()) {
final Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
if (!CommonUtils.isEmpty(objects)) {
final List<ERDEntity> erdEntities = DiagramObjectCollector.generateEntityList(editor.getDiagram(), objects, true);
if (!CommonUtils.isEmpty(erdEntities)) {
Command command = editor.getDiagramPart().createEntityAddCommand(erdEntities, new Point(10, 10));
editor.getCommandStack().execute(command);
}
}
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.commands.Command;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
import org.jkiss.dbeaver.ext.erd.model.DiagramObjectCollector;
import org.jkiss.dbeaver.ext.erd.model.ERDEntity;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.struct.DBSObjectContainer;
import org.jkiss.dbeaver.model.struct.rdb.DBSTable;
import org.jkiss.dbeaver.ui.dnd.DatabaseObjectTransfer;
import org.jkiss.utils.CommonUtils;
import java.util.Collection;
import java.util.List;
public class ERDHandlerPaste extends AbstractHandler {
public ERDHandlerPaste() {
}
@Override
public boolean isEnabled()
{
final Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getFromClipboard();
if (objects == null || CommonUtils.isEmpty(objects)) {
return false;
}
for (DBPNamedObject object : objects) {
if (object instanceof DBSTable || object instanceof DBSObjectContainer) {
return true;
}
}
return false;
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && !editor.isReadOnly()) {
final Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
if (!CommonUtils.isEmpty(objects)) {
final List<ERDEntity> erdEntities = DiagramObjectCollector.generateEntityList(editor.getDiagram(), objects, true);
if (!CommonUtils.isEmpty(erdEntities)) {
Command command = editor.getDiagramPart().createEntityAddCommand(erdEntities, new Point(10, 10));
editor.getCommandStack().execute(command);
}
}
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerPrint extends AbstractHandler {
public ERDHandlerPrint() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null) {
editor.printDiagram();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerPrint extends AbstractHandler {
public ERDHandlerPrint() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null) {
editor.printDiagram();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerRedo extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && editor.getCommandStack().canRedo()) {
editor.getCommandStack().redo();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerRedo extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && editor.getCommandStack().canRedo()) {
editor.getCommandStack().redo();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerSaveImage extends AbstractHandler {
public ERDHandlerSaveImage() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null) {
editor.saveDiagramAs();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerSaveImage extends AbstractHandler {
public ERDHandlerSaveImage() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null) {
editor.saveDiagramAs();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.gef.ui.actions.SelectAllAction;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerSelectAll extends AbstractHandler {
public ERDHandlerSelectAll() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null) {
SelectAllAction selectAllAction = new SelectAllAction(editor);
selectAllAction.run();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.gef.ui.actions.SelectAllAction;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerSelectAll extends AbstractHandler {
public ERDHandlerSelectAll() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null) {
SelectAllAction selectAllAction = new SelectAllAction(editor);
selectAllAction.run();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerUndo extends AbstractHandler {
public ERDHandlerUndo() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && editor.getCommandStack().canUndo()) {
editor.getCommandStack().undo();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorAdapter;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
public class ERDHandlerUndo extends AbstractHandler {
public ERDHandlerUndo() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && editor.getCommandStack().canUndo()) {
editor.getCommandStack().undo();
}
}
return null;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 23, 2004
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IEditorPart;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
import org.jkiss.dbeaver.ext.erd.model.EntityDiagram;
/**
* Action to toggle the layout between manual and automatic
*
* @author Serge Rider
*/
public class FlyoutChangeLayoutAction extends Action
{
private IEditorPart editor;
private boolean checked;
public FlyoutChangeLayoutAction(IEditorPart editor)
{
super("Automatic Layout", Action.AS_CHECK_BOX);
this.editor = editor;
}
@Override
public void run()
{
if (editor instanceof ERDEditorPart)
{
ERDEditorPart erdEditor = (ERDEditorPart) editor;
EntityDiagram entityDiagram = erdEditor.getDiagram();
boolean isManual = entityDiagram.isLayoutManualDesired();
entityDiagram.setLayoutManualDesired(!isManual);
erdEditor.getDiagramPart().changeLayout();
checked = !isManual;
setChecked(checked);
}
}
@Override
public boolean isChecked()
{
if (editor != null)
return isChecked(editor);
else
return super.isChecked();
}
/**
* @see org.eclipse.jface.action.IAction#isChecked()
*/
public boolean isChecked(IEditorPart editor)
{
if (editor instanceof ERDEditorPart)
{
ERDEditorPart schemaEditor = (ERDEditorPart) editor;
EntityDiagram entityDiagram = schemaEditor.getDiagram();
boolean checkTrue = entityDiagram.isLayoutManualDesired();
return (!checkTrue);
}
else
{
return false;
}
}
public void setActiveEditor(IEditorPart editor)
{
this.editor = editor;
boolean localChecked = isChecked(editor);
//there appears to be a bug in the framework which necessitates this
if (localChecked)
firePropertyChange(CHECKED, Boolean.FALSE, Boolean.TRUE);
else
firePropertyChange(CHECKED, Boolean.TRUE, Boolean.FALSE);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 23, 2004
*/
package org.jkiss.dbeaver.ext.erd.action;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IEditorPart;
import org.jkiss.dbeaver.ext.erd.editor.ERDEditorPart;
import org.jkiss.dbeaver.ext.erd.model.EntityDiagram;
/**
* Action to toggle the layout between manual and automatic
*
* @author Serge Rider
*/
public class FlyoutChangeLayoutAction extends Action
{
private IEditorPart editor;
private boolean checked;
public FlyoutChangeLayoutAction(IEditorPart editor)
{
super("Automatic Layout", Action.AS_CHECK_BOX);
this.editor = editor;
}
@Override
public void run()
{
if (editor instanceof ERDEditorPart)
{
ERDEditorPart erdEditor = (ERDEditorPart) editor;
EntityDiagram entityDiagram = erdEditor.getDiagram();
boolean isManual = entityDiagram.isLayoutManualDesired();
entityDiagram.setLayoutManualDesired(!isManual);
erdEditor.getDiagramPart().changeLayout();
checked = !isManual;
setChecked(checked);
}
}
@Override
public boolean isChecked()
{
if (editor != null)
return isChecked(editor);
else
return super.isChecked();
}
/**
* @see org.eclipse.jface.action.IAction#isChecked()
*/
public boolean isChecked(IEditorPart editor)
{
if (editor instanceof ERDEditorPart)
{
ERDEditorPart schemaEditor = (ERDEditorPart) editor;
EntityDiagram entityDiagram = schemaEditor.getDiagram();
boolean checkTrue = entityDiagram.isLayoutManualDesired();
return (!checkTrue);
}
else
{
return false;
}
}
public void setActiveEditor(IEditorPart editor)
{
this.editor = editor;
boolean localChecked = isChecked(editor);
//there appears to be a bug in the framework which necessitates this
if (localChecked)
firePropertyChange(CHECKED, Boolean.FALSE, Boolean.TRUE);
else
firePropertyChange(CHECKED, Boolean.TRUE, Boolean.FALSE);
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.*;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.dbeaver.model.virtual.DBVEntity;
import org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey;
import org.jkiss.dbeaver.model.virtual.DBVUtils;
import org.jkiss.dbeaver.ui.editors.object.struct.EditForeignKeyPage;
import org.jkiss.utils.CommonUtils;
import java.util.Collections;
import java.util.List;
/**
* Command to create association
*/
public class AssociationCreateCommand extends Command {
protected ERDAssociation association;
protected ERDElement sourceEntity;
protected ERDElement targetEntity;
private List<ERDEntityAttribute> sourceAttributes;
private List<ERDEntityAttribute> targetAttributes;
public AssociationCreateCommand() {
}
public ERDEntityAttribute getSourceAttribute() {
return CommonUtils.isEmpty(sourceAttributes) ? null : sourceAttributes.get(0);
}
public ERDEntityAttribute getTargetAttribute() {
return CommonUtils.isEmpty(targetAttributes) ? null : targetAttributes.get(0);
}
public void setAttributes(List<ERDEntityAttribute> sourceAttributes, List<ERDEntityAttribute> targetAttributes) {
this.sourceAttributes = sourceAttributes;
this.targetAttributes = targetAttributes;
}
public void setAttributes(ERDEntityAttribute sourceAttribute, ERDEntityAttribute targetAttribute) {
this.sourceAttributes = Collections.singletonList(sourceAttribute);
this.targetAttributes = Collections.singletonList(targetAttribute);
}
@Override
public boolean canExecute() {
boolean returnValue = true;
if (sourceEntity.equals(targetEntity)) {
returnValue = false;
} else {
if (targetEntity == null) {
return false;
} else {
// Check for existence of relationship already
List<ERDAssociation> relationships = targetEntity.getReferences();
for (ERDAssociation currentRelationship : relationships) {
if (currentRelationship.getSourceEntity().equals(sourceEntity)) {
returnValue = false;
break;
}
}
}
}
return returnValue;
}
@Override
public void execute() {
if (sourceEntity instanceof ERDEntity && targetEntity instanceof ERDEntity) {
DBSEntity srcEntityObject = ((ERDEntity)sourceEntity).getObject();
DBSEntity targetEntityObject = ((ERDEntity)targetEntity).getObject();
List<DBSEntityAttribute> srcAttrs = ERDUtils.getObjectsFromERD(sourceAttributes);
List<DBSEntityAttribute> refAttrs = ERDUtils.getObjectsFromERD(targetAttributes);
DBVEntity vEntity = DBVUtils.getVirtualEntity(srcEntityObject, true);
DBVEntityForeignKey vfk = EditForeignKeyPage.createVirtualForeignKey(
vEntity,
targetEntityObject,
new EditForeignKeyPage.FKType[] {
EditForeignKeyPage.FK_TYPE_LOGICAL
},
srcAttrs,
refAttrs);
if (vfk == null) {
return;
}
vEntity.persistConfiguration();
association = new ERDAssociation(vfk, (ERDEntity)sourceEntity, (ERDEntity)targetEntity, true);
} else {
association = createAssociation(sourceEntity, targetEntity, true);
}
}
public ERDElement getSourceEntity() {
return sourceEntity;
}
public void setSourceEntity(ERDElement sourceEntity) {
this.sourceEntity = sourceEntity;
}
public ERDElement getTargetEntity() {
return targetEntity;
}
public void setTargetEntity(ERDElement targetEntity) {
this.targetEntity = targetEntity;
}
public ERDAssociation getAssociation() {
return association;
}
public void setAssociation(ERDAssociation association) {
this.association = association;
}
@Override
public void redo() {
if (association != null) {
sourceEntity.addAssociation(association, true);
targetEntity.addReferenceAssociation(association, true);
}
}
@Override
public void undo() {
if (association != null) {
sourceEntity.removeAssociation(association, true);
targetEntity.removeReferenceAssociation(association, true);
}
}
protected ERDAssociation createAssociation(ERDElement sourceEntity, ERDElement targetEntity, boolean reflect) {
return new ERDAssociation(sourceEntity, targetEntity, true);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.*;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSEntityAttribute;
import org.jkiss.dbeaver.model.virtual.DBVEntity;
import org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey;
import org.jkiss.dbeaver.model.virtual.DBVUtils;
import org.jkiss.dbeaver.ui.editors.object.struct.EditForeignKeyPage;
import org.jkiss.utils.CommonUtils;
import java.util.Collections;
import java.util.List;
/**
* Command to create association
*/
public class AssociationCreateCommand extends Command {
protected ERDAssociation association;
protected ERDElement sourceEntity;
protected ERDElement targetEntity;
private List<ERDEntityAttribute> sourceAttributes;
private List<ERDEntityAttribute> targetAttributes;
public AssociationCreateCommand() {
}
public ERDEntityAttribute getSourceAttribute() {
return CommonUtils.isEmpty(sourceAttributes) ? null : sourceAttributes.get(0);
}
public ERDEntityAttribute getTargetAttribute() {
return CommonUtils.isEmpty(targetAttributes) ? null : targetAttributes.get(0);
}
public void setAttributes(List<ERDEntityAttribute> sourceAttributes, List<ERDEntityAttribute> targetAttributes) {
this.sourceAttributes = sourceAttributes;
this.targetAttributes = targetAttributes;
}
public void setAttributes(ERDEntityAttribute sourceAttribute, ERDEntityAttribute targetAttribute) {
this.sourceAttributes = Collections.singletonList(sourceAttribute);
this.targetAttributes = Collections.singletonList(targetAttribute);
}
@Override
public boolean canExecute() {
boolean returnValue = true;
if (sourceEntity.equals(targetEntity)) {
returnValue = false;
} else {
if (targetEntity == null) {
return false;
} else {
// Check for existence of relationship already
List<ERDAssociation> relationships = targetEntity.getReferences();
for (ERDAssociation currentRelationship : relationships) {
if (currentRelationship.getSourceEntity().equals(sourceEntity)) {
returnValue = false;
break;
}
}
}
}
return returnValue;
}
@Override
public void execute() {
if (sourceEntity instanceof ERDEntity && targetEntity instanceof ERDEntity) {
DBSEntity srcEntityObject = ((ERDEntity)sourceEntity).getObject();
DBSEntity targetEntityObject = ((ERDEntity)targetEntity).getObject();
List<DBSEntityAttribute> srcAttrs = ERDUtils.getObjectsFromERD(sourceAttributes);
List<DBSEntityAttribute> refAttrs = ERDUtils.getObjectsFromERD(targetAttributes);
DBVEntity vEntity = DBVUtils.getVirtualEntity(srcEntityObject, true);
DBVEntityForeignKey vfk = EditForeignKeyPage.createVirtualForeignKey(
vEntity,
targetEntityObject,
new EditForeignKeyPage.FKType[] {
EditForeignKeyPage.FK_TYPE_LOGICAL
},
srcAttrs,
refAttrs);
if (vfk == null) {
return;
}
vEntity.persistConfiguration();
association = new ERDAssociation(vfk, (ERDEntity)sourceEntity, (ERDEntity)targetEntity, true);
} else {
association = createAssociation(sourceEntity, targetEntity, true);
}
}
public ERDElement getSourceEntity() {
return sourceEntity;
}
public void setSourceEntity(ERDElement sourceEntity) {
this.sourceEntity = sourceEntity;
}
public ERDElement getTargetEntity() {
return targetEntity;
}
public void setTargetEntity(ERDElement targetEntity) {
this.targetEntity = targetEntity;
}
public ERDAssociation getAssociation() {
return association;
}
public void setAssociation(ERDAssociation association) {
this.association = association;
}
@Override
public void redo() {
if (association != null) {
sourceEntity.addAssociation(association, true);
targetEntity.addReferenceAssociation(association, true);
}
}
@Override
public void undo() {
if (association != null) {
sourceEntity.removeAssociation(association, true);
targetEntity.removeReferenceAssociation(association, true);
}
}
protected ERDAssociation createAssociation(ERDElement sourceEntity, ERDElement targetEntity, boolean reflect) {
return new ERDAssociation(sourceEntity, targetEntity, true);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.swt.SWT;
import org.jkiss.dbeaver.ext.erd.model.ERDAssociation;
import org.jkiss.dbeaver.ext.erd.model.ERDElement;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
import org.jkiss.dbeaver.model.struct.DBSEntityAssociation;
import org.jkiss.dbeaver.model.virtual.DBVEntity;
import org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey;
import org.jkiss.dbeaver.model.virtual.DBVUtils;
import org.jkiss.dbeaver.ui.UIUtils;
/**
* Command to delete relationship
*
* @author Serge Rider
*/
public class AssociationDeleteCommand extends Command {
protected final AssociationPart part;
protected final ERDElement sourceEntity;
protected final ERDElement targetEntity;
protected final ERDAssociation association;
public AssociationDeleteCommand(AssociationPart part) {
super();
this.part = part;
association = part.getAssociation();
sourceEntity = association.getSourceEntity();
targetEntity = association.getTargetEntity();
}
/**
* Removes the relationship
*/
@Override
public void execute() {
DBSEntityAssociation entityAssociation = association.getObject();
if (entityAssociation instanceof DBVEntityForeignKey) {
if (!UIUtils.confirmAction("Delete logical key", "Are you sure you want to delete logical key '" + part.getAssociation().getName() + "'?")) {
return;
}
DBVEntity vEntity = DBVUtils.getVirtualEntity(entityAssociation.getParentObject(), false);
if (vEntity == null) {
UIUtils.showMessageBox(UIUtils.getActiveWorkbenchShell(), "No virtual entity", "Can't find association owner virtual entity", SWT.ICON_ERROR);
return;
}
vEntity.removeForeignKey((DBVEntityForeignKey) entityAssociation);
}
part.markAssociatedAttributes(EditPart.SELECTED_NONE);
targetEntity.removeReferenceAssociation(association, true);
sourceEntity.removeAssociation(association, true);
association.setSourceEntity(null);
association.setTargetEntity(null);
}
/**
* Restores the relationship
*/
@Override
public void undo() {
if (association.getSourceEntity() != null) {
return;
}
DBSEntityAssociation entityAssociation = association.getObject();
if (entityAssociation instanceof DBVEntityForeignKey) {
DBVEntity vEntity = DBVUtils.getVirtualEntity(entityAssociation.getParentObject(), false);
if (vEntity != null) {
vEntity.addForeignKey((DBVEntityForeignKey) entityAssociation);
}
}
association.setSourceEntity(sourceEntity);
association.setTargetEntity(targetEntity);
sourceEntity.addAssociation(association, true);
targetEntity.addReferenceAssociation(association, true);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.swt.SWT;
import org.jkiss.dbeaver.ext.erd.model.ERDAssociation;
import org.jkiss.dbeaver.ext.erd.model.ERDElement;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
import org.jkiss.dbeaver.model.struct.DBSEntityAssociation;
import org.jkiss.dbeaver.model.virtual.DBVEntity;
import org.jkiss.dbeaver.model.virtual.DBVEntityForeignKey;
import org.jkiss.dbeaver.model.virtual.DBVUtils;
import org.jkiss.dbeaver.ui.UIUtils;
/**
* Command to delete relationship
*
* @author Serge Rider
*/
public class AssociationDeleteCommand extends Command {
protected final AssociationPart part;
protected final ERDElement sourceEntity;
protected final ERDElement targetEntity;
protected final ERDAssociation association;
public AssociationDeleteCommand(AssociationPart part) {
super();
this.part = part;
association = part.getAssociation();
sourceEntity = association.getSourceEntity();
targetEntity = association.getTargetEntity();
}
/**
* Removes the relationship
*/
@Override
public void execute() {
DBSEntityAssociation entityAssociation = association.getObject();
if (entityAssociation instanceof DBVEntityForeignKey) {
if (!UIUtils.confirmAction("Delete logical key", "Are you sure you want to delete logical key '" + part.getAssociation().getName() + "'?")) {
return;
}
DBVEntity vEntity = DBVUtils.getVirtualEntity(entityAssociation.getParentObject(), false);
if (vEntity == null) {
UIUtils.showMessageBox(UIUtils.getActiveWorkbenchShell(), "No virtual entity", "Can't find association owner virtual entity", SWT.ICON_ERROR);
return;
}
vEntity.removeForeignKey((DBVEntityForeignKey) entityAssociation);
}
part.markAssociatedAttributes(EditPart.SELECTED_NONE);
targetEntity.removeReferenceAssociation(association, true);
sourceEntity.removeAssociation(association, true);
association.setSourceEntity(null);
association.setTargetEntity(null);
}
/**
* Restores the relationship
*/
@Override
public void undo() {
if (association.getSourceEntity() != null) {
return;
}
DBSEntityAssociation entityAssociation = association.getObject();
if (entityAssociation instanceof DBVEntityForeignKey) {
DBVEntity vEntity = DBVUtils.getVirtualEntity(entityAssociation.getParentObject(), false);
if (vEntity != null) {
vEntity.addForeignKey((DBVEntityForeignKey) entityAssociation);
}
}
association.setSourceEntity(sourceEntity);
association.setTargetEntity(targetEntity);
sourceEntity.addAssociation(association, true);
targetEntity.addReferenceAssociation(association, true);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDAssociation;
import org.jkiss.dbeaver.ext.erd.model.ERDElement;
import java.util.List;
/**
* Command to change the foreign key we are connecting to a particular primary
* key
*
* @author Serge Rider
*/
public class AssociationReconnectSourceCommand extends Command {
protected ERDElement sourceEntity;
protected ERDElement targetEntity;
protected ERDAssociation association;
protected ERDElement oldSourceEntity;
/**
* Makes sure that primary key doesn't reconnect to itself or try to create
* a relationship which already exists
*/
@Override
public boolean canExecute() {
boolean returnVal = true;
ERDElement primaryEntity = association.getTargetEntity();
//cannot connect to itself
if (primaryEntity.equals(sourceEntity)) {
returnVal = false;
} else {
List<ERDAssociation> relationships = sourceEntity.getAssociations();
for (ERDAssociation relationship : relationships) {
if (relationship.getTargetEntity().equals(targetEntity) &&
relationship.getSourceEntity().equals(sourceEntity)) {
returnVal = false;
break;
}
}
}
return returnVal;
}
@Override
public void execute() {
if (sourceEntity != null) {
oldSourceEntity.removeAssociation(association, true);
association.setSourceEntity(sourceEntity);
sourceEntity.addAssociation(association, true);
}
}
public void setSourceEntity(ERDElement sourceEntity) {
this.sourceEntity = sourceEntity;
}
public ERDAssociation getAssociation() {
return association;
}
public void setAssociation(ERDAssociation association) {
this.association = association;
targetEntity = association.getTargetEntity();
oldSourceEntity = association.getSourceEntity();
}
@Override
public void undo() {
sourceEntity.removeAssociation(association, true);
association.setSourceEntity(oldSourceEntity);
oldSourceEntity.addAssociation(association, true);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDAssociation;
import org.jkiss.dbeaver.ext.erd.model.ERDElement;
import java.util.List;
/**
* Command to change the foreign key we are connecting to a particular primary
* key
*
* @author Serge Rider
*/
public class AssociationReconnectSourceCommand extends Command {
protected ERDElement sourceEntity;
protected ERDElement targetEntity;
protected ERDAssociation association;
protected ERDElement oldSourceEntity;
/**
* Makes sure that primary key doesn't reconnect to itself or try to create
* a relationship which already exists
*/
@Override
public boolean canExecute() {
boolean returnVal = true;
ERDElement primaryEntity = association.getTargetEntity();
//cannot connect to itself
if (primaryEntity.equals(sourceEntity)) {
returnVal = false;
} else {
List<ERDAssociation> relationships = sourceEntity.getAssociations();
for (ERDAssociation relationship : relationships) {
if (relationship.getTargetEntity().equals(targetEntity) &&
relationship.getSourceEntity().equals(sourceEntity)) {
returnVal = false;
break;
}
}
}
return returnVal;
}
@Override
public void execute() {
if (sourceEntity != null) {
oldSourceEntity.removeAssociation(association, true);
association.setSourceEntity(sourceEntity);
sourceEntity.addAssociation(association, true);
}
}
public void setSourceEntity(ERDElement sourceEntity) {
this.sourceEntity = sourceEntity;
}
public ERDAssociation getAssociation() {
return association;
}
public void setAssociation(ERDAssociation association) {
this.association = association;
targetEntity = association.getTargetEntity();
oldSourceEntity = association.getSourceEntity();
}
@Override
public void undo() {
sourceEntity.removeAssociation(association, true);
association.setSourceEntity(oldSourceEntity);
oldSourceEntity.addAssociation(association, true);
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDAssociation;
import org.jkiss.dbeaver.ext.erd.model.ERDElement;
import java.util.List;
/**
* Command to change the primary key we are connecting to a particular foreign key
* key
*/
public class AssociationReconnectTargetCommand extends Command {
protected ERDElement sourceEntity;
protected ERDElement targetEntity;
protected ERDAssociation relationship;
protected ERDElement oldTargetEntity;
/**
* Makes sure that foreign key doesn't reconnect to itself or try to create
* a relationship which already exists
*/
@Override
public boolean canExecute() {
boolean returnVal = true;
ERDElement foreignKeyEntity = relationship.getSourceEntity();
if (foreignKeyEntity.equals(targetEntity)) {
returnVal = false;
} else {
List<ERDAssociation> relationships = targetEntity.getReferences();
for (ERDAssociation relationship : relationships) {
if (relationship.getSourceEntity().equals(sourceEntity)
&& relationship.getTargetEntity().equals(targetEntity)) {
returnVal = false;
break;
}
}
}
return returnVal;
}
@Override
public void execute() {
if (targetEntity != null) {
oldTargetEntity.removeReferenceAssociation(relationship, true);
relationship.setTargetEntity(targetEntity);
targetEntity.addReferenceAssociation(relationship, true);
}
}
public void setTargetEntity(ERDElement targetEntity) {
this.targetEntity = targetEntity;
}
public void setRelationship(ERDAssociation relationship) {
this.relationship = relationship;
oldTargetEntity = relationship.getTargetEntity();
sourceEntity = relationship.getSourceEntity();
}
@Override
public void undo() {
targetEntity.removeReferenceAssociation(relationship, true);
relationship.setTargetEntity(oldTargetEntity);
oldTargetEntity.addReferenceAssociation(relationship, true);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDAssociation;
import org.jkiss.dbeaver.ext.erd.model.ERDElement;
import java.util.List;
/**
* Command to change the primary key we are connecting to a particular foreign key
* key
*/
public class AssociationReconnectTargetCommand extends Command {
protected ERDElement sourceEntity;
protected ERDElement targetEntity;
protected ERDAssociation relationship;
protected ERDElement oldTargetEntity;
/**
* Makes sure that foreign key doesn't reconnect to itself or try to create
* a relationship which already exists
*/
@Override
public boolean canExecute() {
boolean returnVal = true;
ERDElement foreignKeyEntity = relationship.getSourceEntity();
if (foreignKeyEntity.equals(targetEntity)) {
returnVal = false;
} else {
List<ERDAssociation> relationships = targetEntity.getReferences();
for (ERDAssociation relationship : relationships) {
if (relationship.getSourceEntity().equals(sourceEntity)
&& relationship.getTargetEntity().equals(targetEntity)) {
returnVal = false;
break;
}
}
}
return returnVal;
}
@Override
public void execute() {
if (targetEntity != null) {
oldTargetEntity.removeReferenceAssociation(relationship, true);
relationship.setTargetEntity(targetEntity);
targetEntity.addReferenceAssociation(relationship, true);
}
}
public void setTargetEntity(ERDElement targetEntity) {
this.targetEntity = targetEntity;
}
public void setRelationship(ERDAssociation relationship) {
this.relationship = relationship;
oldTargetEntity = relationship.getTargetEntity();
sourceEntity = relationship.getSourceEntity();
}
@Override
public void undo() {
targetEntity.removeReferenceAssociation(relationship, true);
relationship.setTargetEntity(oldTargetEntity);
oldTargetEntity.addReferenceAssociation(relationship, true);
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
public abstract class BendpointCommand extends Command {
protected final AssociationPart association;
public BendpointCommand(AssociationPart association) {
this.association = association;
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
public abstract class BendpointCommand extends Command {
protected final AssociationPart association;
public BendpointCommand(AssociationPart association) {
this.association = association;
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Point;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
public class BendpointCreateCommand extends BendpointCommand {
private Point location;
private int bendpointIndex;
public BendpointCreateCommand(AssociationPart association, Point location, int bendpointIndex) {
super(association);
this.location = location;
this.bendpointIndex = bendpointIndex;
}
@Override
public void execute() {
association.addBendpoint(bendpointIndex, location);
}
@Override
public void undo() {
association.removeBendpoint(bendpointIndex);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Point;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
public class BendpointCreateCommand extends BendpointCommand {
private Point location;
private int bendpointIndex;
public BendpointCreateCommand(AssociationPart association, Point location, int bendpointIndex) {
super(association);
this.location = location;
this.bendpointIndex = bendpointIndex;
}
@Override
public void execute() {
association.addBendpoint(bendpointIndex, location);
}
@Override
public void undo() {
association.removeBendpoint(bendpointIndex);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
public class BendpointDeleteCommand extends BendpointCommand {
private int bendpointIndex;
public BendpointDeleteCommand(AssociationPart association, int bendpointIndex) {
super(association);
this.bendpointIndex = bendpointIndex;
}
@Override
public void execute() {
association.removeBendpoint(bendpointIndex);
}
@Override
public void undo() {
/*
super.undo();
getWire().insertBendpoint(getIndex(), bendpoint);
*/
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
public class BendpointDeleteCommand extends BendpointCommand {
private int bendpointIndex;
public BendpointDeleteCommand(AssociationPart association, int bendpointIndex) {
super(association);
this.bendpointIndex = bendpointIndex;
}
@Override
public void execute() {
association.removeBendpoint(bendpointIndex);
}
@Override
public void undo() {
/*
super.undo();
getWire().insertBendpoint(getIndex(), bendpoint);
*/
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.Bendpoint;
import org.eclipse.draw2d.geometry.Point;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
public class BendpointMoveCommand extends BendpointCommand {
private Point location;
private int bendpointIndex;
private Bendpoint oldBendpoint;
public BendpointMoveCommand(AssociationPart association, Point location, int bendpointIndex) {
super(association);
this.location = location;
this.bendpointIndex = bendpointIndex;
}
@Override
public void execute() {
association.moveBendpoint(bendpointIndex, location);
/*
WireBendpoint bp = new WireBendpoint();
bp.setRelativeDimensions(getFirstRelativeDimension(),
getSecondRelativeDimension());
setOldBendpoint((Bendpoint) getWire().getBendpoints().get(getIndex()));
getWire().setBendpoint(getIndex(), bp);
super.execute();
*/
}
@Override
public void undo() {
/*
super.undo();
getWire().setBendpoint(getIndex(), getOldBendpoint());
*/
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.Bendpoint;
import org.eclipse.draw2d.geometry.Point;
import org.jkiss.dbeaver.ext.erd.part.AssociationPart;
public class BendpointMoveCommand extends BendpointCommand {
private Point location;
private int bendpointIndex;
private Bendpoint oldBendpoint;
public BendpointMoveCommand(AssociationPart association, Point location, int bendpointIndex) {
super(association);
this.location = location;
this.bendpointIndex = bendpointIndex;
}
@Override
public void execute() {
association.moveBendpoint(bendpointIndex, location);
/*
WireBendpoint bp = new WireBendpoint();
bp.setRelativeDimensions(getFirstRelativeDimension(),
getSecondRelativeDimension());
setOldBendpoint((Bendpoint) getWire().getBendpoints().get(getIndex()));
getWire().setBendpoint(getIndex(), bp);
super.execute();
*/
}
@Override
public void undo() {
/*
super.undo();
getWire().setBendpoint(getIndex(), getOldBendpoint());
*/
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDEntity;
import org.jkiss.dbeaver.ext.erd.model.ERDUtils;
import org.jkiss.dbeaver.ext.erd.part.DiagramPart;
import org.jkiss.dbeaver.ext.erd.part.EntityPart;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.navigator.DBNUtils;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSTable;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.UIUtils;
import java.util.Collections;
import java.util.List;
/**
* Add entity to diagram
*/
public class EntityAddCommand extends Command
{
protected DiagramPart diagramPart;
protected List<ERDEntity> entities;
protected Point location;
public EntityAddCommand(DiagramPart diagram, List<ERDEntity> entities, Point location)
{
this.diagramPart = diagram;
this.entities = entities;
this.location = location;
}
public DiagramPart getDiagram() {
return diagramPart;
}
@Override
public void execute()
{
VoidProgressMonitor monitor = new VoidProgressMonitor();
Point curLocation = location == null ? null : new Point(location);
for (ERDEntity entity : entities) {
boolean resolveRelations = false;
if (entity.getObject() == null) {
// Entity is not initialized
if (entity.getDataSource() != null) {
DBSObject selectedObject = DBUtils.getSelectedObject(DBUtils.getDefaultContext(entity.getDataSource(), false));
DBNDatabaseNode dsNode = DBNUtils.getNodeByObject(selectedObject != null ? selectedObject : entity.getDataSource().getContainer());
if (dsNode != null) {
DBNNode tableNode = DBWorkbench.getPlatformUI().selectObject(
UIUtils.getActiveWorkbenchShell(),
"Select a table",
dsNode,
null,
new Class[]{DBSTable.class},
new Class[]{DBSTable.class},
null);
if (tableNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) tableNode).getObject() instanceof DBSEntity) {
entity = ERDUtils.makeEntityFromObject(
monitor,
diagramPart.getDiagram(),
Collections.emptyList(),
(DBSEntity)((DBNDatabaseNode) tableNode).getObject(),
null);
// This actually only loads unresolved relations.
// This happens only with entities added on diagram during editing
entity.addModelRelations(monitor, diagramPart.getDiagram(), false, false);
}
}
}
}
if (entity.getObject() == null) {
continue;
}
diagramPart.getDiagram().addEntity(entity, true);
if (curLocation != null) {
// Put new entities in specified location
for (Object diagramChild : diagramPart.getChildren()) {
if (diagramChild instanceof EntityPart) {
EntityPart entityPart = (EntityPart) diagramChild;
if (entityPart.getEntity() == entity) {
final Rectangle newBounds = new Rectangle();
final Dimension size = entityPart.getFigure().getPreferredSize();
newBounds.x = curLocation.x;
newBounds.y = curLocation.y;
newBounds.width = size.width;
newBounds.height = size.height;
entityPart.modifyBounds(newBounds);
curLocation.x += size.width + (size.width / 2);
break;
}
}
}
}
handleEntityChange(entity, false);
}
}
@Override
public void undo()
{
for (ERDEntity entity : entities) {
diagramPart.getDiagram().removeEntity(entity, true);
handleEntityChange(entity, true);
}
}
protected void handleEntityChange(ERDEntity entity, boolean remove) {
// Nothing special
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDEntity;
import org.jkiss.dbeaver.ext.erd.model.ERDUtils;
import org.jkiss.dbeaver.ext.erd.part.DiagramPart;
import org.jkiss.dbeaver.ext.erd.part.EntityPart;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.navigator.DBNDatabaseNode;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.navigator.DBNUtils;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSEntity;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.rdb.DBSTable;
import org.jkiss.dbeaver.runtime.DBWorkbench;
import org.jkiss.dbeaver.ui.UIUtils;
import java.util.Collections;
import java.util.List;
/**
* Add entity to diagram
*/
public class EntityAddCommand extends Command
{
protected DiagramPart diagramPart;
protected List<ERDEntity> entities;
protected Point location;
public EntityAddCommand(DiagramPart diagram, List<ERDEntity> entities, Point location)
{
this.diagramPart = diagram;
this.entities = entities;
this.location = location;
}
public DiagramPart getDiagram() {
return diagramPart;
}
@Override
public void execute()
{
VoidProgressMonitor monitor = new VoidProgressMonitor();
Point curLocation = location == null ? null : new Point(location);
for (ERDEntity entity : entities) {
boolean resolveRelations = false;
if (entity.getObject() == null) {
// Entity is not initialized
if (entity.getDataSource() != null) {
DBSObject selectedObject = DBUtils.getSelectedObject(DBUtils.getDefaultContext(entity.getDataSource(), false));
DBNDatabaseNode dsNode = DBNUtils.getNodeByObject(selectedObject != null ? selectedObject : entity.getDataSource().getContainer());
if (dsNode != null) {
DBNNode tableNode = DBWorkbench.getPlatformUI().selectObject(
UIUtils.getActiveWorkbenchShell(),
"Select a table",
dsNode,
null,
new Class[]{DBSTable.class},
new Class[]{DBSTable.class},
null);
if (tableNode instanceof DBNDatabaseNode && ((DBNDatabaseNode) tableNode).getObject() instanceof DBSEntity) {
entity = ERDUtils.makeEntityFromObject(
monitor,
diagramPart.getDiagram(),
Collections.emptyList(),
(DBSEntity)((DBNDatabaseNode) tableNode).getObject(),
null);
// This actually only loads unresolved relations.
// This happens only with entities added on diagram during editing
entity.addModelRelations(monitor, diagramPart.getDiagram(), false, false);
}
}
}
}
if (entity.getObject() == null) {
continue;
}
diagramPart.getDiagram().addEntity(entity, true);
if (curLocation != null) {
// Put new entities in specified location
for (Object diagramChild : diagramPart.getChildren()) {
if (diagramChild instanceof EntityPart) {
EntityPart entityPart = (EntityPart) diagramChild;
if (entityPart.getEntity() == entity) {
final Rectangle newBounds = new Rectangle();
final Dimension size = entityPart.getFigure().getPreferredSize();
newBounds.x = curLocation.x;
newBounds.y = curLocation.y;
newBounds.width = size.width;
newBounds.height = size.height;
entityPart.modifyBounds(newBounds);
curLocation.x += size.width + (size.width / 2);
break;
}
}
}
}
handleEntityChange(entity, false);
}
}
@Override
public void undo()
{
for (ERDEntity entity : entities) {
diagramPart.getDiagram().removeEntity(entity, true);
handleEntityChange(entity, true);
}
}
protected void handleEntityChange(ERDEntity entity, boolean remove) {
// Nothing special
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDAssociation;
import org.jkiss.dbeaver.ext.erd.model.ERDEntity;
import org.jkiss.dbeaver.ext.erd.part.DiagramPart;
import org.jkiss.dbeaver.ext.erd.part.EntityPart;
import java.util.ArrayList;
import java.util.List;
/**
* Command to delete tables from the schema
*
* @author Serge Rider
*/
public class EntityDeleteCommand extends Command {
private EntityPart entityPart;
private DiagramPart diagramPart;
private ERDEntity entity;
private int index = -1;
private List<ERDAssociation> foreignKeyRelationships = new ArrayList<>();
private List<ERDAssociation> primaryKeyRelationships = new ArrayList<>();
//private Rectangle bounds;
public EntityDeleteCommand(EntityPart entityPart) {
this.entityPart = entityPart;
this.diagramPart = entityPart.getDiagramPart();
this.entity = entityPart.getEntity();
//this.bounds = entityPart.getFigure().getBounds().getCopy();
}
public EntityPart getEntityPart() {
return entityPart;
}
public ERDEntity getEntity() {
return entity;
}
private void deleteRelationships(ERDEntity t) {
this.foreignKeyRelationships.addAll(t.getAssociations());
//for all relationships where current entity is foreign key
for (ERDAssociation association : foreignKeyRelationships) {
association.getTargetEntity().removeReferenceAssociation(association, true);
t.removeAssociation(association, true);
}
//for all relationships where current entity is primary key
this.primaryKeyRelationships.addAll(t.getReferences());
for (ERDAssociation r : primaryKeyRelationships) {
r.getSourceEntity().removeAssociation(r, true);
t.removeReferenceAssociation(r, true);
}
}
/**
* @see org.eclipse.gef.commands.Command#execute()
*/
@Override
public void execute() {
primExecute();
}
/**
* Invokes the execution of this command.
*/
private void primExecute() {
// Put entity's bound in init map - it could be used by EntityPart on undo
diagramPart.getDiagram().getVisualInfo(entity.getObject(), true).initBounds = entityPart.getBounds();
// Zero bounds - to let modifyBounds reflect on undo
//entityPart.modifyBounds(new Rectangle(0, 0, 0, 0));
// Delete entity
deleteRelationships(entity);
index = diagramPart.getDiagram().getEntities().indexOf(entity);
diagramPart.getDiagram().removeEntity(entity, true);
}
/**
* @see org.eclipse.gef.commands.Command#redo()
*/
@Override
public void redo() {
primExecute();
}
private void restoreRelationships() {
for (ERDAssociation r : foreignKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
foreignKeyRelationships.clear();
for (ERDAssociation r : primaryKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
primaryKeyRelationships.clear();
}
@Override
public void undo() {
diagramPart.getDiagram().addEntity(entity, index, true);
restoreRelationships();
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDAssociation;
import org.jkiss.dbeaver.ext.erd.model.ERDEntity;
import org.jkiss.dbeaver.ext.erd.part.DiagramPart;
import org.jkiss.dbeaver.ext.erd.part.EntityPart;
import java.util.ArrayList;
import java.util.List;
/**
* Command to delete tables from the schema
*
* @author Serge Rider
*/
public class EntityDeleteCommand extends Command {
private EntityPart entityPart;
private DiagramPart diagramPart;
private ERDEntity entity;
private int index = -1;
private List<ERDAssociation> foreignKeyRelationships = new ArrayList<>();
private List<ERDAssociation> primaryKeyRelationships = new ArrayList<>();
//private Rectangle bounds;
public EntityDeleteCommand(EntityPart entityPart) {
this.entityPart = entityPart;
this.diagramPart = entityPart.getDiagramPart();
this.entity = entityPart.getEntity();
//this.bounds = entityPart.getFigure().getBounds().getCopy();
}
public EntityPart getEntityPart() {
return entityPart;
}
public ERDEntity getEntity() {
return entity;
}
private void deleteRelationships(ERDEntity t) {
this.foreignKeyRelationships.addAll(t.getAssociations());
//for all relationships where current entity is foreign key
for (ERDAssociation association : foreignKeyRelationships) {
association.getTargetEntity().removeReferenceAssociation(association, true);
t.removeAssociation(association, true);
}
//for all relationships where current entity is primary key
this.primaryKeyRelationships.addAll(t.getReferences());
for (ERDAssociation r : primaryKeyRelationships) {
r.getSourceEntity().removeAssociation(r, true);
t.removeReferenceAssociation(r, true);
}
}
/**
* @see org.eclipse.gef.commands.Command#execute()
*/
@Override
public void execute() {
primExecute();
}
/**
* Invokes the execution of this command.
*/
private void primExecute() {
// Put entity's bound in init map - it could be used by EntityPart on undo
diagramPart.getDiagram().getVisualInfo(entity.getObject(), true).initBounds = entityPart.getBounds();
// Zero bounds - to let modifyBounds reflect on undo
//entityPart.modifyBounds(new Rectangle(0, 0, 0, 0));
// Delete entity
deleteRelationships(entity);
index = diagramPart.getDiagram().getEntities().indexOf(entity);
diagramPart.getDiagram().removeEntity(entity, true);
}
/**
* @see org.eclipse.gef.commands.Command#redo()
*/
@Override
public void redo() {
primExecute();
}
private void restoreRelationships() {
for (ERDAssociation r : foreignKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
foreignKeyRelationships.clear();
for (ERDAssociation r : primaryKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
primaryKeyRelationships.clear();
}
@Override
public void undo() {
diagramPart.getDiagram().addEntity(entity, index, true);
restoreRelationships();
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.part.NodePart;
/**
* Command to move the bounds of an existing table. Only used with
* XYLayoutEditPolicy (manual layout)
*
* @author Serge Rider
*/
public class NodeMoveCommand extends Command
{
private NodePart nodePart;
private Rectangle oldBounds;
private Rectangle newBounds;
public NodeMoveCommand(NodePart nodePart, Rectangle oldBounds, Rectangle newBounds)
{
super();
this.nodePart = nodePart;
this.oldBounds = oldBounds;
this.newBounds = newBounds;
}
@Override
public void execute()
{
/*
List tcList = nodePart.getTargetConnections();
for (Object tc : tcList) {
AssociationPart as = (AssociationPart)tc ;
PolylineConnection pc = (PolylineConnection) as.getFigure();
pc.getConnectionRouter().route(pc);
}
*/
nodePart.modifyBounds(newBounds);
}
@Override
public void undo()
{
nodePart.modifyBounds(oldBounds);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.part.NodePart;
/**
* Command to move the bounds of an existing table. Only used with
* XYLayoutEditPolicy (manual layout)
*
* @author Serge Rider
*/
public class NodeMoveCommand extends Command
{
private NodePart nodePart;
private Rectangle oldBounds;
private Rectangle newBounds;
public NodeMoveCommand(NodePart nodePart, Rectangle oldBounds, Rectangle newBounds)
{
super();
this.nodePart = nodePart;
this.oldBounds = oldBounds;
this.newBounds = newBounds;
}
@Override
public void execute()
{
/*
List tcList = nodePart.getTargetConnections();
for (Object tc : tcList) {
AssociationPart as = (AssociationPart)tc ;
PolylineConnection pc = (PolylineConnection) as.getFigure();
pc.getConnectionRouter().route(pc);
}
*/
nodePart.modifyBounds(newBounds);
}
@Override
public void undo()
{
nodePart.modifyBounds(oldBounds);
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDNote;
import org.jkiss.dbeaver.ext.erd.part.DiagramPart;
import org.jkiss.dbeaver.ext.erd.part.NotePart;
/**
* Add entity to diagram
*/
public class NoteCreateCommand extends Command
{
private DiagramPart diagramPart;
private ERDNote note;
private Point location;
private Dimension size;
public NoteCreateCommand(DiagramPart diagram, ERDNote note, Point location, Dimension size)
{
this.diagramPart = diagram;
this.note = note;
this.location = location;
this.size = size;
}
@Override
public void execute()
{
diagramPart.getDiagram().addNote(note, true);
//diagramPart.getDiagram().addModelRelations(monitor, table, true);
if (location != null) {
// Set new note location
for (Object diagramChild : diagramPart.getChildren()) {
if (diagramChild instanceof NotePart) {
NotePart notePart = (NotePart) diagramChild;
if (notePart.getNote() == note) {
Dimension size = this.size;
if (size == null || size.width <= 0 || size.height <= 0) {
size = notePart.getFigure().getPreferredSize();
}
final Rectangle newBounds = new Rectangle(location.x, location.y, size.width, size.height);
notePart.modifyBounds(newBounds);
break;
}
}
}
}
}
@Override
public void undo()
{
diagramPart.getDiagram().removeNote(note, true);
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDNote;
import org.jkiss.dbeaver.ext.erd.part.DiagramPart;
import org.jkiss.dbeaver.ext.erd.part.NotePart;
/**
* Add entity to diagram
*/
public class NoteCreateCommand extends Command
{
private DiagramPart diagramPart;
private ERDNote note;
private Point location;
private Dimension size;
public NoteCreateCommand(DiagramPart diagram, ERDNote note, Point location, Dimension size)
{
this.diagramPart = diagram;
this.note = note;
this.location = location;
this.size = size;
}
@Override
public void execute()
{
diagramPart.getDiagram().addNote(note, true);
//diagramPart.getDiagram().addModelRelations(monitor, table, true);
if (location != null) {
// Set new note location
for (Object diagramChild : diagramPart.getChildren()) {
if (diagramChild instanceof NotePart) {
NotePart notePart = (NotePart) diagramChild;
if (notePart.getNote() == note) {
Dimension size = this.size;
if (size == null || size.width <= 0 || size.height <= 0) {
size = notePart.getFigure().getPreferredSize();
}
final Rectangle newBounds = new Rectangle(location.x, location.y, size.width, size.height);
notePart.modifyBounds(newBounds);
break;
}
}
}
}
}
@Override
public void undo()
{
diagramPart.getDiagram().removeNote(note, true);
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDNote;
import org.jkiss.dbeaver.ext.erd.model.EntityDiagram;
import org.jkiss.dbeaver.ext.erd.part.NotePart;
/**
* Command to delete tables from the schema
*
* @author Serge Rider
*/
public class NoteDeleteCommand extends Command
{
private NotePart notePart;
private ERDNote note;
private EntityDiagram entityDiagram;
private Rectangle bounds;
public NoteDeleteCommand(EntityDiagram entityDiagram, NotePart notePart, Rectangle originalBounds) {
this.entityDiagram = entityDiagram;
this.notePart = notePart;
this.note = notePart.getNote();
this.bounds = originalBounds;
}
/**
* @see org.eclipse.gef.commands.Command#execute()
*/
@Override
public void execute()
{
entityDiagram.removeNote(note, true);
}
/**
* @see org.eclipse.gef.commands.Command#redo()
*/
@Override
public void redo()
{
execute();
}
@Override
public void undo()
{
entityDiagram.addNote(note, true);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.erd.command;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.commands.Command;
import org.jkiss.dbeaver.ext.erd.model.ERDNote;
import org.jkiss.dbeaver.ext.erd.model.EntityDiagram;
import org.jkiss.dbeaver.ext.erd.part.NotePart;
/**
* Command to delete tables from the schema
*
* @author Serge Rider
*/
public class NoteDeleteCommand extends Command
{
private NotePart notePart;
private ERDNote note;
private EntityDiagram entityDiagram;
private Rectangle bounds;
public NoteDeleteCommand(EntityDiagram entityDiagram, NotePart notePart, Rectangle originalBounds) {
this.entityDiagram = entityDiagram;
this.notePart = notePart;
this.note = notePart.getNote();
this.bounds = originalBounds;
}
/**
* @see org.eclipse.gef.commands.Command#execute()
*/
@Override
public void execute()
{
entityDiagram.removeNote(note, true);
}
/**
* @see org.eclipse.gef.commands.Command#redo()
*/
@Override
public void redo()
{
execute();
}
@Override
public void undo()
{
entityDiagram.addNote(note, true);
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 19, 2004
*/
package org.jkiss.dbeaver.ext.erd.directedit;
import org.eclipse.jface.viewers.ICellEditorValidator;
/**
* ICellValidator to validate direct edit values in the column label
* Collaborates with an instance of ValidationMessageHandler
* @author Serge Rider
*/
public class ColumnNameTypeCellEditorValidator implements ICellEditorValidator
{
private ValidationMessageHandler handler;
/**
* @param validationMessageHandler the validation message handler to pass error information to
*/
public ColumnNameTypeCellEditorValidator(ValidationMessageHandler validationMessageHandler)
{
this.handler = validationMessageHandler;
}
/**
* @return the error message if an error has occurred, otherwise null
*/
@Override
public String isValid(Object value)
{
String string = (String)value;
String name = null;
String type = null;
int colonIndex = string.indexOf(':');
if (colonIndex >= 0)
{
name = string.substring(0, colonIndex);
if (string.length() > colonIndex+1)
{
type = string.substring(colonIndex+1);
}
}
if (name != null && type!= null)
{
if (name.indexOf(" ")!= -1)
{
String text = "Column name should not include the space character";
return setMessageText(text);
} else {
return unsetMessageText();
}
}
else
{
String text = "Invalid format for text entry. Needs [name]:[type] format";
return setMessageText(text);
}
}
private String unsetMessageText()
{
handler.reset();
return null;
}
private String setMessageText(String text)
{
handler.setMessageText(text);
return text;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 19, 2004
*/
package org.jkiss.dbeaver.ext.erd.directedit;
import org.eclipse.jface.viewers.ICellEditorValidator;
/**
* ICellValidator to validate direct edit values in the column label
* Collaborates with an instance of ValidationMessageHandler
* @author Serge Rider
*/
public class ColumnNameTypeCellEditorValidator implements ICellEditorValidator
{
private ValidationMessageHandler handler;
/**
* @param validationMessageHandler the validation message handler to pass error information to
*/
public ColumnNameTypeCellEditorValidator(ValidationMessageHandler validationMessageHandler)
{
this.handler = validationMessageHandler;
}
/**
* @return the error message if an error has occurred, otherwise null
*/
@Override
public String isValid(Object value)
{
String string = (String)value;
String name = null;
String type = null;
int colonIndex = string.indexOf(':');
if (colonIndex >= 0)
{
name = string.substring(0, colonIndex);
if (string.length() > colonIndex+1)
{
type = string.substring(colonIndex+1);
}
}
if (name != null && type!= null)
{
if (name.indexOf(" ")!= -1)
{
String text = "Column name should not include the space character";
return setMessageText(text);
} else {
return unsetMessageText();
}
}
else
{
String text = "Invalid format for text entry. Needs [name]:[type] format";
return setMessageText(text);
}
}
private String unsetMessageText()
{
handler.reset();
return null;
}
private String setMessageText(String text)
{
handler.setMessageText(text);
return text;
}
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 13, 2004
*/
package org.jkiss.dbeaver.ext.erd.directedit;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.jface.viewers.ICellEditorValidator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Text;
import org.jkiss.dbeaver.ext.erd.figures.NoteFigure;
/**
* A generic DirectEdit manager to be used for labels which includes validation
* functionality by adding the ICellEditorValidator on startup
*/
public class ExtendedDirectEditManager extends DirectEditManager {
protected Font figureFont;
protected VerifyListener verifyListener;
protected IFigure figure;
protected String originalValue;
private boolean committing = false;
private ICellEditorValidator validator = null;
/**
* Creates a new ActivityDirectEditManager with the given attributes.
*
* @param source the source EditPart
* @param editorType type of editor
* @param locator the CellEditorLocator
*/
public ExtendedDirectEditManager(GraphicalEditPart source, Class editorType, CellEditorLocator locator,
IFigure figure, ICellEditorValidator validator) {
super(source, editorType, locator);
this.figure = figure;
this.originalValue = getFigureText(figure);
this.validator = validator;
}
private static String getFigureText(IFigure figure) {
if (figure instanceof Label) {
return ((Label) figure).getText();
} else if (figure instanceof NoteFigure) {
return ((NoteFigure) figure).getText();
} else {
return "???";
}
}
/**
* @see org.eclipse.gef.tools.DirectEditManager#bringDown()
*/
@Override
protected void bringDown() {
Font disposeFont = figureFont;
figureFont = null;
super.bringDown();
if (disposeFont != null)
disposeFont.dispose();
}
/**
* @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
*/
@Override
protected void initCellEditor() {
Text text = (Text) getCellEditor().getControl();
//add the verifyListener to apply changes to the control size
verifyListener = new VerifyListener() {
/**
* Changes the size of the editor control to reflect the changed
* text
*/
@Override
public void verifyText(VerifyEvent event) {
Text text = (Text) getCellEditor().getControl();
String oldText = text.getText();
String leftText = oldText.substring(0, event.start);
String rightText = oldText.substring(event.end, oldText.length());
GC gc = new GC(text);
String s = leftText + event.text + rightText;
Point size = gc.textExtent(leftText + event.text + rightText);
gc.dispose();
if (size.x != 0)
size = text.computeSize(size.x, SWT.DEFAULT);
else {
//just make it square
size.x = size.y;
}
getCellEditor().getControl().setSize(size.x, size.y);
}
};
text.addVerifyListener(verifyListener);
//set the initial value of the
originalValue = getFigureText(this.figure);
getCellEditor().setValue(originalValue);
//calculate the font size of the underlying
IFigure figure = getEditPart().getFigure();
figureFont = figure.getFont();
FontData data = figureFont.getFontData()[0];
Dimension fontSize = new Dimension(0, data.getHeight());
//set the font to be used
this.figure.translateToAbsolute(fontSize);
data.setHeight(fontSize.height);
figureFont = new Font(null, data);
//set the validator for the CellEditor
getCellEditor().setValidator(validator);
text.setFont(figureFont);
text.selectAll();
}
/**
* Commits the current value of the cell editor by getting a {@link Command}
* from the source edit part and executing it via the {@link CommandStack}.
* Finally, {@link #bringDown()}is called to perform and necessary cleanup.
*/
@Override
protected void commit() {
if (committing)
return;
committing = true;
try {
//we set the cell editor control to invisible to remove any
// possible flicker
getCellEditor().getControl().setVisible(false);
if (isDirty()) {
CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
EditPolicy editPolicy = getEditPart().getEditPolicy(EditPolicy.DIRECT_EDIT_ROLE);
Command command;
if (editPolicy != null) {
command = editPolicy.getCommand(getDirectEditRequest());
} else {
command = getEditPart().getCommand(getDirectEditRequest());
}
if (command != null && command.canExecute()) {
stack.execute(command);
}
}
} finally {
bringDown();
committing = false;
}
}
/**
* Need to override so as to remove the verify listener
*/
@Override
protected void unhookListeners() {
super.unhookListeners();
Text text = (Text) getCellEditor().getControl();
text.removeVerifyListener(verifyListener);
verifyListener = null;
}
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 13, 2004
*/
package org.jkiss.dbeaver.ext.erd.directedit;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CommandStack;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.jface.viewers.ICellEditorValidator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Text;
import org.jkiss.dbeaver.ext.erd.figures.NoteFigure;
/**
* A generic DirectEdit manager to be used for labels which includes validation
* functionality by adding the ICellEditorValidator on startup
*/
public class ExtendedDirectEditManager extends DirectEditManager {
protected Font figureFont;
protected VerifyListener verifyListener;
protected IFigure figure;
protected String originalValue;
private boolean committing = false;
private ICellEditorValidator validator = null;
/**
* Creates a new ActivityDirectEditManager with the given attributes.
*
* @param source the source EditPart
* @param editorType type of editor
* @param locator the CellEditorLocator
*/
public ExtendedDirectEditManager(GraphicalEditPart source, Class editorType, CellEditorLocator locator,
IFigure figure, ICellEditorValidator validator) {
super(source, editorType, locator);
this.figure = figure;
this.originalValue = getFigureText(figure);
this.validator = validator;
}
private static String getFigureText(IFigure figure) {
if (figure instanceof Label) {
return ((Label) figure).getText();
} else if (figure instanceof NoteFigure) {
return ((NoteFigure) figure).getText();
} else {
return "???";
}
}
/**
* @see org.eclipse.gef.tools.DirectEditManager#bringDown()
*/
@Override
protected void bringDown() {
Font disposeFont = figureFont;
figureFont = null;
super.bringDown();
if (disposeFont != null)
disposeFont.dispose();
}
/**
* @see org.eclipse.gef.tools.DirectEditManager#initCellEditor()
*/
@Override
protected void initCellEditor() {
Text text = (Text) getCellEditor().getControl();
//add the verifyListener to apply changes to the control size
verifyListener = new VerifyListener() {
/**
* Changes the size of the editor control to reflect the changed
* text
*/
@Override
public void verifyText(VerifyEvent event) {
Text text = (Text) getCellEditor().getControl();
String oldText = text.getText();
String leftText = oldText.substring(0, event.start);
String rightText = oldText.substring(event.end, oldText.length());
GC gc = new GC(text);
String s = leftText + event.text + rightText;
Point size = gc.textExtent(leftText + event.text + rightText);
gc.dispose();
if (size.x != 0)
size = text.computeSize(size.x, SWT.DEFAULT);
else {
//just make it square
size.x = size.y;
}
getCellEditor().getControl().setSize(size.x, size.y);
}
};
text.addVerifyListener(verifyListener);
//set the initial value of the
originalValue = getFigureText(this.figure);
getCellEditor().setValue(originalValue);
//calculate the font size of the underlying
IFigure figure = getEditPart().getFigure();
figureFont = figure.getFont();
FontData data = figureFont.getFontData()[0];
Dimension fontSize = new Dimension(0, data.getHeight());
//set the font to be used
this.figure.translateToAbsolute(fontSize);
data.setHeight(fontSize.height);
figureFont = new Font(null, data);
//set the validator for the CellEditor
getCellEditor().setValidator(validator);
text.setFont(figureFont);
text.selectAll();
}
/**
* Commits the current value of the cell editor by getting a {@link Command}
* from the source edit part and executing it via the {@link CommandStack}.
* Finally, {@link #bringDown()}is called to perform and necessary cleanup.
*/
@Override
protected void commit() {
if (committing)
return;
committing = true;
try {
//we set the cell editor control to invisible to remove any
// possible flicker
getCellEditor().getControl().setVisible(false);
if (isDirty()) {
CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
EditPolicy editPolicy = getEditPart().getEditPolicy(EditPolicy.DIRECT_EDIT_ROLE);
Command command;
if (editPolicy != null) {
command = editPolicy.getCommand(getDirectEditRequest());
} else {
command = getEditPart().getCommand(getDirectEditRequest());
}
if (command != null && command.canExecute()) {
stack.execute(command);
}
}
} finally {
bringDown();
committing = false;
}
}
/**
* Need to override so as to remove the verify listener
*/
@Override
protected void unhookListeners() {
super.unhookListeners();
Text text = (Text) getCellEditor().getControl();
text.removeVerifyListener(verifyListener);
verifyListener = null;
}
}
\ No newline at end of file
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 25, 2004
*/
package org.jkiss.dbeaver.ext.erd.directedit;
/**
* Represents interface for outputting validation error messages to some widget
* @author Serge Rider
*/
public interface ValidationMessageHandler
{
public void setMessageText(String text);
/**
* Resets so that the validation message is no longer shown
*/
public void reset();
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2020 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Created on Jul 25, 2004
*/
package org.jkiss.dbeaver.ext.erd.directedit;
/**
* Represents interface for outputting validation error messages to some widget
* @author Serge Rider
*/
public interface ValidationMessageHandler
{
public void setMessageText(String text);
/**
* Resets so that the validation message is no longer shown
*/
public void reset();
}
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册