You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2015/08/06 13:26:20 UTC
[2/3] empire-db git commit: prepare release 2.4.4
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/ConfigurationDialog.java
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/ConfigurationDialog.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/ConfigurationDialog.java
new file mode 100644
index 0000000..8670e51
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/ConfigurationDialog.java
@@ -0,0 +1,293 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.empire.db.eclipse.ui;
+
+import org.apache.empire.db.eclipse.Plugin;
+import org.apache.empire.db.eclipse.PluginConsts;
+import org.apache.empire.db.eclipse.model.ConfigFile;
+import org.apache.empire.db.eclipse.util.SWTResourceManager;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+
+public class ConfigurationDialog extends TitleAreaDialog
+{
+ private Navigator navigator;
+
+ private Page visiblePage;
+
+ private Button btnNextPage;
+
+ private Button btnPreviousPage;
+
+ private Button btnOk;
+
+ private Button btnCancel;
+
+ public ConfigurationDialog(Shell shell)
+ {
+ super(shell);
+ }
+
+ @Override
+ public void create()
+ {
+ super.create();
+ UpdateControls();
+ }
+
+ // overriding this methods allows you to set the
+ // title of the custom dialog
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ super.configureShell(newShell);
+ newShell.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dialog.title"));
+ }
+
+ @Override
+ protected Point getInitialSize()
+ {
+ return new Point(470, 685);
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent)
+ {
+ parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ this.btnPreviousPage = createButton(parent, PluginConsts.BUTTON_PREVIOUS_ID, Plugin.getInstance().getMessageService()
+ .resolveMessageKey("dialog.back"), true);
+ this.btnPreviousPage.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent e)
+ {
+ ConfigurationDialog.this.navigator.showPreviousPage();
+ UpdateControls();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e)
+ {
+ }
+ });
+ this.btnNextPage = createButton(parent, PluginConsts.BUTTON_NEXT_ID,
+ Plugin.getInstance().getMessageService().resolveMessageKey("dialog.next"), true);
+ this.btnNextPage.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent e)
+ {
+ ConfigurationDialog.this.navigator.showNextPage();
+ UpdateControls();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e)
+ {
+ }
+ });
+
+ this.btnOk = createButton(parent, PluginConsts.BUTTON_OK, Plugin.getInstance().getMessageService().resolveMessageKey("dialog.ok"),
+ false);
+ this.btnOk.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ if (checkRequiredFields())
+ {
+ saveAction();
+ setReturnCode(Window.OK);
+ close();
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+ this.btnCancel = createButton(parent, PluginConsts.BUTTON_CANCEL,
+ Plugin.getInstance().getMessageService().resolveMessageKey("dialog.close"), false);
+ this.btnCancel.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ save();
+ setReturnCode(Window.CANCEL);
+ close();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ setTitleImage(SWTResourceManager.getImage(ConfigurationDialog.class, "/icons/empire-db-logo.gif"));
+ Composite area = (Composite) super.createDialogArea(parent);
+ area.setLayout(null);
+ final MainPage mainPage = new MainPage(area, SWT.NONE);
+ mainPage.addExistingConfigsListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent event)
+ {
+ if (event.widget instanceof Combo)
+ {
+ Combo combo = (Combo) event.widget;
+ save();
+ load(Plugin.getInstance().getConfigFileService().getConfig(combo.getText()));
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+
+ mainPage.addBtnAddListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ save();
+ load(Plugin.getInstance().getConfigFileService().getDefaultConfig());
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+
+ }
+ });
+ mainPage.addBtnSaveListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ saveAction();
+ mainPage.setConfigTitleList(Plugin.getInstance().getConfigFileService().getConfigTitles());
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+ mainPage.addBtnDeleteListener(new SelectionListener()
+ {
+
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ if (MessageDialog.openConfirm(getShell(), Plugin.getInstance().getMessageService().resolveMessageKey("dialog.delete"),
+ Plugin.getInstance().getMessageService().resolveMessageKey("dialog.delete.msg")))
+ {
+ deleteConfig();
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+ this.visiblePage = mainPage;
+ this.navigator = new Navigator();
+ this.navigator.addPage(this.visiblePage);
+ final SchemaOptionsPage schemaOptions = new SchemaOptionsPage(area, SWT.NONE);
+ schemaOptions.addBtnTableDialogListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ ConfigurationDialog.this.navigator.save();
+ DBTablesDialog dbTablesDialog = new DBTablesDialog(getShell(), ConfigurationDialog.this.navigator.getCurrentConfig()
+ .getCodeGenConfig());
+ if (dbTablesDialog.open() == Window.OK)
+ {
+ schemaOptions.getCtlDbTablePattern().setText(dbTablesDialog.getSelectedTables());
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+ this.navigator.addPage(schemaOptions);
+ ClassParameterPage classParameterPage = new ClassParameterPage(area, SWT.NONE);
+ this.navigator.addPage(classParameterPage);
+ this.navigator.setPagesEnabled(false);
+
+ setHelpAvailable(false);
+ return area;
+ }
+
+ private void UpdateControls()
+ {
+ this.btnPreviousPage.setVisible(this.navigator.hasPreviousPage());
+ this.btnNextPage.setVisible(this.navigator.hasNextPage());
+ }
+
+ public void save()
+ {
+ if (ConfigurationDialog.this.navigator.getCurrentConfig() != null
+ && MessageDialog.openQuestion(getShell(), Plugin.getInstance().getMessageService().resolveMessageKey("dialog.save"),
+ Plugin.getInstance().getMessageService().resolveMessageKey("dialog.save.msg")))
+ {
+ saveAction();
+ }
+ }
+
+ public void saveAction()
+ {
+ ConfigFile configFile = this.navigator.save();
+ if (configFile != null)
+ {
+ Plugin.getInstance().getConfigFileService().saveConfig(configFile);
+ }
+ }
+
+ public void load(ConfigFile config)
+ {
+ this.navigator.load(config);
+ }
+
+ public void deleteConfig()
+ {
+ Plugin.getInstance().getConfigFileService().deleteConfig(this.navigator.getCurrentConfig().getUuid());
+ this.navigator.load(null);
+ }
+
+ public boolean hasConfig()
+ {
+ return this.navigator.getCurrentConfig() != null;
+ }
+
+ public String getConfigFileAbsolutPath()
+ {
+ return Plugin.getInstance().getConfigFileService().getConfigFilePath(this.navigator.getCurrentConfig().getUuid());
+ }
+
+ private boolean checkRequiredFields()
+ {
+ return this.navigator.checkRequiredFields();
+ }
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/DBTablesDialog.java
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/DBTablesDialog.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/DBTablesDialog.java
new file mode 100644
index 0000000..585f1d9
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/DBTablesDialog.java
@@ -0,0 +1,350 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.empire.db.eclipse.ui;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+import org.apache.empire.db.codegen.util.DBUtil;
+import org.apache.empire.db.eclipse.CodeGenConfig;
+import org.apache.empire.db.eclipse.Plugin;
+import org.apache.empire.db.eclipse.PluginConsts;
+import org.apache.empire.db.eclipse.util.SWTResourceManager;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DBTablesDialog extends TitleAreaDialog
+{
+ private CheckboxTableViewer checkboxTableViewer;
+ private Button btnConnect;
+
+ private final CodeGenConfig config;
+ private Label lblConnection;
+ private Button btnOk;
+ private Button btnSpaceholder;
+
+ private String selectedTables;
+
+ public DBTablesDialog(Shell parentShell, CodeGenConfig config)
+ {
+ super(parentShell);
+ this.config = config;
+ }
+
+ @Override
+ public void create()
+ {
+ super.create();
+ setTitle(Plugin.getInstance().getMessageService().resolveMessageKey("dialog.tables.discription"));
+ }
+
+ @Override
+ protected Point getInitialSize()
+ {
+ return new Point(343, 473);
+ }
+
+ // overriding this methods allows you to set the
+ // title of the custom dialog
+ @Override
+ protected void configureShell(Shell newShell)
+ {
+ super.configureShell(newShell);
+ newShell.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dialog.tables.title"));
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent)
+ {
+ parent.setLayoutData(new GridData(SWT.FILL, SWT.RIGHT, true, true));
+
+ this.btnSpaceholder = createButton(parent, PluginConsts.BUTTON_PREVIOUS_ID, " ", true);
+ this.btnSpaceholder.setText("################");
+ this.btnSpaceholder.setVisible(false);
+
+ // Update layout of the parent composite to count the spacer
+ GridLayout layout = (GridLayout) parent.getLayout();
+ layout.makeColumnsEqualWidth = false;
+
+ this.btnOk = createButton(parent, PluginConsts.BUTTON_OK,
+ Plugin.getInstance().getMessageService().resolveMessageKey("dialog.tables.finish"), false);
+ this.btnOk.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ StringBuilder sb = new StringBuilder();
+ Object[] tables = DBTablesDialog.this.checkboxTableViewer.getCheckedElements();
+ for (Object table : tables)
+ {
+ sb.append(table).append(",");
+ }
+ DBTablesDialog.this.selectedTables = sb.toString().substring(0, sb.length() - 1);
+ setReturnCode(Window.OK);
+ close();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+ createButton(parent, Window.CANCEL, Plugin.getInstance().getMessageService().resolveMessageKey("dialog.close"), false);
+
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ setTitleImage(SWTResourceManager.getImage(ConfigurationDialog.class, "/icons/logo.png"));
+ Composite composite = (Composite) super.createDialogArea(parent);
+ composite.setLayout(null);
+
+ this.btnConnect = new Button(composite, SWT.NONE);
+ this.btnConnect.setBounds(5, 5, 145, 25);
+ this.btnConnect.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dialog.tables.connect"));
+ this.btnConnect.setImage(SWTResourceManager.getImage(ConfigurationDialog.class, "/icons/testConnection.gif"));
+ this.btnConnect.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ try
+ {
+ Connection con = Plugin.getInstance().getJDBCConnection(DBTablesDialog.this.config.getJdbcType(),
+ DBTablesDialog.this.config.getJdbcServer(),
+ DBTablesDialog.this.config.getJdbcPort(),
+ DBTablesDialog.this.config.getJdbcSID(),
+ DBTablesDialog.this.config.getJdbcUser(),
+ DBTablesDialog.this.config.getJdbcPwd());
+ if (con != null)
+ {
+ DBTablesDialog.this.lblConnection.setText(Plugin.getInstance().getMessageService()
+ .resolveMessageKey("connectionSuccess"));
+ DBTablesDialog.this.lblConnection.setForeground(new Color(getShell().getDisplay(), 0, 255, 0));
+ DBTablesDialog.this.checkboxTableViewer.setInput(con);
+ if (DBTablesDialog.this.config.getDbTablePattern() != null)
+ {
+ String[] tablePatterns = DBTablesDialog.this.config.getDbTablePattern().split(",");
+ for (String pattern : tablePatterns)
+ {
+ DBTablesDialog.this.checkboxTableViewer.setChecked(pattern, true);
+ }
+ }
+ }
+ con.close();
+ }
+ catch (Exception e)
+ {
+ DBTablesDialog.this.lblConnection.setText(Plugin.getInstance().getMessageService()
+ .resolveMessageKey("connectionFailed"));
+ DBTablesDialog.this.lblConnection.setForeground(new Color(getShell().getDisplay(), 255, 0, 0));
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+
+ this.checkboxTableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
+ final Table table = this.checkboxTableViewer.getTable();
+ table.setBounds(5, 35, 290, 231);
+ table.setLinesVisible(true);
+
+ final Button btnCheckAll = new Button(composite, SWT.NONE);
+ btnCheckAll.setBounds(301, 35, 26, 26);
+ btnCheckAll.setImage(SWTResourceManager.getImage(ConfigurationDialog.class, "/icons/check_all.gif"));
+ btnCheckAll.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ Table table = DBTablesDialog.this.checkboxTableViewer.getTable();
+ for (int i = 0; i < table.getItemCount(); i++)
+ {
+ table.getItem(i).setChecked(true);
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+
+ final Button btnUncheckAll = new Button(composite, SWT.NONE);
+ btnUncheckAll.setBounds(301, 67, 26, 26);
+ btnUncheckAll.setImage(SWTResourceManager.getImage(ConfigurationDialog.class, "/icons/uncheck_all.gif"));
+ btnUncheckAll.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ Table table = DBTablesDialog.this.checkboxTableViewer.getTable();
+ for (int i = 0; i < table.getItemCount(); i++)
+ {
+ table.getItem(i).setChecked(false);
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+
+ this.lblConnection = new Label(composite, SWT.NONE);
+ this.lblConnection.setBounds(156, 10, 139, 15);
+ this.checkboxTableViewer.setContentProvider(new DBTablesContentProvider(this.config));
+ this.checkboxTableViewer.setLabelProvider(new DBTablesLabelProvider());
+
+ setHelpAvailable(false);
+ return composite;
+ }
+
+ public String getSelectedTables()
+ {
+ return this.selectedTables;
+ }
+
+ public void setSelectedTables(String selectedTables)
+ {
+ this.selectedTables = selectedTables;
+ }
+}
+
+class DBTablesContentProvider implements IStructuredContentProvider
+{
+ private static final Logger log = LoggerFactory.getLogger(DBTablesContentProvider.class);
+
+ private static final Object[] EMPTY = new Object[] {};
+
+ private final CodeGenConfig config;
+
+ public DBTablesContentProvider(CodeGenConfig config)
+ {
+ this.config = config;
+ }
+
+ public Object[] getElements(Object arg0)
+ {
+ Connection con = (Connection) arg0;
+ ResultSet tables = null;
+ ArrayList<String> tableNames = new ArrayList<String>();
+ try
+ {
+ DatabaseMetaData dbMeta = con.getMetaData();
+ // Get table metadata
+ tables = dbMeta.getTables(this.config.getDbCatalog(), this.config.getDbSchema(), "%", new String[] { "TABLE", "VIEW" });
+ // Add all tables and views
+ while (tables.next())
+ {
+ String tableName = tables.getString("TABLE_NAME");
+ String tableType = tables.getString("TABLE_TYPE");
+ // Ignore system tables containing a '$' symbol (required for
+ // Oracle!)
+ if (tableName.indexOf('$') >= 0)
+ {
+ DBTablesContentProvider.log.info("Ignoring system table " + tableName);
+ continue;
+ }
+ DBTablesContentProvider.log.info(tableType + ": " + tableName);
+ tableNames.add(tableName);
+ }
+ return tableNames.toArray();
+ }
+ catch (SQLException e)
+ {
+ DBTablesContentProvider.log.info("Error loading meta data: " + e.getMessage());
+ }
+ finally
+ {
+ DBUtil.close(tables, DBTablesContentProvider.log);
+ }
+ return DBTablesContentProvider.EMPTY;
+ }
+
+ public void dispose()
+ {
+ // Nothing to dispose
+ }
+
+ public void inputChanged(Viewer arg0, Object arg1, Object arg2)
+ {
+ // Nothing to do
+ }
+}
+
+class DBTablesLabelProvider implements ILabelProvider
+{
+ public Image getImage(Object arg0)
+ {
+ return null;
+ }
+
+ /**
+ * Returns the name of the file
+ *
+ * @param arg0
+ * the name of the file
+ * @return String
+ */
+ public String getText(Object arg0)
+ {
+ return (String) arg0;
+ }
+
+ public void addListener(ILabelProviderListener arg0)
+ {
+ // Throw it away
+ }
+
+ public void dispose()
+ {
+ // Nothing to dispose
+ }
+
+ public boolean isLabelProperty(Object arg0, String arg1)
+ {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener arg0)
+ {
+ // Ignore
+ }
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/INavigator.java
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/INavigator.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/INavigator.java
new file mode 100644
index 0000000..ca366a2
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/INavigator.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.empire.db.eclipse.ui;
+
+import org.apache.empire.db.eclipse.model.ConfigFile;
+
+public interface INavigator
+{
+ public void addPage(Page page);
+
+ public boolean removePage(Page page);
+
+ public boolean showNextPage();
+
+ public boolean showPreviousPage();
+
+ public boolean hasNextPage();
+
+ public boolean hasPreviousPage();
+
+ public ConfigFile save();
+
+ public void load(ConfigFile config);
+
+ public ConfigFile getCurrentConfig();
+
+ public void setPagesEnabled(boolean enabled);
+
+ public boolean checkRequiredFields();
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/IPage.java
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/IPage.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/IPage.java
new file mode 100644
index 0000000..550d675
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/IPage.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.empire.db.eclipse.ui;
+
+import org.apache.empire.db.eclipse.CodeGenConfig;
+
+public interface IPage
+{
+ public void save(CodeGenConfig config);
+
+ public void load(CodeGenConfig config);
+
+ public boolean checkRequiredFields();
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/MainPage.java
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/MainPage.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/MainPage.java
new file mode 100644
index 0000000..7edeefb
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/MainPage.java
@@ -0,0 +1,305 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.empire.db.eclipse.ui;
+
+import java.sql.Connection;
+
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.db.eclipse.CodeGenConfig;
+import org.apache.empire.db.eclipse.Plugin;
+import org.apache.empire.db.eclipse.util.SWTResourceManager;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class MainPage extends Page
+{
+ private final Text ctlConfigTitle;
+ private final Text ctlServerUrl;
+ private final Text ctlServerPort;
+ private final Text ctlUser;
+ private final Text ctlPassword;
+ private final Text ctlPasswordConfirm;
+ private final Text ctlSID;
+
+ private final Combo ctlExistingConfigs;
+ private final Combo ctlDatabaseType;
+
+ private final Group groupJdbc;
+
+ private final Button btnAdd;
+ private final Button btnSave;
+ private final Button btnDelete;
+ private final Label lblDatabaseType;
+ private final Label lblServerAddress;
+ private final Label lblServerPort;
+ private final Label lblUser;
+ private final Label lblPassword;
+ private final Label lblPasswordConfirm;
+ private final Label lblSid;
+ private final Label lblConfigurationTitle;
+ private final Button btnTestConnection;
+ private final Label lblTestConResult;
+
+ /**
+ * Create the composite.
+ *
+ * @param parent
+ * @param style
+ */
+ public MainPage(Composite parent, int style)
+ {
+ super(parent, style);
+ setLayout(null);
+
+ Label lblExistingConfigurations = new Label(this, SWT.NONE);
+ lblExistingConfigurations.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
+ lblExistingConfigurations.setBounds(6, 31, 154, 15);
+ lblExistingConfigurations.setText(Plugin.getInstance().getMessageService().resolveMessageKey("existingConfigs"));
+
+ this.ctlExistingConfigs = new Combo(this, SWT.READ_ONLY);
+ this.ctlExistingConfigs.setItems(Plugin.getInstance().getConfigFileService().getConfigTitles());
+ this.ctlExistingConfigs.setBounds(165, 27, 248, 23);
+ this.btnAdd = new Button(this, SWT.NONE);
+ this.btnAdd.setBounds(419, 25, 26, 26);
+ this.btnAdd.setImage(SWTResourceManager.getImage(MainPage.class, "/icons/addButton.png"));
+
+ this.lblConfigurationTitle = new Label(this, SWT.NONE);
+ this.lblConfigurationTitle.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
+ this.lblConfigurationTitle.setBounds(6, 62, 154, 15);
+ this.lblConfigurationTitle.setText(Plugin.getInstance().getMessageService().resolveMessageKey("configTitle"));
+
+ this.ctlConfigTitle = new Text(this, SWT.BORDER);
+ this.ctlConfigTitle.setBounds(165, 59, 216, 21);
+
+ this.btnSave = new Button(this, SWT.NONE);
+ this.btnSave.setImage(SWTResourceManager.getImage(MainPage.class, "/icons/save.png"));
+ this.btnSave.setBounds(387, 56, 26, 26);
+
+ this.btnDelete = new Button(this, SWT.NONE);
+ this.btnDelete.setBounds(419, 56, 26, 26);
+ this.btnDelete.setImage(SWTResourceManager.getImage(MainPage.class, "/icons/deleteButton.png"));
+
+ this.groupJdbc = new Group(this, SWT.NONE);
+ this.groupJdbc.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
+ this.groupJdbc.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dbConnection"));
+ this.groupJdbc.setBounds(5, 110, 440, 243);
+
+ this.lblDatabaseType = new Label(this.groupJdbc, SWT.NONE);
+ this.lblDatabaseType.setBounds(10, 21, 154, 15);
+ this.lblDatabaseType.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dbConnectionType"));
+
+ this.ctlDatabaseType = new Combo(this.groupJdbc, SWT.READ_ONLY);
+ this.ctlDatabaseType.setBounds(180, 18, 250, 23);
+ this.ctlDatabaseType.setItems(Plugin.getInstance().getDriverClassNames());
+
+ this.lblServerAddress = new Label(this.groupJdbc, SWT.NONE);
+ this.lblServerAddress.setBounds(10, 49, 154, 17);
+ this.lblServerAddress.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dbServer"));
+
+ this.ctlServerUrl = new Text(this.groupJdbc, SWT.BORDER);
+ this.ctlServerUrl.setBounds(180, 46, 250, 21);
+
+ this.lblServerPort = new Label(this.groupJdbc, SWT.NONE);
+ this.lblServerPort.setBounds(10, 75, 154, 15);
+ this.lblServerPort.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dbPort"));
+
+ this.ctlServerPort = new Text(this.groupJdbc, SWT.BORDER);
+ this.ctlServerPort.setBounds(180, 72, 78, 21);
+
+ this.ctlSID = new Text(this.groupJdbc, SWT.BORDER);
+ this.ctlSID.setBounds(180, 99, 250, 21);
+
+ this.lblSid = new Label(this.groupJdbc, SWT.NONE);
+ this.lblSid.setBounds(10, 102, 154, 15);
+ this.lblSid.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dbSid"));
+
+ this.lblUser = new Label(this.groupJdbc, SWT.NONE);
+ this.lblUser.setBounds(10, 129, 154, 15);
+ this.lblUser.setText(Plugin.getInstance().getMessageService().resolveMessageKey("jdbcUser"));
+
+ this.ctlUser = new Text(this.groupJdbc, SWT.BORDER);
+ this.ctlUser.setBounds(180, 126, 250, 21);
+
+ this.lblPassword = new Label(this.groupJdbc, SWT.NONE);
+ this.lblPassword.setBounds(10, 156, 154, 15);
+ this.lblPassword.setText(Plugin.getInstance().getMessageService().resolveMessageKey("jdbcPassword"));
+
+ this.ctlPassword = new Text(this.groupJdbc, SWT.BORDER | SWT.PASSWORD);
+ this.ctlPassword.setBounds(180, 153, 250, 21);
+
+ this.lblPasswordConfirm = new Label(this.groupJdbc, SWT.NONE);
+ this.lblPasswordConfirm.setBounds(10, 183, 154, 15);
+ this.lblPasswordConfirm.setText(Plugin.getInstance().getMessageService().resolveMessageKey("jdbcPasswordConfirm"));
+
+ this.ctlPasswordConfirm = new Text(this.groupJdbc, SWT.BORDER | SWT.PASSWORD);
+ this.ctlPasswordConfirm.setBounds(180, 180, 250, 21);
+
+ this.btnTestConnection = new Button(this.groupJdbc, SWT.NONE);
+ this.btnTestConnection.setImage(SWTResourceManager.getImage(MainPage.class, "/icons/testConnection.gif"));
+ this.btnTestConnection.setText(Plugin.getInstance().getMessageService().resolveMessageKey("testConnection"));
+ this.btnTestConnection.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.testConnection"));
+ this.btnTestConnection.setBounds(10, 207, 166, 26);
+
+ this.lblTestConResult = new Label(this.groupJdbc, SWT.NONE);
+ this.lblTestConResult.setBounds(180, 213, 250, 15);
+ this.btnTestConnection.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ try
+ {
+ if (!MainPage.this.ctlPassword.getText().equals(MainPage.this.ctlPasswordConfirm.getText()))
+ {
+ MessageDialog.openError(getShell(),
+ Plugin.getInstance().getMessageService().resolveMessageKey("dialog.passwordMismatch"),
+ Plugin.getInstance().getMessageService()
+ .resolveMessageKey("dialog.passwordMismatch.msg"));
+ return;
+ }
+ Connection con = Plugin.getInstance().getJDBCConnection(MainPage.this.ctlDatabaseType.getText(),
+ MainPage.this.ctlServerUrl.getText(),
+ MainPage.this.ctlServerPort.getText(),
+ MainPage.this.ctlSID.getText(),
+ MainPage.this.ctlUser.getText(),
+ MainPage.this.ctlPassword.getText());
+ if (con != null && !con.isClosed())
+ {
+ MainPage.this.lblTestConResult.setText(Plugin.getInstance().getMessageService()
+ .resolveMessageKey("connectionSuccess"));
+ MainPage.this.lblTestConResult.setForeground(new Color(getDisplay(), 0, 255, 0));
+ }
+ else
+ {
+ MainPage.this.lblTestConResult.setText(Plugin.getInstance().getMessageService()
+ .resolveMessageKey("connectionFailed"));
+ MainPage.this.lblTestConResult.setForeground(new Color(getDisplay(), 255, 0, 0));
+ }
+ if (con != null)
+ {
+ con.close();
+ }
+ }
+ catch (Exception e)
+ {
+ MainPage.this.lblTestConResult.setText(Plugin.getInstance().getMessageService()
+ .resolveMessageKey("connectionFailed"));
+ MainPage.this.lblTestConResult.setForeground(new Color(getDisplay(), 255, 0, 0));
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+ }
+
+ public void save(CodeGenConfig config)
+ {
+ config.setConfigTitle(this.ctlConfigTitle.getText());
+ config.setJdbcServer(this.ctlServerUrl.getText());
+ config.setJdbcPort(this.ctlServerPort.getText());
+ config.setJdbcSID(this.ctlSID.getText());
+ config.setJdbcUser(this.ctlUser.getText());
+ config.setJdbcPwd(this.ctlPassword.getText());
+ config.setJdbcType(this.ctlDatabaseType.getText());
+ }
+
+ public void load(CodeGenConfig config)
+ {
+ setControlText(this.ctlConfigTitle, config.getConfigTitle());
+ setControlText(this.ctlServerUrl, config.getJdbcServer());
+ setControlText(this.ctlServerPort, config.getJdbcPort());
+ setControlText(this.ctlSID, config.getJdbcSID());
+ setControlText(this.ctlUser, config.getJdbcUser());
+ setControlText(this.ctlPassword, config.getJdbcPwd());
+ this.ctlDatabaseType.setText(!StringUtils.isEmpty(config.getJdbcType()) ? config.getJdbcType() : " ");
+ this.lblTestConResult.setText(" ");
+ }
+
+ @Override
+ public void setEnabled(boolean enabled)
+ {
+ this.ctlConfigTitle.setEnabled(enabled);
+ this.ctlServerUrl.setEnabled(enabled);
+ this.ctlServerPort.setEnabled(enabled);
+ this.ctlUser.setEnabled(enabled);
+ this.ctlPassword.setEnabled(enabled);
+ this.ctlPasswordConfirm.setEnabled(enabled);
+ this.ctlSID.setEnabled(enabled);
+ this.ctlDatabaseType.setEnabled(enabled);
+ this.btnTestConnection.setEnabled(enabled);
+ }
+
+ public boolean checkRequiredFields()
+ {
+ if (!this.ctlPassword.getText().equals(this.ctlPasswordConfirm.getText()))
+ {
+ MessageDialog.openError(getShell(), Plugin.getInstance().getMessageService().resolveMessageKey("dialog.passwordMismatch"),
+ Plugin.getInstance().getMessageService().resolveMessageKey("dialog.passwordMismatch.msg"));
+ return false;
+ }
+ return checkControlFilled(this.ctlConfigTitle, this.lblConfigurationTitle.getText())
+ && checkControlFilled(this.ctlServerUrl, this.lblServerAddress.getText())
+ && checkControlFilled(this.ctlServerPort, this.lblServerPort.getText())
+ && checkControlFilled(this.ctlUser, this.lblUser.getText())
+ && checkControlFilled(this.ctlPassword, this.lblPassword.getText())
+ && checkControlFilled(this.ctlPasswordConfirm, this.lblPasswordConfirm.getText())
+ && checkControlFilled(this.ctlSID, this.lblSid.getText());
+ }
+
+ public void addExistingConfigsListener(SelectionListener listener)
+ {
+ this.ctlExistingConfigs.addSelectionListener(listener);
+ }
+
+ public void addBtnAddListener(SelectionListener listener)
+ {
+ this.btnAdd.addSelectionListener(listener);
+ }
+
+ public void addBtnSaveListener(SelectionListener listener)
+ {
+ this.btnSave.addSelectionListener(listener);
+ }
+
+ public void addBtnDeleteListener(SelectionListener listener)
+ {
+ this.btnDelete.addSelectionListener(listener);
+ }
+
+ public void setConfigTitleList(String[] configTitleList)
+ {
+ this.ctlExistingConfigs.setItems(configTitleList);
+ }
+
+ @Override
+ protected void checkSubclass()
+ {
+ // Disable the check that prevents subclassing of SWT components
+ }
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/Navigator.java
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/Navigator.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/Navigator.java
new file mode 100644
index 0000000..28534d7
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/Navigator.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.empire.db.eclipse.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.empire.db.eclipse.CodeGenConfig;
+import org.apache.empire.db.eclipse.model.ConfigFile;
+
+public class Navigator implements INavigator
+{
+ private final List<Page> pages;
+
+ private int currentPage;
+
+ private ConfigFile currentConfig;
+
+ public Navigator()
+ {
+ this.pages = new ArrayList<Page>();
+ this.currentPage = 0;
+ }
+
+ public void addPage(Page page)
+ {
+ if (this.pages.size() > 0)
+ {
+ page.setVisible(false);
+ }
+ this.pages.add(page);
+ }
+
+ public boolean removePage(Page page)
+ {
+ if (!this.pages.contains(page))
+ {
+ return false;
+ }
+ return this.pages.remove(page);
+ }
+
+ public boolean showNextPage()
+ {
+ if (!hasNextPage())
+ {
+ return false;
+ }
+ this.pages.get(this.currentPage).setVisible(false);
+ this.currentPage++;
+ this.pages.get(this.currentPage).setVisible(true);
+ return true;
+ }
+
+ public boolean showPreviousPage()
+ {
+ if (!hasPreviousPage())
+ {
+ return false;
+ }
+ this.pages.get(this.currentPage).setVisible(false);
+ this.currentPage--;
+ this.pages.get(this.currentPage).setVisible(true);
+ return true;
+ }
+
+ public boolean hasNextPage()
+ {
+ return this.currentPage < this.pages.size() - 1;
+ }
+
+ public boolean hasPreviousPage()
+ {
+ return this.currentPage > 0;
+ }
+
+ public ConfigFile save()
+ {
+ if (this.currentConfig == null)
+ {
+ return null;
+ }
+ for (Page page : this.pages)
+ {
+ page.save(this.currentConfig.getCodeGenConfig());
+ }
+ return this.currentConfig;
+ }
+
+ public void load(ConfigFile config)
+ {
+ setCurrentConfig(config);
+ for (Page page : this.pages)
+ {
+ page.load(config != null ? config.getCodeGenConfig() : new CodeGenConfig());
+ }
+ }
+
+ public ConfigFile getCurrentConfig()
+ {
+ return this.currentConfig;
+ }
+
+ private void setCurrentConfig(ConfigFile currentConfig)
+ {
+ setPagesEnabled(currentConfig != null);
+ this.currentConfig = currentConfig;
+ }
+
+ public void setPagesEnabled(boolean enabled)
+ {
+ for (Page page : this.pages)
+ {
+ page.setEnabled(enabled);
+ }
+ }
+
+ public boolean checkRequiredFields()
+ {
+ for (Page page : this.pages)
+ {
+ if (!page.checkRequiredFields())
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/Page.java
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/Page.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/Page.java
new file mode 100644
index 0000000..badca1a
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/Page.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.empire.db.eclipse.ui;
+
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.db.eclipse.Plugin;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+
+public abstract class Page extends Composite implements IPage
+{
+ public Page(Composite parent, int style)
+ {
+ super(parent, style);
+ this.setSize(450, 500);
+ this.setBounds(10, 0, 450, 500);
+ }
+
+ protected void setControlText(Text ctlText, String value)
+ {
+ ctlText.setText(value != null ? value : "");
+ }
+
+ protected boolean checkControlFilled(Text ctlText, String field)
+ {
+ if (StringUtils.isNotEmpty(ctlText.getText()))
+ {
+ return true;
+ }
+ MessageDialog.openError(getShell(), Plugin.getInstance().getMessageService().resolveMessageKey("dialog.errorFieldRequired"),
+ Plugin.getInstance().getMessageService().resolveMessageKey("dialog.errorFieldRequired.msg", field));
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/SchemaOptionsPage.java
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/SchemaOptionsPage.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/SchemaOptionsPage.java
new file mode 100644
index 0000000..69ce3c3
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/ui/SchemaOptionsPage.java
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.empire.db.eclipse.ui;
+
+import org.apache.empire.db.eclipse.CodeGenConfig;
+import org.apache.empire.db.eclipse.Plugin;
+import org.apache.empire.db.eclipse.util.SWTResourceManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class SchemaOptionsPage extends Page
+{
+ private final Text ctlDbCatalog;
+ private final Text ctlDbSchema;
+ private final Text ctlTimestampCol;
+ private final Text ctlDbTablePattern;
+
+ private final Text ctlTargetFolder;
+ private final Text ctlPackageName;
+ private final Text ctlTablePackageName;
+ private final Text ctlViewPackageName;
+ private final Text ctlRecordPackageName;
+
+ private final Group groupRequired;
+
+ private final Label lblTargetFolder;
+ private final Label lblPackageName;
+ private final Label lblTablePackageName;
+ private final Label lblViewPackageName;
+ private final Label lblRecordPackageName;
+ private final Button btnDirectoryDialog;
+ private final Button btnOpenTableDialog;
+
+ public SchemaOptionsPage(Composite parent, int style)
+ {
+ super(parent, style);
+ setLayout(null);
+
+ Group grpSchemaOptions = new Group(this, SWT.NONE);
+ grpSchemaOptions.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
+ grpSchemaOptions.setText(Plugin.getInstance().getMessageService().resolveMessageKey("schemaOptions"));
+ grpSchemaOptions.setBounds(5, 30, 440, 128);
+
+ Label lblDbCatalog = new Label(grpSchemaOptions, SWT.NONE);
+ lblDbCatalog.setBounds(10, 23, 154, 17);
+ lblDbCatalog.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dbCatalog"));
+ lblDbCatalog.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.dbCatalog"));
+
+ this.ctlDbCatalog = new Text(grpSchemaOptions, SWT.BORDER);
+ this.ctlDbCatalog.setBounds(180, 20, 250, 21);
+ this.ctlDbCatalog.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.dbCatalog"));
+
+ Label lblDbSchema = new Label(grpSchemaOptions, SWT.NONE);
+ lblDbSchema.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dbSchema"));
+ lblDbSchema.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.dbSchema"));
+ lblDbSchema.setBounds(10, 49, 154, 17);
+
+ this.ctlDbSchema = new Text(grpSchemaOptions, SWT.BORDER);
+ this.ctlDbSchema.setBounds(180, 46, 250, 21);
+ this.ctlDbSchema.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.dbSchema"));
+
+ Label lblDbTablePattern = new Label(grpSchemaOptions, SWT.NONE);
+ lblDbTablePattern.setText(Plugin.getInstance().getMessageService().resolveMessageKey("dbTablePattern"));
+ lblDbTablePattern.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.dbTablePattern"));
+ lblDbTablePattern.setBounds(10, 75, 154, 17);
+
+ this.ctlDbTablePattern = new Text(grpSchemaOptions, SWT.BORDER);
+ this.ctlDbTablePattern.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.dbTablePattern"));
+ this.getCtlDbTablePattern().setBounds(180, 72, 218, 21);
+
+ Label lblTimestampCol = new Label(grpSchemaOptions, SWT.NONE);
+ lblTimestampCol.setText(Plugin.getInstance().getMessageService().resolveMessageKey("timestampColumn"));
+ lblTimestampCol.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.timestampColumn"));
+ lblTimestampCol.setBounds(10, 98, 154, 17);
+
+ this.ctlTimestampCol = new Text(grpSchemaOptions, SWT.BORDER);
+ this.ctlTimestampCol.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.timestampColumn"));
+ this.ctlTimestampCol.setBounds(180, 98, 250, 21);
+
+ this.btnOpenTableDialog = new Button(grpSchemaOptions, SWT.NONE);
+ this.btnOpenTableDialog.setBounds(404, 69, 26, 26);
+ this.btnOpenTableDialog.setImage(SWTResourceManager.getImage(SchemaOptionsPage.class, "/icons/db_element.gif"));
+
+ this.groupRequired = new Group(this, SWT.NONE);
+ this.groupRequired.setText(Plugin.getInstance().getMessageService().resolveMessageKey("requiredParams"));
+ this.groupRequired.setFont(SWTResourceManager.getFont("Segoe UI", 10, SWT.BOLD));
+ this.groupRequired.setBounds(5, 180, 440, 149);
+
+ this.lblTargetFolder = new Label(this.groupRequired, SWT.NONE);
+ this.lblTargetFolder.setBounds(10, 18, 154, 15);
+ this.lblTargetFolder.setText(Plugin.getInstance().getMessageService().resolveMessageKey("targetFolder"));
+ this.lblTargetFolder.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.targetFolder"));
+
+ this.ctlTargetFolder = new Text(this.groupRequired, SWT.BORDER);
+ this.ctlTargetFolder.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.targetFolder"));
+ this.ctlTargetFolder.setBounds(180, 15, 218, 21);
+
+
+ this.btnDirectoryDialog = new Button(this.groupRequired, SWT.NONE);
+ this.btnDirectoryDialog.setImage(SWTResourceManager.getImage(SchemaOptionsPage.class, "/icons/folder.gif"));
+ this.btnDirectoryDialog.setBounds(404, 12, 26, 26);
+ this.btnDirectoryDialog.addSelectionListener(new SelectionListener()
+ {
+ public void widgetSelected(SelectionEvent arg0)
+ {
+ DirectoryDialog directoryDialog = new DirectoryDialog(getShell());
+ directoryDialog.setFilterPath(SchemaOptionsPage.this.ctlTargetFolder.getText());
+ String path = directoryDialog.open();
+ if (path != null)
+ {
+ SchemaOptionsPage.this.ctlTargetFolder.setText(path);
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0)
+ {
+ }
+ });
+
+ this.lblPackageName = new Label(this.groupRequired, SWT.NONE);
+ this.lblPackageName.setBounds(10, 45, 154, 15);
+ this.lblPackageName.setText(Plugin.getInstance().getMessageService().resolveMessageKey("packageName"));
+ this.lblPackageName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.packageName"));
+
+ this.ctlPackageName = new Text(this.groupRequired, SWT.BORDER);
+ this.ctlPackageName.setBounds(180, 42, 250, 21);
+ this.ctlPackageName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.packageName"));
+
+ this.lblTablePackageName = new Label(this.groupRequired, SWT.NONE);
+ this.lblTablePackageName.setBounds(10, 72, 154, 15);
+ this.lblTablePackageName.setText(Plugin.getInstance().getMessageService().resolveMessageKey("tablePackageName"));
+ this.lblTablePackageName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tablePackageName"));
+
+ this.ctlTablePackageName = new Text(this.groupRequired, SWT.BORDER);
+ this.ctlTablePackageName.setBounds(180, 69, 250, 21);
+ this.ctlTablePackageName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.tablePackageName"));
+
+ this.lblViewPackageName = new Label(this.groupRequired, SWT.NONE);
+ this.lblViewPackageName.setBounds(10, 99, 154, 15);
+ this.lblViewPackageName.setText(Plugin.getInstance().getMessageService().resolveMessageKey("viewPackageName"));
+ this.lblViewPackageName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewPackageName"));
+
+ this.ctlViewPackageName = new Text(this.groupRequired, SWT.BORDER);
+ this.ctlViewPackageName.setBounds(180, 96, 250, 21);
+ this.ctlViewPackageName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.viewPackageName"));
+
+ this.lblRecordPackageName = new Label(this.groupRequired, SWT.NONE);
+ this.lblRecordPackageName.setBounds(10, 126, 154, 15);
+ this.lblRecordPackageName.setText(Plugin.getInstance().getMessageService().resolveMessageKey("recordPackageName"));
+ this.lblRecordPackageName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.recordPackageName"));
+
+ this.ctlRecordPackageName = new Text(this.groupRequired, SWT.BORDER);
+ this.ctlRecordPackageName.setBounds(180, 123, 250, 21);
+ this.ctlRecordPackageName.setToolTipText(Plugin.getInstance().getMessageService().resolveMessageKey("tooltip.recordPackageName"));
+ }
+
+ public void save(CodeGenConfig config)
+ {
+ config.setDbCatalog(this.ctlDbCatalog.getText());
+ config.setDbSchema(this.ctlDbSchema.getText());
+ config.setTimestampColumn(this.ctlTimestampCol.getText());
+ config.setDbTablePattern(this.getCtlDbTablePattern().getText());
+ config.setTargetFolder(this.ctlTargetFolder.getText());
+ config.setPackageName(this.ctlPackageName.getText());
+ config.setTablePackageName(this.ctlTablePackageName.getText());
+ config.setViewPackageName(this.ctlViewPackageName.getText());
+ config.setRecordPackageName(this.ctlRecordPackageName.getText());
+ }
+
+ public void load(CodeGenConfig config)
+ {
+ setControlText(this.ctlDbCatalog, config.getDbCatalog());
+ setControlText(this.ctlDbSchema, config.getDbSchema());
+ setControlText(this.ctlTimestampCol, config.getTimestampColumn());
+ setControlText(this.getCtlDbTablePattern(), config.getDbTablePattern());
+ setControlText(this.ctlTargetFolder, config.getTargetFolder());
+ setControlText(this.ctlPackageName, config.getPackageName());
+ setControlText(this.ctlTablePackageName, config.getTablePackageName());
+ setControlText(this.ctlViewPackageName, config.getViewPackageName());
+ setControlText(this.ctlRecordPackageName, config.getRecordPackageName());
+
+ }
+
+ @Override
+ public void setEnabled(boolean enabled)
+ {
+ this.ctlDbCatalog.setEnabled(enabled);
+ this.ctlDbSchema.setEnabled(enabled);
+ this.ctlTimestampCol.setEnabled(enabled);
+ this.getCtlDbTablePattern().setEnabled(enabled);
+ this.ctlTargetFolder.setEnabled(enabled);
+ this.ctlPackageName.setEnabled(enabled);
+ this.ctlTablePackageName.setEnabled(enabled);
+ this.ctlViewPackageName.setEnabled(enabled);
+ this.ctlRecordPackageName.setEnabled(enabled);
+ this.btnDirectoryDialog.setEnabled(enabled);
+ this.btnOpenTableDialog.setEnabled(enabled);
+ }
+
+ public boolean checkRequiredFields()
+ {
+ return checkControlFilled(this.ctlTargetFolder, this.lblTargetFolder.getText())
+ && checkControlFilled(this.ctlPackageName, this.lblPackageName.getText())
+ && checkControlFilled(this.ctlTablePackageName, this.lblTablePackageName.getText())
+ && checkControlFilled(this.ctlViewPackageName, this.lblViewPackageName.getText())
+ && checkControlFilled(this.ctlRecordPackageName, this.lblRecordPackageName.getText());
+ }
+
+ public void addBtnTableDialogListener(SelectionListener selectionListener)
+ {
+ this.btnOpenTableDialog.addSelectionListener(selectionListener);
+ }
+
+ public Text getCtlDbTablePattern()
+ {
+ return this.ctlDbTablePattern;
+ }
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/util/SWTResourceManager.java
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/util/SWTResourceManager.java b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/util/SWTResourceManager.java
new file mode 100644
index 0000000..8217af2
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/java/org/apache/empire/db/eclipse/util/SWTResourceManager.java
@@ -0,0 +1,455 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.empire.db.eclipse.util;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc.
+ * <p>
+ * !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the
+ * operating system resources managed by cached objects when those objects and OS resources are no longer
+ * needed (e.g. on application shutdown)
+ * <p>
+ * This class may be freely distributed as part of any application or plugin.
+ * <p>
+ * @author scheglov_ke
+ * @author Dan Rubel
+ */
+public class SWTResourceManager {
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Color
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>();
+ /**
+ * Returns the system {@link Color} matching the specific ID.
+ *
+ * @param systemColorID
+ * the ID value for the color
+ * @return the system {@link Color} matching the specific ID
+ */
+ public static Color getColor(int systemColorID) {
+ Display display = Display.getCurrent();
+ return display.getSystemColor(systemColorID);
+ }
+ /**
+ * Returns a {@link Color} given its red, green and blue component values.
+ *
+ * @param r
+ * the red component of the color
+ * @param g
+ * the green component of the color
+ * @param b
+ * the blue component of the color
+ * @return the {@link Color} matching the given red, green and blue component values
+ */
+ public static Color getColor(int r, int g, int b) {
+ return getColor(new RGB(r, g, b));
+ }
+ /**
+ * Returns a {@link Color} given its RGB value.
+ *
+ * @param rgb
+ * the {@link RGB} value of the color
+ * @return the {@link Color} matching the RGB value
+ */
+ public static Color getColor(RGB rgb) {
+ Color color = m_colorMap.get(rgb);
+ if (color == null) {
+ Display display = Display.getCurrent();
+ color = new Color(display, rgb);
+ m_colorMap.put(rgb, color);
+ }
+ return color;
+ }
+ /**
+ * Dispose of all the cached {@link Color}'s.
+ */
+ public static void disposeColors() {
+ for (Color color : m_colorMap.values()) {
+ color.dispose();
+ }
+ m_colorMap.clear();
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Image
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps image paths to images.
+ */
+ private static Map<String, Image> m_imageMap = new HashMap<String, Image>();
+ /**
+ * Returns an {@link Image} encoded by the specified {@link InputStream}.
+ *
+ * @param stream
+ * the {@link InputStream} encoding the image data
+ * @return the {@link Image} encoded by the specified input stream
+ */
+ protected static Image getImage(InputStream stream) throws IOException {
+ try {
+ Display display = Display.getCurrent();
+ ImageData data = new ImageData(stream);
+ if (data.transparentPixel > 0) {
+ return new Image(display, data, data.getTransparencyMask());
+ }
+ return new Image(display, data);
+ } finally {
+ stream.close();
+ }
+ }
+ /**
+ * Returns an {@link Image} stored in the file at the specified path.
+ *
+ * @param path
+ * the path to the image file
+ * @return the {@link Image} stored in the file at the specified path
+ */
+ public static Image getImage(String path) {
+ Image image = m_imageMap.get(path);
+ if (image == null) {
+ try {
+ image = getImage(new FileInputStream(path));
+ m_imageMap.put(path, image);
+ } catch (Exception e) {
+ image = getMissingImage();
+ m_imageMap.put(path, image);
+ }
+ }
+ return image;
+ }
+ /**
+ * Returns an {@link Image} stored in the file at the specified path relative to the specified class.
+ *
+ * @param clazz
+ * the {@link Class} relative to which to find the image
+ * @param path
+ * the path to the image file, if starts with <code>'/'</code>
+ * @return the {@link Image} stored in the file at the specified path
+ */
+ public static Image getImage(Class<?> clazz, String path) {
+ String key = clazz.getName() + '|' + path;
+ Image image = m_imageMap.get(key);
+ if (image == null) {
+ try {
+ image = getImage(clazz.getResourceAsStream(path));
+ m_imageMap.put(key, image);
+ } catch (Exception e) {
+ image = getMissingImage();
+ m_imageMap.put(key, image);
+ }
+ }
+ return image;
+ }
+ private static final int MISSING_IMAGE_SIZE = 10;
+ /**
+ * @return the small {@link Image} that can be used as placeholder for missing image.
+ */
+ private static Image getMissingImage() {
+ Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
+ //
+ GC gc = new GC(image);
+ gc.setBackground(getColor(SWT.COLOR_RED));
+ gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
+ gc.dispose();
+ //
+ return image;
+ }
+ /**
+ * Style constant for placing decorator image in top left corner of base image.
+ */
+ public static final int TOP_LEFT = 1;
+ /**
+ * Style constant for placing decorator image in top right corner of base image.
+ */
+ public static final int TOP_RIGHT = 2;
+ /**
+ * Style constant for placing decorator image in bottom left corner of base image.
+ */
+ public static final int BOTTOM_LEFT = 3;
+ /**
+ * Style constant for placing decorator image in bottom right corner of base image.
+ */
+ public static final int BOTTOM_RIGHT = 4;
+ /**
+ * Internal value.
+ */
+ protected static final int LAST_CORNER_KEY = 5;
+ /**
+ * Maps images to decorated images.
+ */
+ @SuppressWarnings("unchecked")
+ private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage
+ * the base {@link Image} that should be decorated
+ * @param decorator
+ * the {@link Image} to decorate the base image
+ * @return {@link Image} The resulting decorated image
+ */
+ public static Image decorateImage(Image baseImage, Image decorator) {
+ return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
+ }
+ /**
+ * Returns an {@link Image} composed of a base image decorated by another image.
+ *
+ * @param baseImage
+ * the base {@link Image} that should be decorated
+ * @param decorator
+ * the {@link Image} to decorate the base image
+ * @param corner
+ * the corner to place decorator image
+ * @return the resulting decorated {@link Image}
+ */
+ public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
+ if (corner <= 0 || corner >= LAST_CORNER_KEY) {
+ throw new IllegalArgumentException("Wrong decorate corner");
+ }
+ Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
+ if (cornerDecoratedImageMap == null) {
+ cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
+ m_decoratedImageMap[corner] = cornerDecoratedImageMap;
+ }
+ Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
+ if (decoratedMap == null) {
+ decoratedMap = new HashMap<Image, Image>();
+ cornerDecoratedImageMap.put(baseImage, decoratedMap);
+ }
+ //
+ Image result = decoratedMap.get(decorator);
+ if (result == null) {
+ Rectangle bib = baseImage.getBounds();
+ Rectangle dib = decorator.getBounds();
+ //
+ result = new Image(Display.getCurrent(), bib.width, bib.height);
+ //
+ GC gc = new GC(result);
+ gc.drawImage(baseImage, 0, 0);
+ if (corner == TOP_LEFT) {
+ gc.drawImage(decorator, 0, 0);
+ } else if (corner == TOP_RIGHT) {
+ gc.drawImage(decorator, bib.width - dib.width, 0);
+ } else if (corner == BOTTOM_LEFT) {
+ gc.drawImage(decorator, 0, bib.height - dib.height);
+ } else if (corner == BOTTOM_RIGHT) {
+ gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height);
+ }
+ gc.dispose();
+ //
+ decoratedMap.put(decorator, result);
+ }
+ return result;
+ }
+ /**
+ * Dispose all of the cached {@link Image}'s.
+ */
+ public static void disposeImages() {
+ // dispose loaded images
+ {
+ for (Image image : m_imageMap.values()) {
+ image.dispose();
+ }
+ m_imageMap.clear();
+ }
+ // dispose decorated images
+ for (int i = 0; i < m_decoratedImageMap.length; i++) {
+ Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
+ if (cornerDecoratedImageMap != null) {
+ for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) {
+ for (Image image : decoratedMap.values()) {
+ image.dispose();
+ }
+ decoratedMap.clear();
+ }
+ cornerDecoratedImageMap.clear();
+ }
+ }
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Font
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps font names to fonts.
+ */
+ private static Map<String, Font> m_fontMap = new HashMap<String, Font>();
+ /**
+ * Maps fonts to their bold versions.
+ */
+ private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>();
+ /**
+ * Returns a {@link Font} based on its name, height and style.
+ *
+ * @param name
+ * the name of the font
+ * @param height
+ * the height of the font
+ * @param style
+ * the style of the font
+ * @return {@link Font} The font matching the name, height and style
+ */
+ public static Font getFont(String name, int height, int style) {
+ return getFont(name, height, style, false, false);
+ }
+ /**
+ * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline
+ * flags are also supported.
+ *
+ * @param name
+ * the name of the font
+ * @param size
+ * the size of the font
+ * @param style
+ * the style of the font
+ * @param strikeout
+ * the strikeout flag (warning: Windows only)
+ * @param underline
+ * the underline flag (warning: Windows only)
+ * @return {@link Font} The font matching the name, height, style, strikeout and underline
+ */
+ public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
+ String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
+ Font font = m_fontMap.get(fontName);
+ if (font == null) {
+ FontData fontData = new FontData(name, size, style);
+ if (strikeout || underline) {
+ try {
+ Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
+ Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
+ if (logFont != null && logFontClass != null) {
+ if (strikeout) {
+ logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
+ }
+ if (underline) {
+ logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
+ }
+ }
+ } catch (Throwable e) {
+ System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ font = new Font(Display.getCurrent(), fontData);
+ m_fontMap.put(fontName, font);
+ }
+ return font;
+ }
+ /**
+ * Returns a bold version of the given {@link Font}.
+ *
+ * @param baseFont
+ * the {@link Font} for which a bold version is desired
+ * @return the bold version of the given {@link Font}
+ */
+ public static Font getBoldFont(Font baseFont) {
+ Font font = m_fontToBoldFontMap.get(baseFont);
+ if (font == null) {
+ FontData fontDatas[] = baseFont.getFontData();
+ FontData data = fontDatas[0];
+ font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
+ m_fontToBoldFontMap.put(baseFont, font);
+ }
+ return font;
+ }
+ /**
+ * Dispose all of the cached {@link Font}'s.
+ */
+ public static void disposeFonts() {
+ // clear fonts
+ for (Font font : m_fontMap.values()) {
+ font.dispose();
+ }
+ m_fontMap.clear();
+ // clear bold fonts
+ for (Font font : m_fontToBoldFontMap.values()) {
+ font.dispose();
+ }
+ m_fontToBoldFontMap.clear();
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // Cursor
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Maps IDs to cursors.
+ */
+ private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>();
+ /**
+ * Returns the system cursor matching the specific ID.
+ *
+ * @param id
+ * int The ID value for the cursor
+ * @return Cursor The system cursor matching the specific ID
+ */
+ public static Cursor getCursor(int id) {
+ Integer key = Integer.valueOf(id);
+ Cursor cursor = m_idToCursorMap.get(key);
+ if (cursor == null) {
+ cursor = new Cursor(Display.getDefault(), id);
+ m_idToCursorMap.put(key, cursor);
+ }
+ return cursor;
+ }
+ /**
+ * Dispose all of the cached cursors.
+ */
+ public static void disposeCursors() {
+ for (Cursor cursor : m_idToCursorMap.values()) {
+ cursor.dispose();
+ }
+ m_idToCursorMap.clear();
+ }
+ ////////////////////////////////////////////////////////////////////////////
+ //
+ // General
+ //
+ ////////////////////////////////////////////////////////////////////////////
+ /**
+ * Dispose of cached objects and their underlying OS resources. This should only be called when the cached
+ * objects are no longer needed (e.g. on application shutdown).
+ */
+ public static void dispose() {
+ disposeColors();
+ disposeImages();
+ disposeFonts();
+ disposeCursors();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/resources/defaultConfig.xml
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/resources/defaultConfig.xml b/empire-db-eclipse-codegen/src/main/resources/defaultConfig.xml
new file mode 100644
index 0000000..33c77bf
--- /dev/null
+++ b/empire-db-eclipse-codegen/src/main/resources/defaultConfig.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<config>
+ <properties>
+ <!-- provider name must match the property-section containing the connection data -->
+ <jdbcClass></jdbcClass>
+ <jdbcURL></jdbcURL>
+ <jdbcServer></jdbcServer>
+ <jdbcPort></jdbcPort>
+ <jdbcSID></jdbcSID>
+ <jdbcUser></jdbcUser>
+ <jdbcPwd></jdbcPwd>
+
+ <!-- Schema options -->
+ <dbCatalog></dbCatalog>
+ <dbSchema></dbSchema>
+ <dbTablePattern></dbTablePattern>
+ <timestampColumn>CREATIONDATE</timestampColumn>
+
+ <!-- generation options -->
+ <targetFolder></targetFolder>
+ <packageName>org.apache.empire.db</packageName>
+ <tablePackageName>org.apache.empire.db.table</tablePackageName>
+ <viewPackageName>org.apache.empire.db.view</viewPackageName>
+ <recordPackageName>org.apache.empire.db.record</recordPackageName>
+ <dbClassName>EmpireDB</dbClassName>
+ <tableBaseName>BaseTable</tableBaseName>
+ <viewBaseName>BaseView</viewBaseName>
+ <recordBaseName>BaseRecord</recordBaseName>
+ <tableNamePrefix></tableNamePrefix>
+ <tableClassPrefix>T_</tableClassPrefix>
+ <tableClassSuffix></tableClassSuffix>
+ <viewNamePrefix></viewNamePrefix>
+ <viewClassPrefix>V_</viewClassPrefix>
+ <viewClassSuffix></viewClassSuffix>
+ <columnNamePrefix></columnNamePrefix>
+ <nestTables>true</nestTables>
+ <nestViews>false</nestViews>
+ <createRecordProperties>true</createRecordProperties>
+ <preserverCharacterCase>false</preserverCharacterCase>
+ <preserveRelationNames>false</preserveRelationNames>
+ </properties>
+
+ <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <appender name="default" class="org.apache.log4j.ConsoleAppender">
+ <!-- layout class="org.apache.log4j.TTCCLayout"/ -->
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- param name="ConversionPattern" value="NSB(%c) %-5p %m at %l%n"/ -->
+ <param name="ConversionPattern" value="%-5p [%d{yyyy/MM/dd HH:mm}]: %m at %l %n"/>
+ </layout>
+ </appender>
+
+ <!-- log detail configuration -->
+ <logger name="org.apache.empire.commons" additivity="false">
+ <level value="warn"/>
+ <appender-ref ref="default"/>
+ </logger>
+
+ <root>
+ <priority value="info"/>
+ <appender-ref ref="default"/>
+ </root>
+
+ </log4j:configuration>
+
+</config>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/resources/icons/addButton.png
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/resources/icons/addButton.png b/empire-db-eclipse-codegen/src/main/resources/icons/addButton.png
new file mode 100644
index 0000000..c6aeae4
Binary files /dev/null and b/empire-db-eclipse-codegen/src/main/resources/icons/addButton.png differ
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/resources/icons/check_all.gif
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/resources/icons/check_all.gif b/empire-db-eclipse-codegen/src/main/resources/icons/check_all.gif
new file mode 100644
index 0000000..4370bf1
Binary files /dev/null and b/empire-db-eclipse-codegen/src/main/resources/icons/check_all.gif differ
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/resources/icons/db_element.gif
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/resources/icons/db_element.gif b/empire-db-eclipse-codegen/src/main/resources/icons/db_element.gif
new file mode 100644
index 0000000..1d459ce
Binary files /dev/null and b/empire-db-eclipse-codegen/src/main/resources/icons/db_element.gif differ
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/resources/icons/deleteButton.png
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/resources/icons/deleteButton.png b/empire-db-eclipse-codegen/src/main/resources/icons/deleteButton.png
new file mode 100644
index 0000000..5f00385
Binary files /dev/null and b/empire-db-eclipse-codegen/src/main/resources/icons/deleteButton.png differ
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/resources/icons/empire-db-logo.gif
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/resources/icons/empire-db-logo.gif b/empire-db-eclipse-codegen/src/main/resources/icons/empire-db-logo.gif
new file mode 100644
index 0000000..3d60d76
Binary files /dev/null and b/empire-db-eclipse-codegen/src/main/resources/icons/empire-db-logo.gif differ
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/resources/icons/empire_db_icon.png
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/resources/icons/empire_db_icon.png b/empire-db-eclipse-codegen/src/main/resources/icons/empire_db_icon.png
new file mode 100644
index 0000000..30ac6e9
Binary files /dev/null and b/empire-db-eclipse-codegen/src/main/resources/icons/empire_db_icon.png differ
http://git-wip-us.apache.org/repos/asf/empire-db/blob/83302f08/empire-db-eclipse-codegen/src/main/resources/icons/folder.gif
----------------------------------------------------------------------
diff --git a/empire-db-eclipse-codegen/src/main/resources/icons/folder.gif b/empire-db-eclipse-codegen/src/main/resources/icons/folder.gif
new file mode 100644
index 0000000..42e027c
Binary files /dev/null and b/empire-db-eclipse-codegen/src/main/resources/icons/folder.gif differ