Remove ui.swing dependency. Added a text/console setup UI.
This commit is contained in:
parent
de108fd469
commit
66a94ab919
|
@ -6,8 +6,7 @@ Bundle-Version: 1.0.0.qualifier
|
|||
Bundle-ClassPath: install.jar,
|
||||
ant-contrib-1.0b3.jar
|
||||
Export-Package: org.compiere.install
|
||||
Require-Bundle: org.adempiere.base;bundle-version="1.0.0",
|
||||
org.adempiere.ui.swing;bundle-version="1.0.0"
|
||||
Require-Bundle: org.adempiere.base;bundle-version="1.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Import-Package: javax.mail;version="1.4.1",
|
||||
javax.mail.internet;version="1.4.1",
|
||||
|
|
|
@ -2,11 +2,22 @@
|
|||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
id="org.adempiere.Install"
|
||||
id="org.adempiere.install.application"
|
||||
point="org.eclipse.core.runtime.applications">
|
||||
<application>
|
||||
<run class="org.compiere.install.Application" />
|
||||
</application>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
id="org.adempiere.install.console.application"
|
||||
point="org.eclipse.core.runtime.applications">
|
||||
<application
|
||||
cardinality="singleton-global"
|
||||
thread="main"
|
||||
visible="true">
|
||||
<run
|
||||
class="org.compiere.install.console.Application">
|
||||
</run>
|
||||
</application>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -20,7 +20,8 @@ import java.sql.Connection;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.compiere.swing.CCheckBox;
|
||||
import javax.swing.JCheckBox;
|
||||
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
|
||||
|
@ -119,7 +120,7 @@ public abstract class Config
|
|||
* @param critical true if critical
|
||||
* @param errorMsg error Message
|
||||
*/
|
||||
void signalOK (CCheckBox cb, String resString,
|
||||
void signalOK (JCheckBox cb, String resString,
|
||||
boolean pass, boolean critical, String errorMsg)
|
||||
{
|
||||
p_data.p_panel.signalOK(cb, resString, pass, critical, errorMsg);
|
||||
|
|
|
@ -175,7 +175,7 @@ public class ConfigurationData
|
|||
public static final String ADEMPIERE_WEBSTORES = "ADEMPIERE_WEBSTORES";
|
||||
|
||||
|
||||
private void updateProperty(String property, String value) {
|
||||
public void updateProperty(String property, String value) {
|
||||
if (value == null) value = "";
|
||||
String currentValue = (String)p_properties.get(property);
|
||||
if (currentValue == null)
|
||||
|
@ -183,6 +183,11 @@ public class ConfigurationData
|
|||
else if (!currentValue.equals(value))
|
||||
p_properties.put(property, value);
|
||||
}
|
||||
|
||||
public String getProperty(String property)
|
||||
{
|
||||
return p_properties.getProperty(property);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Configuration Data
|
||||
|
@ -291,7 +296,7 @@ public class ConfigurationData
|
|||
// Database Server
|
||||
initDatabase("");
|
||||
String connectionName = getDatabaseDiscovered();
|
||||
if (connectionName != null) {
|
||||
if (connectionName != null && connectionName.trim().length() > 0) {
|
||||
setDatabaseName(resolveDatabaseName(connectionName));
|
||||
}
|
||||
setDatabaseSystemPassword("");
|
||||
|
@ -402,7 +407,7 @@ public class ConfigurationData
|
|||
* Test Adempiere and set AdempiereHome
|
||||
* @return error message or null if OK
|
||||
*/
|
||||
private String testAdempiere()
|
||||
public String testAdempiere()
|
||||
{
|
||||
// Adempiere Home
|
||||
m_adempiereHome = new File (getAdempiereHome());
|
||||
|
@ -460,15 +465,13 @@ public class ConfigurationData
|
|||
* Test (optional) Mail
|
||||
* @return error message or null, if OK
|
||||
*/
|
||||
private String testMail()
|
||||
public String testMail()
|
||||
{
|
||||
// Mail Server
|
||||
String server = p_panel != null
|
||||
? p_panel.fMailServer.getText()
|
||||
: (String)p_properties.get(ADEMPIERE_MAIL_SERVER);
|
||||
boolean pass = server != null && server.length() > 0
|
||||
&& server.toLowerCase().indexOf("localhost") == -1
|
||||
&& !server.equals("127.0.0.1");
|
||||
boolean pass = server != null && server.length() > 0;
|
||||
String error = "Error Mail Server = " + server;
|
||||
InetAddress mailServer = null;
|
||||
try
|
||||
|
@ -898,9 +901,18 @@ public class ConfigurationData
|
|||
*/
|
||||
public String getKeyStore ()
|
||||
{
|
||||
char[] pw = p_panel.fKeyStore.getPassword();
|
||||
if (pw != null)
|
||||
return new String(pw);
|
||||
if (p_panel != null)
|
||||
{
|
||||
char[] pw = p_panel.fKeyStore.getPassword();
|
||||
if (pw != null)
|
||||
return new String(pw);
|
||||
}
|
||||
else
|
||||
{
|
||||
String pw = getProperty(ADEMPIERE_KEYSTOREPASS);
|
||||
if (pw != null)
|
||||
return pw;
|
||||
}
|
||||
return "";
|
||||
} // getKeyStore
|
||||
|
||||
|
@ -925,17 +937,15 @@ public class ConfigurationData
|
|||
private static String JAVATYPE_SUN = "sun";
|
||||
/** Apple VM */
|
||||
private static String JAVATYPE_MAC = "mac";
|
||||
/** IBM VM */
|
||||
private static String JAVATYPE_IBM = "<ibm>";
|
||||
/** Open JDK */
|
||||
private static String JAVATYPE_OPENJDK = "OpenJDK";
|
||||
/** Java VM Types */
|
||||
static String[] JAVATYPE = new String[]
|
||||
{JAVATYPE_SUN, JAVATYPE_OPENJDK, JAVATYPE_MAC, JAVATYPE_IBM};
|
||||
public static String[] JAVATYPE = new String[]
|
||||
{JAVATYPE_SUN, JAVATYPE_OPENJDK, JAVATYPE_MAC};
|
||||
|
||||
/** Virtual machine Configurations */
|
||||
private Config[] m_javaConfig = new Config[]
|
||||
{new ConfigVMSun(this), new ConfigVMOpenJDK(this), new ConfigVMMac(this), null};
|
||||
{new ConfigVMSun(this), new ConfigVMOpenJDK(this), new ConfigVMMac(this)};
|
||||
private ConfigAppServer m_appsConfig = new ConfigAppServer(this);
|
||||
|
||||
/**
|
||||
|
@ -947,7 +957,7 @@ public class ConfigurationData
|
|||
initJava(index);
|
||||
} // initDatabase
|
||||
|
||||
private void initJava(int index)
|
||||
public void initJava(int index)
|
||||
{
|
||||
if (index < 0 || index >= JAVATYPE.length)
|
||||
log.warning("JavaType Index invalid: " + index);
|
||||
|
@ -1154,16 +1164,13 @@ public class ConfigurationData
|
|||
|
||||
/** Oracle directory */
|
||||
private static String DBTYPE_ORACLE = "oracle";
|
||||
/** Oracle XP */
|
||||
private static String DBTYPE_ORACLEXE = "oracleXE";
|
||||
|
||||
/** PostgreSQL */
|
||||
private static String DBTYPE_POSTGRESQL = "postgresql";
|
||||
|
||||
/** Database Types */
|
||||
static String[] DBTYPE = new String[]
|
||||
{ DBTYPE_ORACLEXE,
|
||||
DBTYPE_ORACLE,
|
||||
public static String[] DBTYPE = new String[]
|
||||
{ DBTYPE_ORACLE,
|
||||
//begin e-evolution vpj-cd 02/07/2005 PostgreSQL
|
||||
DBTYPE_POSTGRESQL
|
||||
};
|
||||
|
@ -1173,7 +1180,6 @@ public class ConfigurationData
|
|||
private Config[] m_databaseConfig = new Config[]
|
||||
{
|
||||
new ConfigOracle(this,true),
|
||||
new ConfigOracle(this,false),
|
||||
//begin e-evolution vpj-cd 02/07/2005 PostgreSQL
|
||||
new ConfigPostgreSQL(this)
|
||||
// end e-evolution vpj-cd 02/07/2005 PostgreSQL
|
||||
|
@ -1185,7 +1191,20 @@ public class ConfigurationData
|
|||
*/
|
||||
public void initDatabase(String selected)
|
||||
{
|
||||
int index = (p_panel != null ? p_panel.fDatabaseType.getSelectedIndex() : 0);
|
||||
int index = (p_panel != null ? p_panel.fDatabaseType.getSelectedIndex() : -1);
|
||||
if (index < 0)
|
||||
{
|
||||
for(int i = 0; i < DBTYPE.length; i++)
|
||||
{
|
||||
if (DBTYPE[i].equals(selected))
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
}
|
||||
initDatabase(selected, index);
|
||||
} // initDatabase
|
||||
|
||||
|
@ -1274,7 +1293,9 @@ public class ConfigurationData
|
|||
*/
|
||||
public String getDatabaseDiscovered ()
|
||||
{
|
||||
return (String)p_panel.fDatabaseDiscovered.getSelectedItem();
|
||||
return p_panel != null
|
||||
? (String)p_panel.fDatabaseDiscovered.getSelectedItem()
|
||||
: "";
|
||||
}
|
||||
/**
|
||||
* @param databaseDiscovered The database Discovered to set.
|
||||
|
@ -1436,5 +1457,91 @@ public class ConfigurationData
|
|||
else
|
||||
updateProperty(ADEMPIERE_DB_USER, databaseUser);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the mail Server.
|
||||
*/
|
||||
public String getMailServer ()
|
||||
{
|
||||
return p_panel != null
|
||||
? p_panel.fMailServer.getText()
|
||||
: (String)p_properties.get(ADEMPIERE_MAIL_SERVER);
|
||||
}
|
||||
|
||||
public void setMailServer(String mailServer)
|
||||
{
|
||||
if (p_panel != null)
|
||||
p_panel.fMailServer.setText(mailServer);
|
||||
else
|
||||
updateProperty(ADEMPIERE_MAIL_SERVER, mailServer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the mailUser.
|
||||
*/
|
||||
public String getMailUser ()
|
||||
{
|
||||
return p_panel != null
|
||||
? p_panel.fMailUser.getText()
|
||||
: (String)p_properties.get(ADEMPIERE_MAIL_USER);
|
||||
}
|
||||
/**
|
||||
* @param mailUser The mailUser to set.
|
||||
*/
|
||||
public void setMailUser (String mailUser)
|
||||
{
|
||||
if (p_panel != null)
|
||||
p_panel.fMailUser.setText(mailUser);
|
||||
else
|
||||
updateProperty(ADEMPIERE_MAIL_USER, mailUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the mail User Password.
|
||||
*/
|
||||
public String getMailPassword ()
|
||||
{
|
||||
if (p_panel != null)
|
||||
{
|
||||
char[] pw = p_panel.fMailPassword.getPassword();
|
||||
if (pw != null)
|
||||
return new String(pw);
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
String pw = (String)p_properties.get(ADEMPIERE_MAIL_PASSWORD);
|
||||
return (pw != null ? pw : "");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param mailPassword The mailPassword to set.
|
||||
*/
|
||||
public void setMailPassword (String mailPassword)
|
||||
{
|
||||
if (p_panel != null)
|
||||
p_panel.fMailPassword.setText(mailPassword);
|
||||
else
|
||||
updateProperty(ADEMPIERE_MAIL_PASSWORD, mailPassword);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the admin email
|
||||
*/
|
||||
public String getAdminEMail()
|
||||
{
|
||||
return p_panel != null
|
||||
? p_panel.fAdminEMail.getText()
|
||||
: (String)p_properties.get(ADEMPIERE_ADMIN_EMAIL);
|
||||
}
|
||||
/**
|
||||
* @param adminEMail The admin email
|
||||
*/
|
||||
public void setAdminEMail(String adminEMail)
|
||||
{
|
||||
if (p_panel != null)
|
||||
p_panel.fAdminEMail.setText(adminEMail);
|
||||
else
|
||||
updateProperty(ADEMPIERE_ADMIN_EMAIL, adminEMail);
|
||||
}
|
||||
} // ConfigurationData
|
||||
|
|
|
@ -29,22 +29,21 @@ import java.util.ResourceBundle;
|
|||
import java.util.logging.Level;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
import org.adempiere.base.Core;
|
||||
import org.apache.tools.ant.Main;
|
||||
import org.compiere.swing.CButton;
|
||||
import org.compiere.swing.CCheckBox;
|
||||
import org.compiere.swing.CComboBox;
|
||||
import org.compiere.swing.CLabel;
|
||||
import org.compiere.swing.CPanel;
|
||||
import org.compiere.swing.CPassword;
|
||||
import org.compiere.swing.CTextField;
|
||||
import org.compiere.util.CLogger;
|
||||
|
||||
/**
|
||||
|
@ -53,7 +52,7 @@ import org.compiere.util.CLogger;
|
|||
* @author Jorg Janke
|
||||
* @version $Id: ConfigurationPanel.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $
|
||||
*/
|
||||
public class ConfigurationPanel extends CPanel implements ActionListener
|
||||
public class ConfigurationPanel extends JPanel implements ActionListener
|
||||
{
|
||||
/**
|
||||
*
|
||||
|
@ -103,68 +102,68 @@ public class ConfigurationPanel extends CPanel implements ActionListener
|
|||
private GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
private static final int FIELDLENGTH = 15;
|
||||
// Java
|
||||
private CLabel lJavaHome = new CLabel();
|
||||
CTextField fJavaHome = new CTextField(FIELDLENGTH);
|
||||
CCheckBox okJavaHome = new CCheckBox();
|
||||
private CButton bJavaHome = new CButton(iOpen);
|
||||
private CLabel lJavaType = new CLabel();
|
||||
CComboBox fJavaType = new CComboBox(ConfigurationData.JAVATYPE);
|
||||
private JLabel lJavaHome = new JLabel();
|
||||
JTextField fJavaHome = new JTextField(FIELDLENGTH);
|
||||
JCheckBox okJavaHome = new JCheckBox();
|
||||
private JButton bJavaHome = new JButton(iOpen);
|
||||
private JLabel lJavaType = new JLabel();
|
||||
JComboBox fJavaType = new JComboBox(ConfigurationData.JAVATYPE);
|
||||
// Adempiere - KeyStore
|
||||
private CLabel lAdempiereHome = new CLabel();
|
||||
CTextField fAdempiereHome = new CTextField(FIELDLENGTH);
|
||||
CCheckBox okAdempiereHome = new CCheckBox();
|
||||
private CButton bAdempiereHome = new CButton(iOpen);
|
||||
private CLabel lKeyStore = new CLabel();
|
||||
CPassword fKeyStore = new CPassword();
|
||||
CCheckBox okKeyStore = new CCheckBox();
|
||||
private JLabel lAdempiereHome = new JLabel();
|
||||
JTextField fAdempiereHome = new JTextField(FIELDLENGTH);
|
||||
JCheckBox okAdempiereHome = new JCheckBox();
|
||||
private JButton bAdempiereHome = new JButton(iOpen);
|
||||
private JLabel lKeyStore = new JLabel();
|
||||
JPasswordField fKeyStore = new JPasswordField();
|
||||
JCheckBox okKeyStore = new JCheckBox();
|
||||
// Apps Server - Type
|
||||
CLabel lAppsServer = new CLabel();
|
||||
CTextField fAppsServer = new CTextField(FIELDLENGTH);
|
||||
CCheckBox okAppsServer = new CCheckBox();
|
||||
JLabel lAppsServer = new JLabel();
|
||||
JTextField fAppsServer = new JTextField(FIELDLENGTH);
|
||||
JCheckBox okAppsServer = new JCheckBox();
|
||||
// Web Ports
|
||||
private CLabel lWebPort = new CLabel();
|
||||
CTextField fWebPort = new CTextField(FIELDLENGTH);
|
||||
CCheckBox okWebPort = new CCheckBox();
|
||||
private CLabel lSSLPort = new CLabel();
|
||||
CTextField fSSLPort = new CTextField(FIELDLENGTH);
|
||||
CCheckBox okSSLPort = new CCheckBox();
|
||||
private JLabel lWebPort = new JLabel();
|
||||
JTextField fWebPort = new JTextField(FIELDLENGTH);
|
||||
JCheckBox okWebPort = new JCheckBox();
|
||||
private JLabel lSSLPort = new JLabel();
|
||||
JTextField fSSLPort = new JTextField(FIELDLENGTH);
|
||||
JCheckBox okSSLPort = new JCheckBox();
|
||||
// Database
|
||||
private CLabel lDatabaseType = new CLabel();
|
||||
CComboBox fDatabaseType = new CComboBox(ConfigurationData.DBTYPE);
|
||||
private JLabel lDatabaseType = new JLabel();
|
||||
JComboBox fDatabaseType = new JComboBox(ConfigurationData.DBTYPE);
|
||||
//
|
||||
CLabel lDatabaseServer = new CLabel();
|
||||
CTextField fDatabaseServer = new CTextField(FIELDLENGTH);
|
||||
private CLabel lDatabaseName = new CLabel();
|
||||
CTextField fDatabaseName = new CTextField(FIELDLENGTH);
|
||||
private CLabel lDatabaseDiscovered = new CLabel();
|
||||
CComboBox fDatabaseDiscovered = new CComboBox();
|
||||
private CLabel lDatabasePort = new CLabel();
|
||||
CTextField fDatabasePort = new CTextField(FIELDLENGTH);
|
||||
private CLabel lSystemPassword = new CLabel();
|
||||
CPassword fSystemPassword = new CPassword();
|
||||
private CLabel lDatabaseUser = new CLabel();
|
||||
CTextField fDatabaseUser = new CTextField(FIELDLENGTH);
|
||||
private CLabel lDatabasePassword = new CLabel();
|
||||
CPassword fDatabasePassword = new CPassword();
|
||||
CCheckBox okDatabaseServer = new CCheckBox();
|
||||
CCheckBox okDatabaseUser = new CCheckBox();
|
||||
CCheckBox okDatabaseSystem = new CCheckBox();
|
||||
CCheckBox okDatabaseSQL = new CCheckBox();
|
||||
JLabel lDatabaseServer = new JLabel();
|
||||
JTextField fDatabaseServer = new JTextField(FIELDLENGTH);
|
||||
private JLabel lDatabaseName = new JLabel();
|
||||
JTextField fDatabaseName = new JTextField(FIELDLENGTH);
|
||||
private JLabel lDatabaseDiscovered = new JLabel();
|
||||
JComboBox fDatabaseDiscovered = new JComboBox();
|
||||
private JLabel lDatabasePort = new JLabel();
|
||||
JTextField fDatabasePort = new JTextField(FIELDLENGTH);
|
||||
private JLabel lSystemPassword = new JLabel();
|
||||
JPasswordField fSystemPassword = new JPasswordField();
|
||||
private JLabel lDatabaseUser = new JLabel();
|
||||
JTextField fDatabaseUser = new JTextField(FIELDLENGTH);
|
||||
private JLabel lDatabasePassword = new JLabel();
|
||||
JPasswordField fDatabasePassword = new JPasswordField();
|
||||
JCheckBox okDatabaseServer = new JCheckBox();
|
||||
JCheckBox okDatabaseUser = new JCheckBox();
|
||||
JCheckBox okDatabaseSystem = new JCheckBox();
|
||||
JCheckBox okDatabaseSQL = new JCheckBox();
|
||||
//
|
||||
CLabel lMailServer = new CLabel();
|
||||
CTextField fMailServer = new CTextField(FIELDLENGTH);
|
||||
private CLabel lAdminEMail = new CLabel();
|
||||
CTextField fAdminEMail = new CTextField(FIELDLENGTH);
|
||||
private CLabel lMailUser = new CLabel();
|
||||
CTextField fMailUser = new CTextField(FIELDLENGTH);
|
||||
private CLabel lMailPassword = new CLabel();
|
||||
CPassword fMailPassword = new CPassword();
|
||||
CCheckBox okMailServer = new CCheckBox();
|
||||
CCheckBox okMailUser = new CCheckBox();
|
||||
JLabel lMailServer = new JLabel();
|
||||
JTextField fMailServer = new JTextField(FIELDLENGTH);
|
||||
private JLabel lAdminEMail = new JLabel();
|
||||
JTextField fAdminEMail = new JTextField(FIELDLENGTH);
|
||||
private JLabel lMailUser = new JLabel();
|
||||
JTextField fMailUser = new JTextField(FIELDLENGTH);
|
||||
private JLabel lMailPassword = new JLabel();
|
||||
JPasswordField fMailPassword = new JPasswordField();
|
||||
JCheckBox okMailServer = new JCheckBox();
|
||||
JCheckBox okMailUser = new JCheckBox();
|
||||
//
|
||||
private CButton bHelp = new CButton(iHelp);
|
||||
private CButton bTest = new CButton();
|
||||
private CButton bSave = new CButton(iSave);
|
||||
private JButton bHelp = new JButton(iHelp);
|
||||
private JButton bTest = new JButton();
|
||||
private JButton bSave = new JButton(iSave);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -411,7 +410,7 @@ public class ConfigurationPanel extends CPanel implements ActionListener
|
|||
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 2, 5), 0, 0));
|
||||
|
||||
//grap extra space when window is maximized
|
||||
CPanel filler = new CPanel();
|
||||
JPanel filler = new JPanel();
|
||||
filler.setOpaque(false);
|
||||
filler.setBorder(null);
|
||||
this.add(filler, new GridBagConstraints(0, 21, 1, 1, 0.0, 1.0
|
||||
|
@ -499,7 +498,7 @@ public class ConfigurationPanel extends CPanel implements ActionListener
|
|||
* Set Path in Field
|
||||
* @param field field to set Path
|
||||
*/
|
||||
private void setPath (CTextField field)
|
||||
private void setPath (JTextField field)
|
||||
{
|
||||
JFileChooser fc = new JFileChooser(field.getText());
|
||||
fc.setDialogType(JFileChooser.OPEN_DIALOG);
|
||||
|
@ -516,9 +515,9 @@ public class ConfigurationPanel extends CPanel implements ActionListener
|
|||
* @param saveIt save
|
||||
* @return SwingWorker
|
||||
*/
|
||||
private org.compiere.apps.SwingWorker startTest(final boolean saveIt)
|
||||
private org.compiere.install.util.SwingWorker startTest(final boolean saveIt)
|
||||
{
|
||||
org.compiere.apps.SwingWorker worker = new org.compiere.apps.SwingWorker()
|
||||
org.compiere.install.util.SwingWorker worker = new org.compiere.install.util.SwingWorker()
|
||||
{
|
||||
// Start it
|
||||
public Object construct()
|
||||
|
@ -587,7 +586,7 @@ public class ConfigurationPanel extends CPanel implements ActionListener
|
|||
* @param critical true if critical
|
||||
* @param errorMsg error Message
|
||||
*/
|
||||
void signalOK (CCheckBox cb, String resString,
|
||||
void signalOK (JCheckBox cb, String resString,
|
||||
boolean pass, boolean critical, String errorMsg)
|
||||
{
|
||||
m_errorString = res.getString(resString);
|
||||
|
|
|
@ -21,18 +21,19 @@ import java.awt.Dimension;
|
|||
import java.awt.FlowLayout;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.compiere.apps.AEnv;
|
||||
import org.compiere.apps.ALayout;
|
||||
import org.compiere.apps.ALayoutConstraint;
|
||||
import org.compiere.apps.ConfirmPanel;
|
||||
import org.compiere.swing.CButton;
|
||||
import org.compiere.swing.CDialog;
|
||||
import org.compiere.swing.CLabel;
|
||||
import org.compiere.swing.CPanel;
|
||||
import org.compiere.swing.CTextField;
|
||||
import org.compiere.install.util.AEnv;
|
||||
import org.compiere.install.util.ALayout;
|
||||
import org.compiere.install.util.ALayoutConstraint;
|
||||
import org.compiere.install.util.ConfirmPanel;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -41,7 +42,7 @@ import org.compiere.swing.CTextField;
|
|||
* @author Jorg Janke
|
||||
* @version $Id: KeyStoreDialog.java,v 1.3 2006/07/30 00:57:42 jjanke Exp $
|
||||
*/
|
||||
public class KeyStoreDialog extends CDialog
|
||||
public class KeyStoreDialog extends JDialog implements ActionListener
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -73,21 +74,21 @@ public class KeyStoreDialog extends CDialog
|
|||
AEnv.showCenterWindow(owner, this);
|
||||
} // KeyStoreDialog
|
||||
|
||||
private CLabel lCN = new CLabel("(ON) Common Name");
|
||||
private CTextField fCN = new CTextField(20);
|
||||
private CLabel lOU = new CLabel("(OU) Organization Unit");
|
||||
private CTextField fOU = new CTextField(20);
|
||||
private CLabel lO = new CLabel("(O) Organization");
|
||||
private CTextField fO = new CTextField(20);
|
||||
private CLabel lL = new CLabel("(L) Locale/Town");
|
||||
private CTextField fL = new CTextField(20);
|
||||
private CLabel lS = new CLabel("(S) State");
|
||||
private CTextField fS = new CTextField(20);
|
||||
private CLabel lC = new CLabel("(C) Country (2 Char)");
|
||||
private CTextField fC = new CTextField(2);
|
||||
private JLabel lCN = new JLabel("(ON) Common Name");
|
||||
private JTextField fCN = new JTextField(20);
|
||||
private JLabel lOU = new JLabel("(OU) Organization Unit");
|
||||
private JTextField fOU = new JTextField(20);
|
||||
private JLabel lO = new JLabel("(O) Organization");
|
||||
private JTextField fO = new JTextField(20);
|
||||
private JLabel lL = new JLabel("(L) Locale/Town");
|
||||
private JTextField fL = new JTextField(20);
|
||||
private JLabel lS = new JLabel("(S) State");
|
||||
private JTextField fS = new JTextField(20);
|
||||
private JLabel lC = new JLabel("(C) Country (2 Char)");
|
||||
private JTextField fC = new JTextField(2);
|
||||
|
||||
private CButton bOK = ConfirmPanel.createOKButton("OK");
|
||||
private CButton bCancel = ConfirmPanel.createCancelButton("Cancel");
|
||||
private JButton bOK = ConfirmPanel.createOKButton("OK");
|
||||
private JButton bCancel = ConfirmPanel.createCancelButton("Cancel");
|
||||
private boolean m_ok = false;
|
||||
|
||||
/**
|
||||
|
@ -95,7 +96,7 @@ public class KeyStoreDialog extends CDialog
|
|||
*/
|
||||
private void jbInit()
|
||||
{
|
||||
CPanel panel = new CPanel(new ALayout());
|
||||
JPanel panel = new JPanel(new ALayout());
|
||||
panel.add(lCN, new ALayoutConstraint(0, 0));
|
||||
panel.add(fCN, null);
|
||||
panel.add(lOU, new ALayoutConstraint(1, 0));
|
||||
|
@ -113,7 +114,7 @@ public class KeyStoreDialog extends CDialog
|
|||
getContentPane().setLayout(new BorderLayout());
|
||||
getContentPane().add (panel, BorderLayout.CENTER);
|
||||
//
|
||||
CPanel confirmPanel = new CPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
JPanel confirmPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
confirmPanel.add(bCancel);
|
||||
confirmPanel.add(bOK);
|
||||
getContentPane().add (confirmPanel, BorderLayout.SOUTH);
|
||||
|
|
|
@ -30,12 +30,11 @@ import javax.swing.JFrame;
|
|||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import org.compiere.Adempiere;
|
||||
import org.compiere.apps.AEnv;
|
||||
import org.compiere.swing.CFrame;
|
||||
import org.compiere.swing.CMenuItem;
|
||||
import org.compiere.install.util.AEnv;
|
||||
import org.compiere.util.CLogFile;
|
||||
import org.compiere.util.CLogMgt;
|
||||
import org.compiere.util.CLogger;
|
||||
|
@ -46,7 +45,7 @@ import org.compiere.util.CLogger;
|
|||
* @author Jorg Janke
|
||||
* @version $Id: Setup.java,v 1.2 2006/07/30 00:57:42 jjanke Exp $
|
||||
*/
|
||||
public class Setup extends CFrame implements ActionListener
|
||||
public class Setup extends JFrame implements ActionListener
|
||||
{
|
||||
/**
|
||||
*
|
||||
|
@ -94,9 +93,9 @@ public class Setup extends CFrame implements ActionListener
|
|||
private JPanel contentPane;
|
||||
private JMenuBar menuBar = new JMenuBar();
|
||||
private JMenu menuFile = new JMenu();
|
||||
private CMenuItem menuFileExit = new CMenuItem();
|
||||
private JMenuItem menuFileExit = new JMenuItem();
|
||||
private JMenu menuHelp = new JMenu();
|
||||
private CMenuItem menuHelpInfo = new CMenuItem();
|
||||
private JMenuItem menuHelpInfo = new JMenuItem();
|
||||
private JLabel statusBar = new JLabel();
|
||||
private BorderLayout borderLayout = new BorderLayout();
|
||||
private ConfigurationPanel configurationPanel = new ConfigurationPanel (statusBar);
|
||||
|
|
|
@ -32,10 +32,10 @@ import java.util.ResourceBundle;
|
|||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import org.compiere.apps.OnlineHelp;
|
||||
import org.compiere.swing.CPanel;
|
||||
import org.compiere.install.util.OnlineHelp;
|
||||
|
||||
/**
|
||||
* Setup Online Help
|
||||
|
@ -104,8 +104,8 @@ public class Setup_Help extends JDialog implements ActionListener
|
|||
|
||||
|
||||
static ResourceBundle res = ResourceBundle.getBundle("org.compiere.install.SetupRes");
|
||||
private CPanel mainPanel = new CPanel();
|
||||
private CPanel southPanel = new CPanel();
|
||||
private JPanel mainPanel = new JPanel();
|
||||
private JPanel southPanel = new JPanel();
|
||||
private JButton bOK = new JButton();
|
||||
private BorderLayout mainLayout = new BorderLayout();
|
||||
private JScrollPane centerScrollPane = new JScrollPane();
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.compiere.install.console;
|
||||
|
||||
import org.eclipse.equinox.app.IApplication;
|
||||
import org.eclipse.equinox.app.IApplicationContext;
|
||||
|
||||
/**
|
||||
* @author hengsin
|
||||
*
|
||||
*/
|
||||
public class Application implements IApplication {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
|
||||
*/
|
||||
@Override
|
||||
public Object start(IApplicationContext context) throws Exception {
|
||||
ConfigurationConsole console = new ConfigurationConsole();
|
||||
console.doSetup();
|
||||
return Application.EXIT_OK;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.equinox.app.IApplication#stop()
|
||||
*/
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,500 @@
|
|||
package org.compiere.install.console;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import org.compiere.install.ConfigurationData;
|
||||
import org.compiere.install.KeyStoreMgt;
|
||||
import org.compiere.util.Ini;
|
||||
|
||||
public class ConfigurationConsole {
|
||||
|
||||
ConfigurationData data = new ConfigurationData(null);
|
||||
|
||||
public void doSetup() {
|
||||
BufferedReader reader = null;
|
||||
PrintWriter writer = null;
|
||||
reader = new BufferedReader(new InputStreamReader(System.in));
|
||||
writer = new PrintWriter(System.out, true);
|
||||
|
||||
Ini.setShowLicenseDialog(false);
|
||||
data.load();
|
||||
|
||||
try {
|
||||
jvmType(reader, writer);
|
||||
jvmHome(reader, writer);
|
||||
|
||||
adempiereHome(reader, writer);
|
||||
keyStorePass(reader, writer);
|
||||
|
||||
appServerHostname(reader, writer);
|
||||
appServerWebPort(reader, writer);
|
||||
appServerSSLPort(reader, writer);
|
||||
|
||||
dbType(reader, writer);
|
||||
dbHostname(reader, writer);
|
||||
dbPort(reader, writer);
|
||||
dbName(reader, writer);
|
||||
dbUser(reader, writer);
|
||||
dbPassword(reader, writer);
|
||||
dbSystemPassword(reader, writer);
|
||||
|
||||
mailServer(reader, writer);
|
||||
mailUser(reader, writer);
|
||||
mailPassword(reader, writer);
|
||||
mailAdmin(reader, writer);
|
||||
writer.println("Save changes (Y/N) [Y]: ");
|
||||
String yesNo = reader.readLine();
|
||||
if ((yesNo == null || yesNo.trim().length() == 0) || "y".equalsIgnoreCase(yesNo))
|
||||
{
|
||||
boolean b = data.save();
|
||||
if (b)
|
||||
writer.println("Changes save successfully.");
|
||||
else
|
||||
writer.println("Failed to save changes.");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.println("Changes ignore.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void mailAdmin(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
while(true)
|
||||
{
|
||||
writer.println("Administrator EMail ["+data.getAdminEMail()+"]:");
|
||||
String adminEMail = reader.readLine();
|
||||
if (adminEMail != null && adminEMail.trim().length() > 0)
|
||||
{
|
||||
data.setAdminEMail(adminEMail);
|
||||
}
|
||||
String error = data.testMail();
|
||||
if (error != null && error.trim().length() > 0)
|
||||
{
|
||||
writer.println("Mail setting validation error: " + error);
|
||||
mailServer(reader, writer);
|
||||
mailUser(reader, writer);
|
||||
mailPassword(reader, writer);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void mailPassword(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
writer.println("Mail User Password ["+data.getMailPassword()+"]");
|
||||
String mailPassword = reader.readLine();
|
||||
if (mailPassword != null && mailPassword.trim().length() > 0)
|
||||
{
|
||||
data.setMailPassword(mailPassword);
|
||||
}
|
||||
}
|
||||
|
||||
private void mailUser(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
writer.println("Mail User Login ["+data.getMailUser()+"]:");
|
||||
String userName = reader.readLine();
|
||||
if (userName != null && userName.trim().length() > 0)
|
||||
{
|
||||
data.setMailUser(userName);
|
||||
}
|
||||
}
|
||||
|
||||
private void mailServer(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
writer.println("Mail Server Host Name ["+data.getMailServer()+"]:");
|
||||
String hostName = reader.readLine();
|
||||
if (hostName != null && hostName.trim().length() > 0)
|
||||
{
|
||||
data.setMailServer(hostName);
|
||||
}
|
||||
}
|
||||
|
||||
private void dbPort(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
while (true)
|
||||
{
|
||||
writer.println("Database Server Port ["+data.getDatabasePort()+"]:");
|
||||
String input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
int inputPort = Integer.parseInt(input);
|
||||
if (inputPort <= 0 || inputPort > 65535)
|
||||
{
|
||||
writer.println("Invalid input, please enter a valid port number");
|
||||
continue;
|
||||
}
|
||||
data.setDatabasePort(input);
|
||||
break;
|
||||
}
|
||||
catch (NumberFormatException e){
|
||||
writer.println("Invalid input, please enter a valid port number");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void dbSystemPassword(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
while (true)
|
||||
{
|
||||
writer.println("Database System User Password ["+data.getDatabaseSystemPassword()+"]");
|
||||
String dbPassword = reader.readLine();
|
||||
if (dbPassword != null && dbPassword.trim().length() > 0)
|
||||
{
|
||||
data.setDatabaseSystemPassword(dbPassword);
|
||||
}
|
||||
String error = data.testDatabase();
|
||||
if (error != null && error.trim().length() > 0)
|
||||
{
|
||||
writer.println("Database test fail: " + error);
|
||||
dbType(reader, writer);
|
||||
dbHostname(reader, writer);
|
||||
dbPort(reader, writer);
|
||||
dbName(reader, writer);
|
||||
dbUser(reader, writer);
|
||||
dbPassword(reader, writer);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void dbPassword(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
writer.println("Database Password [" + data.getDatabasePassword()+"]:");
|
||||
String dbPassword = reader.readLine();
|
||||
if (dbPassword != null && dbPassword.trim().length() > 0)
|
||||
{
|
||||
data.setDatabasePassword(dbPassword);
|
||||
}
|
||||
}
|
||||
|
||||
private void dbUser(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
writer.println("Database user ["+data.getDatabaseUser()+"]:");
|
||||
String dbUser = reader.readLine();
|
||||
if (dbUser != null && dbUser.trim().length() > 0)
|
||||
{
|
||||
data.setDatabaseUser(dbUser);
|
||||
}
|
||||
}
|
||||
|
||||
private void dbName(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
writer.println("Database Name["+data.getDatabaseName()+"]:");
|
||||
String dbName = reader.readLine();
|
||||
if (dbName != null && dbName.trim().length() > 0)
|
||||
{
|
||||
data.setDatabaseName(dbName);
|
||||
}
|
||||
}
|
||||
|
||||
private void dbHostname(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
writer.println("Database Server Host Name ["+data.getDatabaseServer()+"]:");
|
||||
String hostName = reader.readLine();
|
||||
if (hostName != null && hostName.trim().length() > 0)
|
||||
{
|
||||
data.setDatabaseServer(hostName);
|
||||
}
|
||||
}
|
||||
|
||||
private void appServerSSLPort(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
while (true)
|
||||
{
|
||||
writer.println("Application Server SSL Port["+data.getAppsServerSSLPort()+"]:");
|
||||
String input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
int inputPort = Integer.parseInt(input);
|
||||
if (inputPort <= 0 || inputPort > 65535)
|
||||
{
|
||||
writer.println("Invalid input, please enter a valid port number");
|
||||
continue;
|
||||
}
|
||||
data.setAppsServerSSLPort(input);
|
||||
String error = data.testAppsServer();
|
||||
if (error != null && error.trim().length() > 0)
|
||||
{
|
||||
writer.println("Application server test fail: " + error);
|
||||
appServerHostname(reader, writer);
|
||||
appServerWebPort(reader, writer);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
catch (NumberFormatException e){
|
||||
writer.println("Invalid input, please enter a valid port number");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void appServerWebPort(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
while (true)
|
||||
{
|
||||
writer.println("Application Server Web Port ["+data.getAppsServerWebPort()+"]:");
|
||||
String input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
int inputPort = Integer.parseInt(input);
|
||||
if (inputPort <= 0 || inputPort > 65535)
|
||||
{
|
||||
writer.println("Invalid input, please enter a valid port number");
|
||||
continue;
|
||||
}
|
||||
data.setAppsServerWebPort(input);
|
||||
break;
|
||||
}
|
||||
catch (NumberFormatException e){
|
||||
writer.println("Invalid input, please enter a valid port number");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void appServerHostname(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
writer.println("Application Server Host Name ["+data.getAppsServer()+"]:");
|
||||
String hostName = reader.readLine();
|
||||
if (hostName != null && hostName.trim().length() > 0)
|
||||
{
|
||||
data.setAppsServer(hostName);
|
||||
}
|
||||
}
|
||||
|
||||
private void keyStorePass(BufferedReader reader, PrintWriter writer) throws Exception {
|
||||
while (true)
|
||||
{
|
||||
writer.println("Key Store Password [" + data.getKeyStore() + "]:");
|
||||
String password = reader.readLine();
|
||||
if (password != null && password.trim().length() > 0)
|
||||
{
|
||||
data.setKeyStore(password);
|
||||
}
|
||||
else
|
||||
{
|
||||
password = data.getKeyStore();
|
||||
}
|
||||
|
||||
File adempiereHome = new File(data.getAdempiereHome());
|
||||
String fileName = KeyStoreMgt.getKeystoreFileName(adempiereHome.getAbsolutePath());
|
||||
KeyStoreMgt storeMgt = new KeyStoreMgt (fileName, password.toCharArray());
|
||||
KeyStore keyStore = storeMgt.getKeyStore();
|
||||
if (keyStore == null)
|
||||
{
|
||||
String cn = data.getProperty(ConfigurationData.ADEMPIERE_CERT_CN);
|
||||
if (cn == null)
|
||||
cn = System.getProperty("user.name");
|
||||
String ou = data.getProperty(ConfigurationData.ADEMPIERE_CERT_ORG_UNIT);
|
||||
if (ou == null)
|
||||
ou = "AdempiereUser";
|
||||
String o = data.getProperty(ConfigurationData.ADEMPIERE_CERT_ORG);
|
||||
if (o == null)
|
||||
o = System.getProperty("user.name");
|
||||
String lt = data.getProperty(ConfigurationData.ADEMPIERE_CERT_LOCATION);
|
||||
if (lt == null)
|
||||
lt = "MyTown";
|
||||
String st = data.getProperty(ConfigurationData.ADEMPIERE_CERT_STATE);
|
||||
if (st == null) st = "";
|
||||
String country = data.getProperty(ConfigurationData.ADEMPIERE_CERT_COUNTRY);
|
||||
if (country == null)
|
||||
country = System.getProperty("user.country");
|
||||
|
||||
writer.println("KeyStore Settings.");
|
||||
writer.println("(ON) Common Name [" + cn + "]:");
|
||||
String input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
cn = input;
|
||||
data.updateProperty(ConfigurationData.ADEMPIERE_CERT_CN, input);
|
||||
}
|
||||
|
||||
writer.println("(OU) Organization Unit [" + ou + "]:");
|
||||
input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
ou = input;
|
||||
data.updateProperty(ConfigurationData.ADEMPIERE_CERT_ORG_UNIT, ou);
|
||||
}
|
||||
|
||||
writer.println("(O) Organization [" + o + "]:");
|
||||
input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
o = input;
|
||||
data.updateProperty(ConfigurationData.ADEMPIERE_CERT_ORG, o);
|
||||
}
|
||||
|
||||
writer.println("(L) Locale/Town [" + lt + "]:");
|
||||
input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
lt = input;
|
||||
data.updateProperty(ConfigurationData.ADEMPIERE_CERT_LOCATION, lt);
|
||||
}
|
||||
|
||||
writer.println("(S) State [" + st + "]:");
|
||||
input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
st = input;
|
||||
data.updateProperty(ConfigurationData.ADEMPIERE_CERT_STATE, st);
|
||||
}
|
||||
|
||||
writer.println("(C) Country (2 Char) [" + country +"]");
|
||||
input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
country = input;
|
||||
data.updateProperty(ConfigurationData.ADEMPIERE_CERT_COUNTRY, input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String error = data.testAdempiere();
|
||||
if (error != null && error.trim().length() > 0)
|
||||
{
|
||||
writer.println("Adempiere home and keystore validation error: " + error);
|
||||
adempiereHome(reader, writer);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void adempiereHome(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
writer.println("Adempiere Home ["+data.getAdempiereHome()+"]:");
|
||||
String input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
data.setAdempiereHome(input);
|
||||
}
|
||||
}
|
||||
|
||||
private void jvmHome(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
while (true)
|
||||
{
|
||||
writer.println("Java Home ["+data.getJavaHome()+"]:");
|
||||
String input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
data.setJavaHome(input);
|
||||
}
|
||||
String error = data.testJava();
|
||||
if (error != null && error.trim().length() > 0)
|
||||
{
|
||||
writer.println("JVM test fail: " + error);
|
||||
jvmType(reader, writer);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void jvmType(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
//java type
|
||||
String javaType = data.getJavaType();
|
||||
int javaTypeSelected = 0;
|
||||
for(int i = 0; i < ConfigurationData.JAVATYPE.length; i++)
|
||||
{
|
||||
if (ConfigurationData.JAVATYPE[i].equals(javaType))
|
||||
{
|
||||
javaTypeSelected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// console.writer().println("JVM Type:");
|
||||
for(int i = 0; i < ConfigurationData.JAVATYPE.length; i++)
|
||||
{
|
||||
writer.println((i+1) + ". " + ConfigurationData.JAVATYPE[i]);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
writer.println("JVM Type [" + (javaTypeSelected+1) + "]:");
|
||||
String input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
int inputIndex = Integer.parseInt(input);
|
||||
if (inputIndex <= 0 || inputIndex > ConfigurationData.JAVATYPE.length)
|
||||
{
|
||||
writer.println("Invalid input, please enter numeric value of 1 to " + ConfigurationData.JAVATYPE.length);
|
||||
continue;
|
||||
}
|
||||
data.initJava(inputIndex-1);
|
||||
data.setJavaType(ConfigurationData.JAVATYPE[inputIndex-1]);
|
||||
break;
|
||||
}
|
||||
catch (NumberFormatException e){
|
||||
writer.println("Invalid input, please enter numeric value of 1 to " + ConfigurationData.JAVATYPE.length);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data.initJava(javaTypeSelected);
|
||||
data.setJavaType(ConfigurationData.JAVATYPE[javaTypeSelected]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void dbType(BufferedReader reader, PrintWriter writer) throws IOException {
|
||||
String dbType = data.getDatabaseType();
|
||||
int dbTypeSelected = 0;
|
||||
for(int i = 0; i < ConfigurationData.DBTYPE.length; i++)
|
||||
{
|
||||
if (ConfigurationData.DBTYPE[i].equals(dbType))
|
||||
{
|
||||
dbTypeSelected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// console.writer().println("JVM Type:");
|
||||
for(int i = 0; i < ConfigurationData.DBTYPE.length; i++)
|
||||
{
|
||||
writer.println((i+1)+". "+ConfigurationData.DBTYPE[i]);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
writer.println("Database Type ["+(dbTypeSelected+1)+"]");
|
||||
String input = reader.readLine();
|
||||
if (input != null && input.trim().length() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
int inputIndex = Integer.parseInt(input);
|
||||
if (inputIndex <= 0 || inputIndex > ConfigurationData.DBTYPE.length)
|
||||
{
|
||||
writer.println("Invalid input, please enter numeric value of 1 to " + ConfigurationData.DBTYPE.length);
|
||||
continue;
|
||||
}
|
||||
data.initDatabase(ConfigurationData.DBTYPE[inputIndex-1]);
|
||||
data.setDatabaseType(ConfigurationData.DBTYPE[inputIndex-1]);
|
||||
break;
|
||||
}
|
||||
catch (NumberFormatException e){
|
||||
writer.println("Invalid input, please enter numeric value of 1 to " + ConfigurationData.DBTYPE.length);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
package org.compiere.install.util;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
|
||||
import javax.swing.SwingConstants;
|
||||
|
||||
public class AEnv {
|
||||
|
||||
/**
|
||||
* Show in the center of the screen.
|
||||
* (pack, set location and set visibility)
|
||||
* @param window Window to position
|
||||
*/
|
||||
public static void showCenterScreen(Window window)
|
||||
{
|
||||
positionCenterScreen(window);
|
||||
showWindow(window);
|
||||
} // showCenterScreen
|
||||
|
||||
/**
|
||||
* Position in center of the parent window.
|
||||
* (pack, set location and set visibility)
|
||||
* @param parent Parent Window
|
||||
* @param window Window to position
|
||||
*/
|
||||
public static void showCenterWindow(Window parent, Window window)
|
||||
{
|
||||
positionCenterWindow(parent, window);
|
||||
showWindow(window);
|
||||
} // showCenterWindow
|
||||
|
||||
/**
|
||||
* Position in center of the parent window
|
||||
*
|
||||
* @param parent Parent Window
|
||||
* @param window Window to position
|
||||
*/
|
||||
public static void positionCenterWindow(Window parent, Window window)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
positionCenterScreen(window);
|
||||
return;
|
||||
}
|
||||
window.pack();
|
||||
//
|
||||
Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
// take into account task bar and other adornments
|
||||
GraphicsConfiguration config = window.getGraphicsConfiguration();
|
||||
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config);
|
||||
sSize.width -= (insets.left + insets.right);
|
||||
sSize.height -= (insets.top + insets.bottom);
|
||||
|
||||
Dimension wSize = window.getSize();
|
||||
// fit on window
|
||||
if (wSize.height > sSize.height)
|
||||
wSize.height = sSize.height;
|
||||
if (wSize.width > sSize.width)
|
||||
wSize.width = sSize.width;
|
||||
window.setSize(wSize);
|
||||
// center in parent
|
||||
Rectangle pBounds = parent.getBounds();
|
||||
// Parent is in upper left corner
|
||||
if (pBounds.x == pBounds.y && pBounds.x == 0)
|
||||
{
|
||||
positionCenterScreen(window);
|
||||
return;
|
||||
}
|
||||
// Find middle
|
||||
int x = pBounds.x + ((pBounds.width-wSize.width)/2);
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
int y = pBounds.y + ((pBounds.height-wSize.height)/2);
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
|
||||
// Is it on Screen?
|
||||
if (x + wSize.width > sSize.width)
|
||||
x = sSize.width - wSize.width;
|
||||
if (y + wSize.height > sSize.height)
|
||||
y = sSize.height - wSize.height;
|
||||
//
|
||||
// System.out.println("Position: x=" + x + " y=" + y + " w=" + wSize.getWidth() + " h=" + wSize.getHeight()
|
||||
// + " - Parent loc x=" + pLoc.x + " y=" + y + " w=" + pSize.getWidth() + " h=" + pSize.getHeight());
|
||||
window.setLocation(x + insets.left, y + insets.top);
|
||||
} // positionCenterScreen
|
||||
|
||||
/**
|
||||
* Position window in center of the screen
|
||||
* @param window Window to position
|
||||
*/
|
||||
public static void positionCenterScreen(Window window)
|
||||
{
|
||||
positionScreen (window, SwingConstants.CENTER);
|
||||
} // positionCenterScreen
|
||||
|
||||
/**
|
||||
* Position window in center of the screen
|
||||
* @param window Window to position
|
||||
* @param position SwingConstants
|
||||
*/
|
||||
public static void positionScreen (Window window, int position)
|
||||
{
|
||||
window.pack();
|
||||
// take into account task bar and other adornments
|
||||
GraphicsConfiguration config = window.getGraphicsConfiguration();
|
||||
Rectangle bounds = config.getBounds();
|
||||
Dimension sSize = bounds.getSize();
|
||||
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config);
|
||||
sSize.width -= (insets.left + insets.right);
|
||||
sSize.height -= (insets.top + insets.bottom);
|
||||
|
||||
Dimension wSize = window.getSize();
|
||||
// fit on window
|
||||
if (wSize.height > sSize.height)
|
||||
wSize.height = sSize.height;
|
||||
if (wSize.width > sSize.width)
|
||||
wSize.width = sSize.width;
|
||||
window.setSize(wSize);
|
||||
// Center
|
||||
int x = (sSize.width - wSize.width) / 2;
|
||||
int y = (sSize.height - wSize.height) / 2;
|
||||
if (position == SwingConstants.CENTER)
|
||||
;
|
||||
else if (position == SwingConstants.NORTH_WEST)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
else if (position == SwingConstants.NORTH)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
else if (position == SwingConstants.NORTH_EAST)
|
||||
{
|
||||
x = (sSize.width - wSize.width);
|
||||
y = 0;
|
||||
}
|
||||
else if (position == SwingConstants.WEST)
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
else if (position == SwingConstants.EAST)
|
||||
{
|
||||
x = (sSize.width - wSize.width);
|
||||
}
|
||||
else if (position == SwingConstants.SOUTH)
|
||||
{
|
||||
y = (sSize.height - wSize.height);
|
||||
}
|
||||
else if (position == SwingConstants.SOUTH_WEST)
|
||||
{
|
||||
x = 0;
|
||||
y = (sSize.height - wSize.height);
|
||||
}
|
||||
else if (position == SwingConstants.SOUTH_EAST)
|
||||
{
|
||||
x = (sSize.width - wSize.width);
|
||||
y = (sSize.height - wSize.height);
|
||||
}
|
||||
//
|
||||
window.setLocation(bounds.x + x + insets.left, bounds.y + y + insets.top);
|
||||
} // positionScreen
|
||||
|
||||
/**
|
||||
* Show window: de-iconify and bring it to front
|
||||
* @author teo_sarca [ 1707221 ]
|
||||
*/
|
||||
public static void showWindow(Window window) {
|
||||
window.setVisible(true);
|
||||
if (window instanceof Frame) {
|
||||
Frame f = (Frame)window;
|
||||
int state = f.getExtendedState();
|
||||
if ((state & Frame.ICONIFIED) > 0)
|
||||
f.setExtendedState(state & ~Frame.ICONIFIED);
|
||||
}
|
||||
window.toFront();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,418 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.install.util;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.LayoutManager2;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Application Layout Manager.
|
||||
* <code>
|
||||
* panel.setLayout(new ALayout());
|
||||
* panel.add(field11, new ALayoutConstraint(0,0));
|
||||
* panel.add(field12, null);
|
||||
* panel.add(field13, null);
|
||||
* panel.add(field14, null);
|
||||
* panel.add(field21, new ALayoutConstraint(1,0));
|
||||
* </code>
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: ALayout.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
|
||||
*/
|
||||
public class ALayout implements LayoutManager2
|
||||
{
|
||||
/**
|
||||
* Default Constructor with spacing of 2 and columns filled
|
||||
*/
|
||||
public ALayout()
|
||||
{
|
||||
this (2,4, true);
|
||||
} // ALayout
|
||||
|
||||
/**
|
||||
* Detail Contructor
|
||||
* @param spaceH horizontal space (top, between rows, button)
|
||||
* @param spaceV vertical space (left, between columns, right)
|
||||
* @param colFill fields are fully filled (rather then preferred size)
|
||||
*/
|
||||
public ALayout(int spaceH, int spaceV, boolean colFill)
|
||||
{
|
||||
setSpaceH(spaceH);
|
||||
setSpaceV(spaceV);
|
||||
m_colFill = colFill;
|
||||
} // ALayout
|
||||
|
||||
/** Data Storage */
|
||||
private ALayoutCollection m_data = new ALayoutCollection();
|
||||
/** Horizontal Space */
|
||||
private int m_spaceH;
|
||||
/** Vertical Space */
|
||||
private int m_spaceV;
|
||||
/** Column Fill */
|
||||
private boolean m_colFill;
|
||||
|
||||
/**
|
||||
* Add To Layout with NULL constraint
|
||||
*
|
||||
* @param name the string to be associated with the component - ignored
|
||||
* @param comp the component to be added
|
||||
*/
|
||||
public void addLayoutComponent(String name, Component comp)
|
||||
{
|
||||
addLayoutComponent (comp, null);
|
||||
} // addLayoutComponent
|
||||
|
||||
/**
|
||||
* Adds the specified component to the layout, using the specified
|
||||
* constraint object. If the constraint is not a ALayoutConstraint
|
||||
* the component is added with a NULL constraint.
|
||||
* <p>
|
||||
* Components with a NULL constraint are added as the next column to the last row
|
||||
*
|
||||
* @param component the component to be added
|
||||
* @param constraint where/how the component is added to the layout.
|
||||
* @see ALayoutConstraint
|
||||
*/
|
||||
public void addLayoutComponent(Component component, Object constraint)
|
||||
{
|
||||
ALayoutConstraint con = null;
|
||||
if (constraint instanceof ALayoutConstraint)
|
||||
con = (ALayoutConstraint)constraint;
|
||||
//
|
||||
m_data.put(con, component);
|
||||
} // addLayoutComponent
|
||||
|
||||
/**
|
||||
* Removes the specified component from the layout.
|
||||
* @param comp the component to be removed
|
||||
*/
|
||||
public void removeLayoutComponent(Component comp)
|
||||
{
|
||||
if (!m_data.containsValue(comp))
|
||||
return;
|
||||
Iterator it = m_data.keySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
Object key = it.next();
|
||||
if (m_data.get(key).equals(comp))
|
||||
{
|
||||
m_data.remove(key);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // removeLayoutComponent
|
||||
|
||||
/**
|
||||
* Calculates the preferred size dimensions for the specified
|
||||
* container, given the components it contains.
|
||||
* @param parent the container to be laid out
|
||||
* @return Size
|
||||
* @see #minimumLayoutSize
|
||||
*/
|
||||
public Dimension preferredLayoutSize(Container parent)
|
||||
{
|
||||
return calculateLayoutSize (parent, 'P');
|
||||
} // preferredLayoutSize
|
||||
|
||||
/**
|
||||
* Calculates the minimum size dimensions for the specified
|
||||
* container, given the components it contains.
|
||||
* @param parent the component to be laid out
|
||||
* @return Size
|
||||
* @see #preferredLayoutSize
|
||||
*/
|
||||
public Dimension minimumLayoutSize(Container parent)
|
||||
{
|
||||
return calculateLayoutSize (parent, 'm');
|
||||
} // minimumLayoutSize
|
||||
|
||||
/**
|
||||
* Calculates the maximum size dimensions for the specified container,
|
||||
* given the components it contains.
|
||||
* @param parent Parent Container
|
||||
* @return Size
|
||||
* @see java.awt.Component#getMaximumSize
|
||||
* @see LayoutManager
|
||||
*/
|
||||
public Dimension maximumLayoutSize(Container parent)
|
||||
{
|
||||
return calculateLayoutSize (parent, 'M');
|
||||
} // maximumLayoutSize
|
||||
|
||||
/**
|
||||
* Calculate Layout Size
|
||||
* @param parent Parent Container
|
||||
* @param how P=Preferred - M=Maximum = m=Mimimum
|
||||
* @return Size
|
||||
*/
|
||||
private Dimension calculateLayoutSize(Container parent, char how)
|
||||
{
|
||||
checkComponents(parent);
|
||||
// -- Create 2D Dimension Array
|
||||
int rows = getRowCount();
|
||||
int cols = getColCount();
|
||||
Dimension[][] dim = new Dimension[rows][cols];
|
||||
//
|
||||
Object[] keys = m_data.keySet().toArray();
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; i++)
|
||||
{
|
||||
ALayoutConstraint constraint = (ALayoutConstraint)keys[i];
|
||||
Component component = (Component)m_data.get(keys[i]);
|
||||
Dimension d = null;
|
||||
if (how == 'P')
|
||||
d = component.getPreferredSize();
|
||||
else if (how == 'M')
|
||||
d = component.getMaximumSize();
|
||||
else
|
||||
d = component.getMinimumSize();
|
||||
if (component.isVisible())
|
||||
dim [constraint.getRow()][constraint.getCol()] = d;
|
||||
else
|
||||
dim [constraint.getRow()][constraint.getCol()] = null;
|
||||
}
|
||||
|
||||
// -- Calculate 2D Dimension Size
|
||||
Insets insets = parent.getInsets();
|
||||
Dimension retValue = new Dimension (insets.left+insets.right, insets.top+insets.bottom);
|
||||
retValue.height += m_spaceH;
|
||||
retValue.width += m_spaceV;
|
||||
int maxWidth = 0;
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
Dimension d = dim[r][c];
|
||||
if (d != null)
|
||||
{
|
||||
width += d.width;
|
||||
height = Math.max(height, d.height);
|
||||
}
|
||||
width += m_spaceV;
|
||||
} // for all columns
|
||||
retValue.height += height + m_spaceH;
|
||||
maxWidth += Math.max(maxWidth, width);
|
||||
} // for all rows
|
||||
retValue.width += maxWidth;
|
||||
// Log.trace(this,Log.l6_Database, "ALayout.calculateLayoutSize", retValue.toString());
|
||||
return retValue;
|
||||
} // calculateLayoutSize
|
||||
|
||||
/**
|
||||
* Lays out the specified container.
|
||||
* @param parent the container to be laid out
|
||||
*/
|
||||
public void layoutContainer(Container parent)
|
||||
{
|
||||
checkComponents(parent);
|
||||
// -- Create 2D Component Array
|
||||
int rows = getRowCount();
|
||||
int cols = getColCount();
|
||||
Component[][] com = new Component[rows][cols];
|
||||
//
|
||||
Object[] keys = m_data.keySet().toArray();
|
||||
Arrays.sort(keys);
|
||||
for (int i = 0; i < keys.length; i++)
|
||||
{
|
||||
ALayoutConstraint constraint = (ALayoutConstraint)keys[i];
|
||||
Component component = (Component)m_data.get(keys[i]);
|
||||
if (component.isVisible())
|
||||
com [constraint.getRow()][constraint.getCol()] = component;
|
||||
else
|
||||
com [constraint.getRow()][constraint.getCol()] = null;
|
||||
}
|
||||
|
||||
// -- Calculate Column Size
|
||||
int[] colWidth = new int[cols];
|
||||
int[] rowHeight = new int[rows];
|
||||
int columnWidth = m_spaceV;
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
int width = 0;
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
Component component = com[r][c];
|
||||
if (component != null)
|
||||
{
|
||||
width = Math.max (width, component.getPreferredSize().width);
|
||||
rowHeight[r] = Math.max (rowHeight[r], component.getPreferredSize().height);
|
||||
}
|
||||
}
|
||||
colWidth[c] = width;
|
||||
columnWidth += width + m_spaceV;
|
||||
}
|
||||
|
||||
// -- Stretch/Squeeze Columns to fit target width
|
||||
int parentWidth = parent.getSize().width;
|
||||
double multiplier = (double)parentWidth / (double)columnWidth;
|
||||
if (multiplier < .5) // limit sqeezing
|
||||
multiplier = .5;
|
||||
for (int c = 0; c < cols; c++)
|
||||
colWidth[c] = (int) (colWidth[c] * multiplier);
|
||||
int spaceV = (int)(m_spaceV * multiplier);
|
||||
//
|
||||
// log.fine( "ALayout.layoutContainer",
|
||||
// "ParentWidth=" + parentWidth + ", ColumnWidth=" + columnWidth + ", SpaceV=" + spaceV + ", Multiplier=" + multiplier);
|
||||
|
||||
// -- Lay out components
|
||||
Insets insets = parent.getInsets();
|
||||
int posH = insets.top + m_spaceH;
|
||||
for (int r = 0; r < rows; r++)
|
||||
{
|
||||
int posV = insets.left + spaceV;
|
||||
int height = 0;
|
||||
for (int c = 0; c < cols; c++)
|
||||
{
|
||||
Component component = com[r][c];
|
||||
if (component != null)
|
||||
{
|
||||
Dimension ps = component.getPreferredSize();
|
||||
int w = ps.width;
|
||||
if (m_colFill || w > colWidth[c]) // limit or stretch
|
||||
w = colWidth[c];
|
||||
int h = ps.height;
|
||||
int topSpace = 0;
|
||||
if (h < rowHeight[r]) // push a little bit lower
|
||||
topSpace = (rowHeight[r] - h) / 3;
|
||||
height = Math.max(height, h);
|
||||
component.setBounds(posV, posH+topSpace, w, h);
|
||||
// log.fine( "ALayout.layoutContainer",
|
||||
// "Row=" + r + ", Col=" + c + ", PosV=" + posV + ", PosH=" + posH + "/" + topSpace + ", width=" + w + ", height=" + h);
|
||||
}
|
||||
posV += colWidth[c] + spaceV;
|
||||
} // for all columns
|
||||
posH += height + m_spaceH;
|
||||
} // for all rows
|
||||
} // layoutContainer
|
||||
|
||||
/**
|
||||
* Returns the alignment along the x axis. This specifies how
|
||||
* the component would like to be aligned relative to other
|
||||
* components. The value should be a number between 0 and 1
|
||||
* where 0 represents alignment along the origin, 1 is aligned
|
||||
* the furthest away from the origin, 0.5 is centered, etc.
|
||||
* @param target target
|
||||
* @return 0f
|
||||
*/
|
||||
public float getLayoutAlignmentX(Container target)
|
||||
{
|
||||
return 0f;
|
||||
} // getLayoutAlignmentX
|
||||
|
||||
/**
|
||||
* Returns the alignment along the y axis. This specifies how
|
||||
* the component would like to be aligned relative to other
|
||||
* components. The value should be a number between 0 and 1
|
||||
* where 0 represents alignment along the origin, 1 is aligned
|
||||
* the furthest away from the origin, 0.5 is centered, etc.
|
||||
* @param target target
|
||||
* @return 0f
|
||||
*/
|
||||
public float getLayoutAlignmentY(Container target)
|
||||
{
|
||||
return 0f;
|
||||
} // getLayoutAlignmentY
|
||||
|
||||
/**
|
||||
* Invalidates the layout, indicating that if the layout manager
|
||||
* has cached information it should be discarded.
|
||||
* @param target target
|
||||
*/
|
||||
public void invalidateLayout(Container target)
|
||||
{
|
||||
} // invalidateLayout
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Check target components and add components, which don't have no constraints
|
||||
* @param target target
|
||||
*/
|
||||
private void checkComponents (Container target)
|
||||
{
|
||||
int size = target.getComponentCount();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
Component comp = target.getComponent(i);
|
||||
if (!m_data.containsValue(comp))
|
||||
m_data.put(null, comp);
|
||||
}
|
||||
} // checkComponents
|
||||
|
||||
/**
|
||||
* Get Number of Rows
|
||||
* @return no pf rows
|
||||
*/
|
||||
public int getRowCount()
|
||||
{
|
||||
return m_data.getMaxRow()+1;
|
||||
} // getRowCount
|
||||
|
||||
/**
|
||||
* Get Number of Columns
|
||||
* @return no of cols
|
||||
*/
|
||||
public int getColCount()
|
||||
{
|
||||
return m_data.getMaxCol()+1;
|
||||
} // getColCount
|
||||
|
||||
/**
|
||||
* Set Horizontal Space (top, between rows, button)
|
||||
* @param spaceH horizontal space (top, between rows, button)
|
||||
*/
|
||||
public void setSpaceH (int spaceH)
|
||||
{
|
||||
m_spaceH = spaceH;
|
||||
} // setSpaceH
|
||||
|
||||
/**
|
||||
* Get Horizontal Space (top, between rows, button)
|
||||
* @return spaceH horizontal space (top, between rows, button)
|
||||
*/
|
||||
public int getSpaceH()
|
||||
{
|
||||
return m_spaceH;
|
||||
} // getSpaceH
|
||||
|
||||
/**
|
||||
* Set Vertical Space (left, between columns, right)
|
||||
* @param spaceV vertical space (left, between columns, right)
|
||||
*/
|
||||
public void setSpaceV(int spaceV)
|
||||
{
|
||||
m_spaceV = spaceV;
|
||||
} // setSpaceV
|
||||
|
||||
/**
|
||||
* Get Vertical Space (left, between columns, right)
|
||||
* @return spaceV vertical space (left, between columns, right)
|
||||
*/
|
||||
public int getSpaceV()
|
||||
{
|
||||
return m_spaceV;
|
||||
} // getSpaceV
|
||||
|
||||
} // ALayout
|
|
@ -0,0 +1,135 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.install.util;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Collection of Components ordered based on ALayoutConstraint
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: ALayoutCollection.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
|
||||
*/
|
||||
class ALayoutCollection extends HashMap<Object,Object>
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2906536401026546141L;
|
||||
|
||||
/**
|
||||
* Create Collection
|
||||
*/
|
||||
public ALayoutCollection()
|
||||
{
|
||||
super();
|
||||
} // ALayoutCollection
|
||||
|
||||
/**
|
||||
* Add a Component.
|
||||
* If constraint is null, it is added to the last row as additional column
|
||||
* @param constraint
|
||||
* @param component
|
||||
* @return component
|
||||
* @throws IllegalArgumentException if component is not a Component
|
||||
*/
|
||||
public Object put (Object constraint, Object component)
|
||||
{
|
||||
if (!(component instanceof Component))
|
||||
throw new IllegalArgumentException ("ALayoutCollection can only add Component values");
|
||||
|
||||
if (constraint != null
|
||||
&& !containsKey(constraint)
|
||||
&& constraint instanceof ALayoutConstraint)
|
||||
{
|
||||
// Log.trace(this,Log.l6_Database, "ALayoutCollection.put", constraint.toString());
|
||||
return super.put (constraint, component);
|
||||
}
|
||||
|
||||
// We need to create constraint
|
||||
if (super.size() == 0)
|
||||
{
|
||||
// Log.trace(this,Log.l6_Database, "ALayoutCollection.put - first");
|
||||
return super.put(new ALayoutConstraint(0,0), component);
|
||||
}
|
||||
|
||||
// Add to end of list
|
||||
int row = getMaxRow();
|
||||
if (row == -1)
|
||||
row = 0;
|
||||
int col = getMaxCol(row) + 1;
|
||||
ALayoutConstraint next = new ALayoutConstraint(row, col);
|
||||
// Log.trace(this,Log.l6_Database, "ALayoutCollection.put - addEnd", next.toString());
|
||||
return super.put(next, component);
|
||||
} // put
|
||||
|
||||
/**
|
||||
* Get Maximum Row Number
|
||||
* @return max row no - or -1 if no row
|
||||
*/
|
||||
public int getMaxRow ()
|
||||
{
|
||||
int maxRow = -1;
|
||||
//
|
||||
Iterator i = keySet().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
ALayoutConstraint c = (ALayoutConstraint)i.next();
|
||||
maxRow = Math.max(maxRow, c.getRow());
|
||||
}
|
||||
return maxRow;
|
||||
} // getMaxRow
|
||||
|
||||
/**
|
||||
* Get Maximum Column Number
|
||||
* @return max col no - or -1 if no column
|
||||
*/
|
||||
public int getMaxCol ()
|
||||
{
|
||||
int maxCol = -1;
|
||||
//
|
||||
Iterator i = keySet().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
ALayoutConstraint c = (ALayoutConstraint)i.next();
|
||||
maxCol = Math.max(maxCol, c.getCol());
|
||||
}
|
||||
return maxCol;
|
||||
} // getMaxCol
|
||||
|
||||
/**
|
||||
* Get Maximum Column Number for Row
|
||||
* @param row
|
||||
* @return max col no for row - or -1 if no col in row
|
||||
*/
|
||||
public int getMaxCol (int row)
|
||||
{
|
||||
int maxCol = -1;
|
||||
//
|
||||
Iterator i = keySet().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
ALayoutConstraint c = (ALayoutConstraint)i.next();
|
||||
if (c.getRow() == row)
|
||||
maxCol = Math.max(maxCol, c.getCol());
|
||||
}
|
||||
return maxCol;
|
||||
} // getMaxCol
|
||||
|
||||
} // ALayoutCollection
|
|
@ -0,0 +1,116 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.install.util;
|
||||
|
||||
|
||||
/**
|
||||
* Application Layout Constraint to indicate grid position (immutable)
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: ALayoutConstraint.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
|
||||
*/
|
||||
public class ALayoutConstraint implements Comparable
|
||||
{
|
||||
/**
|
||||
* Layout Constraint to indicate grid position
|
||||
* @param row row 0..x
|
||||
* @param col column 0..x
|
||||
*/
|
||||
public ALayoutConstraint(int row, int col)
|
||||
{
|
||||
m_row = row;
|
||||
m_col = col;
|
||||
} // ALayoutConstraint
|
||||
|
||||
/**
|
||||
* Create Next in Row
|
||||
* @return ALayoutConstraint for additional column in same row
|
||||
*/
|
||||
public ALayoutConstraint createNext()
|
||||
{
|
||||
return new ALayoutConstraint(m_row, m_col+1);
|
||||
} // createNext
|
||||
|
||||
private int m_row;
|
||||
private int m_col;
|
||||
|
||||
/**
|
||||
* Get Row
|
||||
* @return roe no
|
||||
*/
|
||||
public int getRow()
|
||||
{
|
||||
return m_row;
|
||||
} // getRow
|
||||
|
||||
/**
|
||||
* Get Column
|
||||
* @return col no
|
||||
*/
|
||||
public int getCol()
|
||||
{
|
||||
return m_col;
|
||||
} // getCol
|
||||
|
||||
/**
|
||||
* Compares this object with the specified object for order. Returns a
|
||||
* negative integer, zero, or a positive integer as this object is less
|
||||
* than, equal to, or greater than the specified object.<p>
|
||||
*
|
||||
* @param o the Object to be compared.
|
||||
* @return a negative integer if this object is less than the specified object,
|
||||
* zero if equal,
|
||||
* or a positive integer if this object is greater than the specified object.
|
||||
*/
|
||||
public int compareTo(Object o)
|
||||
{
|
||||
ALayoutConstraint comp = null;
|
||||
if (o instanceof ALayoutConstraint)
|
||||
comp = (ALayoutConstraint)o;
|
||||
if (comp == null)
|
||||
return +111;
|
||||
|
||||
// Row compare
|
||||
int rowComp = m_row - comp.getRow();
|
||||
if (rowComp != 0)
|
||||
return rowComp;
|
||||
// Column compare
|
||||
return m_col - comp.getCol();
|
||||
} // compareTo
|
||||
|
||||
/**
|
||||
* Is Object Equal
|
||||
* @param o
|
||||
* @return true if equal
|
||||
*/
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (o instanceof ALayoutConstraint)
|
||||
return compareTo(o) == 0;
|
||||
return false;
|
||||
} // equal
|
||||
|
||||
/**
|
||||
* To String
|
||||
* @return info
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return "ALayoutConstraint [Row=" + m_row + ", Col=" + m_col + "]";
|
||||
} // toString
|
||||
|
||||
} // ALayoutConstraint
|
|
@ -0,0 +1,315 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.install.util;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.AbstractButton;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
/**
|
||||
* Application Action.
|
||||
* Creates Action with MenuItem and Button, delegate execution of action to an attached ActionListener instance
|
||||
* The ActionCommand is translated for display
|
||||
* If translated text contains &, the next character is the Mnemonic
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: AppsAction.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
|
||||
*/
|
||||
public final class AppsAction extends AbstractAction
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 8522301377339185496L;
|
||||
|
||||
/**
|
||||
* Application Action
|
||||
*
|
||||
* @param action base action command - used as AD_Message for Text and Icon name
|
||||
* @param accelerator optional keystroke for accelerator
|
||||
* @param toggle is toggle action (maintains state)
|
||||
*/
|
||||
public AppsAction (String action, KeyStroke accelerator, boolean toggle)
|
||||
{
|
||||
this (action, accelerator, null, toggle);
|
||||
}
|
||||
/**
|
||||
* Application Action
|
||||
*
|
||||
* @param action base action command - used as AD_Message for Text and Icon name
|
||||
* @param accelerator optional keystroke for accelerator
|
||||
* @param text text, if null defered from action
|
||||
*/
|
||||
public AppsAction (String action, KeyStroke accelerator, String text)
|
||||
{
|
||||
this (action, accelerator, text, false);
|
||||
} // AppsAction
|
||||
|
||||
/**
|
||||
* Application Action
|
||||
*
|
||||
* @param action base action command - used as AD_Message for Text and Icon name
|
||||
* @param accelerator optional keystroke for accelerator
|
||||
* @param toolTipText text, if null defered from action
|
||||
* @param toggle is toggle action (maintains state)
|
||||
*/
|
||||
public AppsAction (String action, KeyStroke accelerator, String toolTipText, boolean toggle)
|
||||
{
|
||||
super();
|
||||
m_action = action;
|
||||
m_accelerator = accelerator;
|
||||
m_toggle = toggle;
|
||||
|
||||
// Data
|
||||
if (toolTipText == null)
|
||||
toolTipText = Msg.getMsg(Env.getCtx(), action);
|
||||
int pos = toolTipText.indexOf('&');
|
||||
if (pos != -1 && toolTipText.length() > pos) // We have a nemonic - creates ALT-_
|
||||
{
|
||||
Character ch = new Character(toolTipText.toUpperCase().charAt(pos+1));
|
||||
if (ch != ' ')
|
||||
{
|
||||
toolTipText = toolTipText.substring(0, pos) + toolTipText.substring(pos+1);
|
||||
putValue(Action.MNEMONIC_KEY, new Integer(ch.hashCode()));
|
||||
}
|
||||
}
|
||||
//
|
||||
Icon small = getIcon(action, true);
|
||||
Icon large = getIcon(action, false);
|
||||
Icon largePressed = null;
|
||||
|
||||
// ToggleIcons have the pressed name with X
|
||||
if (m_toggle)
|
||||
{
|
||||
m_smallPressed = getIcon(action+"X", true);
|
||||
if (m_smallPressed == null)
|
||||
m_smallPressed = small;
|
||||
largePressed = getIcon(action+"X", false);
|
||||
if (largePressed == null)
|
||||
largePressed = large;
|
||||
}
|
||||
|
||||
// Attributes
|
||||
putValue(Action.NAME, toolTipText); // Display
|
||||
putValue(Action.SMALL_ICON, small); // Icon
|
||||
putValue(Action.SHORT_DESCRIPTION, toolTipText); // Tooltip
|
||||
putValue(Action.ACTION_COMMAND_KEY, m_action); // ActionCammand
|
||||
putValue(Action.ACCELERATOR_KEY, accelerator); // KeyStroke
|
||||
// putValue(Action.MNEMONIC_KEY, new Integer(0)); // Mnemonic
|
||||
// putValue(Action.DEFAULT, text); // Not Used
|
||||
|
||||
// Create Button
|
||||
if (toggle)
|
||||
{
|
||||
m_button = new JToggleButton(this);
|
||||
m_button.setSelectedIcon(largePressed);
|
||||
}
|
||||
else
|
||||
m_button = new JButton(this);
|
||||
m_button.setName(action);
|
||||
// Correcting Action items
|
||||
if (large != null)
|
||||
{
|
||||
m_button.setIcon(large);
|
||||
m_button.setText(null);
|
||||
}
|
||||
m_button.setActionCommand(m_action);
|
||||
m_button.setMargin(BUTTON_INSETS);
|
||||
m_button.setSize(BUTTON_SIZE);
|
||||
//
|
||||
if (accelerator != null)
|
||||
{
|
||||
m_button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(accelerator, action);
|
||||
m_button.getActionMap().put(action, this);
|
||||
}
|
||||
} // Action
|
||||
|
||||
/** Button Size */
|
||||
public static final Dimension BUTTON_SIZE = new Dimension(28,28);
|
||||
/** Button Insets */
|
||||
public static final Insets BUTTON_INSETS = new Insets(0, 0, 0, 0);
|
||||
/** CButton or CToggelButton */
|
||||
private AbstractButton m_button;
|
||||
/** Menu */
|
||||
private JMenuItem m_menu;
|
||||
|
||||
private String m_action = null;
|
||||
private KeyStroke m_accelerator = null;
|
||||
private Icon m_smallPressed = null;
|
||||
private ActionListener m_delegate = null;
|
||||
private boolean m_toggle = false;
|
||||
private boolean m_pressed = false;
|
||||
|
||||
/**
|
||||
* Get Icon with name action
|
||||
* @param name name
|
||||
* @param small small
|
||||
* @return Icon
|
||||
*/
|
||||
private ImageIcon getIcon(String name, boolean small)
|
||||
{
|
||||
String fullName = name + (small ? "16" : "24");
|
||||
return Env.getImageIcon2(fullName);
|
||||
} // getIcon
|
||||
|
||||
/**
|
||||
* Get Name/ActionCommand
|
||||
* @return ActionName
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return m_action;
|
||||
} // getName
|
||||
|
||||
/**
|
||||
* Return Button
|
||||
* @return Button
|
||||
*/
|
||||
public AbstractButton getButton()
|
||||
{
|
||||
return m_button;
|
||||
} // getButton
|
||||
|
||||
/**
|
||||
* Return MenuItem
|
||||
* @return MenuItem
|
||||
*/
|
||||
public JMenuItem getMenuItem()
|
||||
{
|
||||
if (m_menu == null)
|
||||
{
|
||||
if (m_toggle)
|
||||
{
|
||||
m_menu = new JCheckBoxMenuItem(this);
|
||||
m_menu.setSelectedIcon(m_smallPressed);
|
||||
}
|
||||
else
|
||||
m_menu = new JMenuItem(this);
|
||||
m_menu.setAccelerator(m_accelerator);
|
||||
m_menu.setActionCommand(m_action);
|
||||
}
|
||||
return m_menu;
|
||||
} // getMenuItem
|
||||
|
||||
/**
|
||||
* Set Delegate to receive the actionPerformed calls
|
||||
* @param al listener
|
||||
*/
|
||||
public void setDelegate(ActionListener al)
|
||||
{
|
||||
m_delegate = al;
|
||||
} // setDelegate
|
||||
|
||||
/**
|
||||
* Toggle
|
||||
* @param pressed pressed
|
||||
*/
|
||||
public void setPressed (boolean pressed)
|
||||
{
|
||||
if (!m_toggle)
|
||||
return;
|
||||
m_pressed = pressed;
|
||||
|
||||
// Set Button
|
||||
if (m_button != null)
|
||||
m_button.setSelected(pressed);
|
||||
|
||||
// Set Menu
|
||||
if (m_menu != null)
|
||||
m_menu.setSelected(pressed);
|
||||
} // setPressed
|
||||
|
||||
/**
|
||||
* IsPressed
|
||||
* @return true if pressed
|
||||
*/
|
||||
public boolean isPressed()
|
||||
{
|
||||
return m_pressed;
|
||||
} // isPressed
|
||||
|
||||
/**
|
||||
* Get Mnemonic character
|
||||
* @return character
|
||||
*/
|
||||
public Character getMnemonic()
|
||||
{
|
||||
Object oo = getValue(Action.MNEMONIC_KEY);
|
||||
if (oo instanceof Integer)
|
||||
return (char)((Integer)oo).intValue();
|
||||
return null;
|
||||
} // getMnemonic
|
||||
|
||||
/**
|
||||
* ActionListener
|
||||
* @param e Event
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
// log.info( "AppsAction.actionPerformed", e.getActionCommand());
|
||||
// Toggle Items
|
||||
if (m_toggle)
|
||||
setPressed(!m_pressed);
|
||||
// Inform
|
||||
if (m_delegate != null)
|
||||
m_delegate.actionPerformed(e);
|
||||
} // actionPerformed
|
||||
|
||||
/**
|
||||
* Dispose
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
m_button = null;
|
||||
m_menu = null;
|
||||
} // dispose
|
||||
|
||||
/**
|
||||
* String Info
|
||||
* @return String Representation
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer sb = new StringBuffer("AppsAction[");
|
||||
sb.append(m_action);
|
||||
Object oo = getValue(Action.ACCELERATOR_KEY);
|
||||
if (oo != null)
|
||||
sb.append(",Accelerator=").append(oo);
|
||||
oo = getMnemonic();
|
||||
if (oo != null)
|
||||
sb.append(",MnemonicKey=").append(oo);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
} // toString
|
||||
|
||||
} // AppsAction
|
|
@ -0,0 +1,739 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.install.util;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRootPane;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
|
||||
/**
|
||||
* Application Confirm Panel.
|
||||
* <code>
|
||||
* if (e.getActionCommand().equals(ConfirmPanel.A_OK))
|
||||
* </code>
|
||||
* @author Jorg Janke
|
||||
* @version $Id: ConfirmPanel.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
|
||||
*/
|
||||
public final class ConfirmPanel extends JPanel
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6041019802043360966L;
|
||||
|
||||
|
||||
/**
|
||||
* Create OK Button with label text and F4 Shortcut
|
||||
* @param text text
|
||||
* @return OK Button
|
||||
*/
|
||||
public static final JButton createOKButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_OK, KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
button.setDefaultCapable(true);
|
||||
return button;
|
||||
} // createOKButton
|
||||
|
||||
/**
|
||||
* Create OK Button with Standard text
|
||||
* @param withText with text
|
||||
* @return OK Button
|
||||
*/
|
||||
public static final JButton createOKButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createOKButton(Msg.getMsg(Env.getCtx(), A_OK));
|
||||
return createOKButton("");
|
||||
} // createOKButton
|
||||
|
||||
/**
|
||||
* Create Cancel Button wlth label text and register ESC as KeyStroke
|
||||
* @param text text
|
||||
* @return Cancel Button
|
||||
*/
|
||||
public static final JButton createCancelButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_CANCEL, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createCancelButton
|
||||
|
||||
/**
|
||||
* Create Cancel Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createCancelButton(boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createCancelButton(Msg.getMsg(Env.getCtx(), A_CANCEL));
|
||||
return createCancelButton("");
|
||||
} // createCancelButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create Refresh Button wlth label text and F5
|
||||
* @param text text
|
||||
* @return button
|
||||
*/
|
||||
public static final JButton createRefreshButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_REFRESH, KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createRefreshButton
|
||||
|
||||
/**
|
||||
* Create Refresh Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createRefreshButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createRefreshButton(Msg.getMsg(Env.getCtx(), A_REFRESH));
|
||||
return createRefreshButton("");
|
||||
} // createRefreshButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create Reset Button wlth label text
|
||||
* @param text text
|
||||
* @return button
|
||||
*/
|
||||
public static final JButton createResetButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_RESET, null, text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createResetButton
|
||||
|
||||
/**
|
||||
* Create Reset Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createResetButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createResetButton(Msg.getMsg(Env.getCtx(), A_RESET));
|
||||
return createResetButton(null);
|
||||
} // createRefreshButton
|
||||
|
||||
/************************
|
||||
* Create Customize Button wlth label text
|
||||
* @param text text
|
||||
* @return button
|
||||
*/
|
||||
public static final JButton createCustomizeButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_CUSTOMIZE, null, text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
// Env.getImageIcon("Preference24.gif"));
|
||||
} // createCustomizeButton
|
||||
|
||||
/**
|
||||
* Create Customize Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createCustomizeButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createCustomizeButton(Msg.getMsg(Env.getCtx(), A_CUSTOMIZE));
|
||||
return createCustomizeButton(null);
|
||||
} // createCustomizeButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create History Button wlth label text
|
||||
* @param text text
|
||||
* @return button
|
||||
*/
|
||||
public static final JButton createHistoryButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_HISTORY, KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0), text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
// Env.getImageIcon("HistoryX24.gif"));
|
||||
} // createHistoryButton
|
||||
|
||||
/**
|
||||
* Create History Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createHistoryButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createHistoryButton(Msg.getMsg(Env.getCtx(), A_HISTORY));
|
||||
return createHistoryButton(null);
|
||||
} // createHistoryButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create Zoom Button wlth label text
|
||||
* @param text text
|
||||
* @return button
|
||||
*/
|
||||
public static final JButton createZoomButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_ZOOM, null, text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createZoomButton
|
||||
|
||||
/**
|
||||
* Create Zoom Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createZoomButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createZoomButton(Msg.getMsg(Env.getCtx(), A_ZOOM));
|
||||
return createZoomButton(null);
|
||||
} // createZoomButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create Process Button wlth label text Shift-F4
|
||||
* @param text text
|
||||
* @return button
|
||||
*/
|
||||
public static final JButton createProcessButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_PROCESS,
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_F4, KeyEvent.SHIFT_MASK), text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createProcessButton
|
||||
|
||||
/**
|
||||
* Create Process Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createProcessButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createProcessButton(Msg.getMsg(Env.getCtx(), A_PROCESS));
|
||||
return createProcessButton(null);
|
||||
} // createProcessButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create Print Button wlth label text
|
||||
* @param text text
|
||||
* @return button
|
||||
*/
|
||||
public static final JButton createPrintButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_PRINT, KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createPrintButton
|
||||
|
||||
/**
|
||||
* Create Print Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createPrintButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createPrintButton(Msg.getMsg(Env.getCtx(), A_PRINT));
|
||||
return createPrintButton(null);
|
||||
} // createPrintButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create Help Button wlth label text
|
||||
* @param text text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createHelpButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_HELP, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createHelpButton
|
||||
|
||||
/**
|
||||
* Create Help Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createHelpButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createHelpButton(Msg.getMsg(Env.getCtx(), A_HELP));
|
||||
return createHelpButton(null);
|
||||
} // createHelpButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create Export Button wlth label text
|
||||
* @param text text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createExportButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_EXPORT, null, text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createExportButton
|
||||
|
||||
/**
|
||||
* Create Export Button wlth Standard text
|
||||
* @param withText with text
|
||||
* @return Button
|
||||
*/
|
||||
public static final JButton createExportButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createExportButton(Msg.getMsg(Env.getCtx(), A_EXPORT));
|
||||
return createExportButton(null);
|
||||
} // createExportButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create Delete Button with label text - F3
|
||||
* @param text text
|
||||
* @return Delete Button
|
||||
*/
|
||||
public static final JButton createDeleteButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_DELETE, KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createDeleteButton
|
||||
|
||||
/**
|
||||
* Create Delete Button with Standard text
|
||||
* @param withText with text
|
||||
* @return Delete Button
|
||||
*/
|
||||
public static final JButton createDeleteButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createDeleteButton(Msg.getMsg(Env.getCtx(), A_DELETE));
|
||||
return createDeleteButton(null);
|
||||
} // createDeleteButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create Product Attribute Button with Standard text
|
||||
* @param withText with text
|
||||
* @return Product Attribute Button
|
||||
*/
|
||||
public static final JButton createPAttributeButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createPAttributeButton(Msg.getMsg(Env.getCtx(), A_PATTRIBUTE));
|
||||
return createPAttributeButton(null);
|
||||
} // createPAttributeButton
|
||||
|
||||
/**
|
||||
* Create Product Attribute Button with label text
|
||||
* @param text text
|
||||
* @return Product Attribute Button
|
||||
*/
|
||||
public static final JButton createPAttributeButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_PATTRIBUTE, null, text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createPAttributeButton
|
||||
|
||||
|
||||
/************************
|
||||
* Create New Button with Standard text
|
||||
* @param withText with text
|
||||
* @return New Button
|
||||
*/
|
||||
public static final JButton createNewButton (boolean withText)
|
||||
{
|
||||
if (withText)
|
||||
return createNewButton(Msg.getMsg(Env.getCtx(), A_NEW));
|
||||
return createNewButton(null);
|
||||
} // createNewButton
|
||||
|
||||
/**
|
||||
* Create New Button with label text - F2
|
||||
* @param text text
|
||||
* @return Product Attribute Button
|
||||
*/
|
||||
public static final JButton createNewButton (String text)
|
||||
{
|
||||
AppsAction aa = new AppsAction (A_NEW, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0), text);
|
||||
JButton button = (JButton)aa.getButton();
|
||||
button.setMargin(s_insets);
|
||||
return button;
|
||||
} // createNewButton
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/** Action String OK */
|
||||
public static final String A_OK = "Ok";
|
||||
/** Action String Cancel */
|
||||
public static final String A_CANCEL = "Cancel";
|
||||
/** Action String Refresh */
|
||||
public static final String A_REFRESH = "Refresh";
|
||||
/** Action String Reset */
|
||||
public static final String A_RESET = "Reset";
|
||||
/** Action String Customize */
|
||||
public static final String A_CUSTOMIZE = "Customize";
|
||||
/** Action String History */
|
||||
public static final String A_HISTORY = "History";
|
||||
/** Action String Zoom */
|
||||
public static final String A_ZOOM = "Zoom";
|
||||
|
||||
/** Action String Process */
|
||||
public static final String A_PROCESS = "Process";
|
||||
/** Action String Print */
|
||||
public static final String A_PRINT = "Print";
|
||||
/** Action String Export */
|
||||
public static final String A_EXPORT = "Export";
|
||||
/** Action String Help */
|
||||
public static final String A_HELP = "Help";
|
||||
/** Action String Delete */
|
||||
public static final String A_DELETE = "Delete";
|
||||
/** Action String PAttribute */
|
||||
public static final String A_PATTRIBUTE = "PAttribute";
|
||||
/** Action String New */
|
||||
public static final String A_NEW = "New";
|
||||
|
||||
/** Standard Insets used */
|
||||
public static Insets s_insets = new Insets (0, 10, 0, 10);
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Create Confirmation Panel with OK Button
|
||||
*/
|
||||
public ConfirmPanel()
|
||||
{
|
||||
this (false, false, false, false, false, false, true);
|
||||
} // ConfirmPanel
|
||||
|
||||
/**
|
||||
* Create Confirmation Panel with OK and Cancel Button
|
||||
* @param withCancelButton with cancel
|
||||
*/
|
||||
public ConfirmPanel(boolean withCancelButton)
|
||||
{
|
||||
this (withCancelButton, false, false, false, false, false, true);
|
||||
} // ConfirmPanel
|
||||
|
||||
/**
|
||||
* Create Confirmation Panel with different buttons
|
||||
* @param withCancelButton with cancel
|
||||
* @param withRefreshButton with refresh
|
||||
* @param withResetButton with reset
|
||||
* @param withCustomizeButton with customize
|
||||
* @param withHistoryButton with history
|
||||
* @param withZoomButton with zoom
|
||||
* @param withText with text
|
||||
*/
|
||||
public ConfirmPanel(boolean withCancelButton,
|
||||
boolean withRefreshButton,
|
||||
boolean withResetButton,
|
||||
boolean withCustomizeButton,
|
||||
boolean withHistoryButton,
|
||||
boolean withZoomButton,
|
||||
boolean withText)
|
||||
{
|
||||
super();
|
||||
BorderLayout mainLayout = new BorderLayout();
|
||||
this.setLayout(mainLayout);
|
||||
this.setName("confirmPanel");
|
||||
//
|
||||
JPanel okCancel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
okCancel.setOpaque(false);
|
||||
bCancel = createCancelButton(withText);
|
||||
okCancel.add(bCancel);
|
||||
bOK = createOKButton(withText);
|
||||
okCancel.add(bOK);
|
||||
setCancelVisible(withCancelButton);
|
||||
this.add(okCancel, BorderLayout.EAST);
|
||||
//
|
||||
if (withRefreshButton)
|
||||
{
|
||||
bRefresh = createRefreshButton(withText);
|
||||
addComponent(bRefresh);
|
||||
}
|
||||
if (withResetButton)
|
||||
{
|
||||
bReset = createResetButton(withText);
|
||||
addComponent(bReset);
|
||||
}
|
||||
if (withCustomizeButton)
|
||||
{
|
||||
bCustomize = createCustomizeButton(withText);
|
||||
addComponent(bCustomize);
|
||||
}
|
||||
if (withHistoryButton)
|
||||
{
|
||||
bHistory = createHistoryButton(withText);
|
||||
addComponent(bHistory);
|
||||
}
|
||||
if (withZoomButton)
|
||||
{
|
||||
bZoom = createZoomButton(withText);
|
||||
addComponent(bZoom);
|
||||
}
|
||||
} // ConfirmPanel
|
||||
|
||||
/** Additional Buttons Panel */
|
||||
private JPanel m_addlButtons = null;
|
||||
|
||||
private JButton bOK;
|
||||
private JButton bCancel;
|
||||
//
|
||||
private JButton bRefresh;
|
||||
private JButton bReset;
|
||||
private JButton bCustomize;
|
||||
private JButton bHistory;
|
||||
private JButton bZoom;
|
||||
|
||||
/**
|
||||
* Add Button to left side of confirmPanel
|
||||
* @param button button
|
||||
*/
|
||||
public void addComponent (Component button)
|
||||
{
|
||||
if (m_addlButtons == null)
|
||||
{
|
||||
m_addlButtons = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
this.add(m_addlButtons, BorderLayout.WEST);
|
||||
}
|
||||
m_addlButtons.add(button);
|
||||
} // addButton
|
||||
|
||||
/**
|
||||
* Add Button to left side of confirmPanel
|
||||
* @param action action command
|
||||
* @param toolTipText tool tip text
|
||||
* @param icon icon
|
||||
* @return JButton
|
||||
*/
|
||||
public JButton addButton (String action, String toolTipText, Icon icon)
|
||||
{
|
||||
AppsAction aa = new AppsAction(action, null, toolTipText);
|
||||
JButton b = (JButton)aa.getButton();
|
||||
// new DialogButton (action, toolTipText, icon);
|
||||
addComponent (b);
|
||||
return b;
|
||||
} // addButton
|
||||
|
||||
/**
|
||||
* Add Button to left side of confirmPanel
|
||||
* @param button button
|
||||
* @return JButton
|
||||
*/
|
||||
public JButton addButton (JButton button)
|
||||
{
|
||||
addComponent (button);
|
||||
return button;
|
||||
} // addButton
|
||||
|
||||
/**
|
||||
* Get OK Button
|
||||
* @return OK Button
|
||||
*/
|
||||
public JButton getOKButton()
|
||||
{
|
||||
return bOK;
|
||||
} // getOKButton
|
||||
|
||||
/**
|
||||
* Get Cancel Button
|
||||
* @return Cancel Button
|
||||
*/
|
||||
public JButton getCancelButton()
|
||||
{
|
||||
return bCancel;
|
||||
} // getCancelButton
|
||||
|
||||
/**
|
||||
* Show OK button
|
||||
* @param value true for visible
|
||||
*/
|
||||
public void setOKVisible (boolean value)
|
||||
{
|
||||
bOK.setVisible(value);
|
||||
bOK.setEnabled(value);
|
||||
} // setOKVisible
|
||||
|
||||
/**
|
||||
* Is OK Visible
|
||||
* @return true of OK visisble
|
||||
*/
|
||||
public boolean isOKVisible()
|
||||
{
|
||||
return bOK.isVisible();
|
||||
} // isOKVisible
|
||||
|
||||
/**
|
||||
* Show Cancel button
|
||||
* @param value trie for visible
|
||||
*/
|
||||
public void setCancelVisible (boolean value)
|
||||
{
|
||||
bCancel.setVisible(value);
|
||||
bCancel.setEnabled(value);
|
||||
} // setCancelVisible
|
||||
|
||||
/**
|
||||
* Is Cancel Visible
|
||||
* @return true if Canvel is visible
|
||||
*/
|
||||
public boolean isCancelVisible()
|
||||
{
|
||||
return bCancel.isVisible();
|
||||
} // isCancelVisible
|
||||
|
||||
/**
|
||||
* Get Reset Button
|
||||
* @return Button
|
||||
*/
|
||||
public JButton getResetButton()
|
||||
{
|
||||
return bReset;
|
||||
} // getResetButton
|
||||
|
||||
/**
|
||||
* Get Customize Button
|
||||
* @return Button
|
||||
*/
|
||||
public JButton getCustomizeButton()
|
||||
{
|
||||
return bCustomize;
|
||||
} // getCustomizeButton
|
||||
|
||||
/**
|
||||
* Get History Button
|
||||
* @return Button
|
||||
*/
|
||||
public JButton getHistoryButton()
|
||||
{
|
||||
return bHistory;
|
||||
} // getHistoryButton
|
||||
|
||||
/**
|
||||
* Get Zoom Button
|
||||
* @return Button
|
||||
*/
|
||||
public JButton getZoomButton()
|
||||
{
|
||||
return bZoom;
|
||||
} // getZoomyButton
|
||||
|
||||
/**
|
||||
* Get Refresh Button
|
||||
* @return Button
|
||||
*/
|
||||
public JButton getRefreshButton()
|
||||
{
|
||||
return bRefresh;
|
||||
} // getRefreshButton
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Add Action Listener
|
||||
* <code>
|
||||
* if (e.getActionCommand().equals(ConfirmPanel.A_OK))
|
||||
* </code>
|
||||
* @param al listener
|
||||
*/
|
||||
public void addActionListener(ActionListener al)
|
||||
{
|
||||
((AppsAction)bOK.getAction()).setDelegate(al);
|
||||
((AppsAction)bCancel.getAction()).setDelegate(al);
|
||||
//
|
||||
if (bRefresh != null)
|
||||
((AppsAction)bRefresh.getAction()).setDelegate(al);
|
||||
if (bReset != null)
|
||||
((AppsAction)bReset.getAction()).setDelegate(al);
|
||||
if (bCustomize != null)
|
||||
((AppsAction)bCustomize.getAction()).setDelegate(al);
|
||||
if (bHistory != null)
|
||||
((AppsAction)bHistory.getAction()).setDelegate(al);
|
||||
if (bZoom != null)
|
||||
((AppsAction)bZoom.getAction()).setDelegate(al);
|
||||
|
||||
// Set OK as default Button
|
||||
JRootPane rootpane = null;
|
||||
if (al instanceof JDialog)
|
||||
rootpane = ((JDialog)al).getRootPane();
|
||||
else if (al instanceof JFrame)
|
||||
rootpane = ((JFrame)al).getRootPane();
|
||||
if (rootpane != null)
|
||||
rootpane.setDefaultButton(bOK);
|
||||
} // addActionListener
|
||||
|
||||
/**
|
||||
* Enable all components
|
||||
* @param enabled trie if enabled
|
||||
*/
|
||||
public void setEnabled (boolean enabled)
|
||||
{
|
||||
super.setEnabled(enabled);
|
||||
bOK.setEnabled(enabled);
|
||||
bCancel.setEnabled(enabled);
|
||||
//
|
||||
if (bRefresh != null)
|
||||
bRefresh.setEnabled(enabled);
|
||||
if (bCustomize != null)
|
||||
bCustomize.setEnabled(enabled);
|
||||
if (bHistory != null)
|
||||
bHistory.setEnabled(enabled);
|
||||
if (bZoom != null)
|
||||
bZoom.setEnabled(enabled);
|
||||
} // setEnabled
|
||||
|
||||
} // ConfirmPanel
|
|
@ -0,0 +1,338 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
* Contributor: Carlos Ruiz - globalqss *
|
||||
*****************************************************************************/
|
||||
package org.compiere.install.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.ConnectException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.html.HTML;
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
|
||||
|
||||
import org.compiere.util.Env;
|
||||
|
||||
/**
|
||||
* Online Help Browser & Link.
|
||||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: OnlineHelp.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $
|
||||
*
|
||||
* globalqss: fix error about null pointer in OnlineHelp.Worker.run
|
||||
* change the URL for online help for connection
|
||||
*/
|
||||
public class OnlineHelp extends JEditorPane implements HyperlinkListener
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -7201158578463954623L;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public OnlineHelp()
|
||||
{
|
||||
super ();
|
||||
setEditable (false);
|
||||
setContentType ("text/html");
|
||||
addHyperlinkListener (this);
|
||||
} // OnlineHelp
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param url URL to load
|
||||
*/
|
||||
public OnlineHelp (String url)
|
||||
{
|
||||
this();
|
||||
try
|
||||
{
|
||||
if (url != null && url.length() > 0)
|
||||
setPage(url);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("OnlineHelp URL=" + url + " - " + e);
|
||||
}
|
||||
} // OnlineHelp
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param loadOnline load online URL
|
||||
*/
|
||||
public OnlineHelp (boolean loadOnline)
|
||||
{
|
||||
this (loadOnline ? BASE_URL : null);
|
||||
} // OnlineHelp
|
||||
|
||||
/** Base of Online Help System */
|
||||
protected static final String BASE_URL = "http://www.adempiere.com/wiki/index.php/OnlineLoginHelp";
|
||||
|
||||
public static void openInDefaultBrowser()
|
||||
{
|
||||
Env.startBrowser(BASE_URL);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* Hyperlink Listener
|
||||
* @param e event
|
||||
*/
|
||||
public void hyperlinkUpdate (HyperlinkEvent e)
|
||||
{
|
||||
// System.out.println("OnlineHelp.hyperlinkUpdate - " + e.getDescription() + " " + e.getURL());
|
||||
if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
|
||||
return;
|
||||
|
||||
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||
//
|
||||
if (e instanceof HTMLFrameHyperlinkEvent)
|
||||
{
|
||||
HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent)e;
|
||||
HTMLDocument doc = (HTMLDocument)getDocument();
|
||||
doc.processHTMLFrameHyperlinkEvent(evt);
|
||||
}
|
||||
else if (e.getURL() == null)
|
||||
// remove # of the reference
|
||||
scrollToReference(e.getDescription().substring(1));
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
setPage(e.getURL());
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
System.err.println("Help.hyperlinkUpdate - " + t.toString());
|
||||
displayError("Error", e.getURL(), t);
|
||||
}
|
||||
}
|
||||
this.setCursor(Cursor.getDefaultCursor());
|
||||
} // hyperlinkUpdate
|
||||
|
||||
/**
|
||||
* Set Text
|
||||
* @param text text
|
||||
*/
|
||||
public void setText (String text)
|
||||
{
|
||||
super.setText(text);
|
||||
setCaretPosition(0); // scroll to top
|
||||
} // setText
|
||||
|
||||
/**
|
||||
* Load URL async
|
||||
* @param url url
|
||||
*/
|
||||
public void setPage (final URL url)
|
||||
{
|
||||
setBackground (Color.white);
|
||||
Runnable pgm = new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
loadPage(url);
|
||||
}
|
||||
};
|
||||
new Thread(pgm).start();
|
||||
} // setPage
|
||||
|
||||
/**
|
||||
* Load Page Async
|
||||
* @param url url
|
||||
*/
|
||||
private void loadPage (URL url)
|
||||
{
|
||||
try
|
||||
{
|
||||
super.setPage(url);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
displayError("Error: URL not found", url, e);
|
||||
}
|
||||
} // loadPage
|
||||
|
||||
/**
|
||||
* Display Error message
|
||||
* @param header header
|
||||
* @param url url
|
||||
* @param exception exception
|
||||
*/
|
||||
protected void displayError (String header, Object url, Object exception)
|
||||
{
|
||||
StringBuffer msg = new StringBuffer ("<HTML><BODY>");
|
||||
msg.append("<H1>").append(header).append("</H1>")
|
||||
.append("<H3>URL=").append(url).append("</H3>")
|
||||
.append("<H3>Error=").append(exception).append("</H3>")
|
||||
.append("<p>© Adempiere ")
|
||||
.append("<A HREF=\"").append(BASE_URL).append ("\">Online Help</A></p>")
|
||||
.append("</BODY></HTML>");
|
||||
setText(msg.toString());
|
||||
} // displayError
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/** Online links.
|
||||
* Key=AD_Window_ID (as String) - Value=URL
|
||||
*/
|
||||
private static HashMap<String,String> s_links = new HashMap<String,String>();
|
||||
static
|
||||
{
|
||||
new Worker (BASE_URL, s_links).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Online Help available.
|
||||
* @return true if available
|
||||
*/
|
||||
public static boolean isAvailable()
|
||||
{
|
||||
return s_links.size() != 0;
|
||||
} // isAvailable
|
||||
|
||||
} // OnlineHelp
|
||||
|
||||
/**
|
||||
* Online Help Worker
|
||||
*/
|
||||
class Worker extends Thread
|
||||
{
|
||||
/**
|
||||
* Worker Constructor
|
||||
* @param urlString url
|
||||
* @param links links
|
||||
*/
|
||||
Worker (String urlString, HashMap<String,String> links)
|
||||
{
|
||||
m_urlString = urlString;
|
||||
m_links = links;
|
||||
setPriority(Thread.MIN_PRIORITY);
|
||||
} // Worker
|
||||
|
||||
private String m_urlString = null;
|
||||
private HashMap<String,String> m_links = null;
|
||||
|
||||
/**
|
||||
* Worker: Read available Online Help Pages
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
if (m_links == null)
|
||||
return;
|
||||
URL url = null;
|
||||
try
|
||||
{
|
||||
url = new URL (m_urlString);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("OnlineHelp.Worker.run (url) - " + e);
|
||||
}
|
||||
if (url == null)
|
||||
return;
|
||||
|
||||
// Read Reference Page
|
||||
try
|
||||
{
|
||||
URLConnection conn = url.openConnection();
|
||||
InputStream is = conn.getInputStream();
|
||||
HTMLEditorKit kit = new HTMLEditorKit();
|
||||
HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
|
||||
doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
|
||||
kit.read (new InputStreamReader(is), doc, 0);
|
||||
|
||||
// Get The Links to the Help Pages
|
||||
HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
|
||||
Object target = null;
|
||||
Object href = null;
|
||||
while (it != null && it.isValid())
|
||||
{
|
||||
AttributeSet as = it.getAttributes();
|
||||
// ~ href=/help/100/index.html target=Online title=My Test
|
||||
// System.out.println("~ " + as);
|
||||
|
||||
// key keys
|
||||
if (target == null || href == null)
|
||||
{
|
||||
Enumeration<?> en = as.getAttributeNames();
|
||||
while (en.hasMoreElements())
|
||||
{
|
||||
Object o = en.nextElement();
|
||||
if (target == null && o.toString().equals("target"))
|
||||
target = o; // javax.swing.text.html.HTML$Attribute
|
||||
else if (href == null && o.toString().equals("href"))
|
||||
href = o;
|
||||
}
|
||||
}
|
||||
|
||||
if (target != null && "Online".equals(as.getAttribute(target)))
|
||||
{
|
||||
// Format: /help/<AD_Window_ID>/index.html
|
||||
String hrefString = (String)as.getAttribute(href);
|
||||
if (hrefString != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// System.err.println(hrefString);
|
||||
String AD_Window_ID = hrefString.substring(hrefString.indexOf('/',1), hrefString.lastIndexOf('/'));
|
||||
m_links.put(AD_Window_ID, hrefString);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("OnlineHelp.Worker.run (help) - " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
it.next();
|
||||
}
|
||||
is.close();
|
||||
}
|
||||
catch (ConnectException e)
|
||||
{
|
||||
// System.err.println("OnlineHelp.Worker.run URL=" + url + " - " + e);
|
||||
}
|
||||
catch (UnknownHostException uhe)
|
||||
{
|
||||
// System.err.println("OnlineHelp.Worker.run " + uhe);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.err.println("OnlineHelp.Worker.run (e) " + e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
System.err.println("OnlineHelp.Worker.run (t) " + t);
|
||||
// t.printStackTrace();
|
||||
}
|
||||
// System.out.println("OnlineHelp - Links=" + m_links.size());
|
||||
} // run
|
||||
} // Worker
|
|
@ -0,0 +1,221 @@
|
|||
/******************************************************************************
|
||||
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. This program is distributed in the hope *
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||
* See the GNU General Public License for more details. *
|
||||
* You should have received a copy of the GNU General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
* For the text or an alternative of this public license, you may reach us *
|
||||
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
|
||||
* or via info@compiere.org or http://www.compiere.org/license.html *
|
||||
*****************************************************************************/
|
||||
package org.compiere.install.util;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
/**
|
||||
* SwingWorker (based on SwingWorker 3).
|
||||
* To use the SwingWorker class, you create a subclass of it.
|
||||
* In the subclass, you must implement the construct() method contains
|
||||
* the code to perform your lengthy operation.
|
||||
* You invoke start() on your SwingWorker object to start the thread,
|
||||
* which then calls your construct() method.
|
||||
* When you need the object returned by the construct() method,
|
||||
* you call the SwingWorker's get() method.
|
||||
* <pre>
|
||||
* SwingWorker worker = new SwingWorker()
|
||||
* {
|
||||
* public Object construct()
|
||||
* {
|
||||
* return new expensiveOperation();
|
||||
* }
|
||||
* };
|
||||
* worker.start();
|
||||
* // do something
|
||||
* // when you need the result:
|
||||
* x = worker.get(); // this blocks the UI !!
|
||||
* </pre>
|
||||
*/
|
||||
public abstract class SwingWorker
|
||||
{
|
||||
/**
|
||||
* Start a thread that will call the <code>construct</code> method
|
||||
* and then exit.
|
||||
*/
|
||||
public SwingWorker()
|
||||
{
|
||||
/** Finish Runnable */
|
||||
final Runnable doFinished = new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
finished();
|
||||
}
|
||||
};
|
||||
|
||||
/** Worker Runnable */
|
||||
Runnable doConstruct = new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
setValue(construct());
|
||||
}
|
||||
finally
|
||||
{
|
||||
m_threadVar.clear();
|
||||
}
|
||||
SwingUtilities.invokeLater(doFinished);
|
||||
}
|
||||
};
|
||||
|
||||
Thread t = new Thread (doConstruct);
|
||||
m_threadVar = new ThreadVar(t);
|
||||
} // SwingWorker
|
||||
|
||||
/** Worker Thread */
|
||||
private ThreadVar m_threadVar;
|
||||
/** Return value */
|
||||
private Object m_value; // see getValue(), setValue()
|
||||
|
||||
/**
|
||||
* Compute the value to be returned by the <code>get</code> method.
|
||||
* @return value
|
||||
*/
|
||||
public abstract Object construct();
|
||||
|
||||
/**
|
||||
* Called on the event dispatching thread (not on the worker thread)
|
||||
* after the <code>construct</code> method has returned.
|
||||
*/
|
||||
public void finished()
|
||||
{
|
||||
} // finished
|
||||
|
||||
/**
|
||||
* Get the value produced by the worker thread,
|
||||
* or null if it hasn't been constructed yet.
|
||||
* @return value of worker
|
||||
*/
|
||||
protected synchronized Object getValue()
|
||||
{
|
||||
return m_value;
|
||||
} // getValue
|
||||
|
||||
/**
|
||||
* Set the value produced by worker thread
|
||||
* @param x worker value
|
||||
*/
|
||||
private synchronized void setValue(Object x)
|
||||
{
|
||||
m_value = x;
|
||||
} // setValue
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* Start the worker thread.
|
||||
*/
|
||||
public void start()
|
||||
{
|
||||
Thread t = m_threadVar.get();
|
||||
if (t != null)
|
||||
t.start();
|
||||
} // start
|
||||
|
||||
/**
|
||||
* Return the value created by the <code>construct</code> method.
|
||||
* Returns null if either the constructing thread or the current
|
||||
* thread was interrupted before a value was produced.
|
||||
* (Blocks UI)
|
||||
* @return the value created by the <code>construct</code> method
|
||||
*/
|
||||
public Object get()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Thread t = m_threadVar.get();
|
||||
if (t == null)
|
||||
{
|
||||
return getValue();
|
||||
}
|
||||
try
|
||||
{
|
||||
t.join();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
Thread.currentThread().interrupt(); // propagate
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} // get
|
||||
|
||||
/**
|
||||
* A new method that interrupts the worker thread. Call this method
|
||||
* to force the worker to stop what it's doing.
|
||||
*/
|
||||
public void interrupt()
|
||||
{
|
||||
Thread t = m_threadVar.get();
|
||||
if (t != null)
|
||||
{
|
||||
t.interrupt();
|
||||
}
|
||||
m_threadVar.clear();
|
||||
} // interrupt
|
||||
|
||||
/**
|
||||
* Is worker Alive
|
||||
* @return true if alive
|
||||
*/
|
||||
public boolean isAlive()
|
||||
{
|
||||
Thread t = m_threadVar.get();
|
||||
if (t == null)
|
||||
return false;
|
||||
return t.isAlive();
|
||||
} // isAlive
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* Class to maintain reference to current worker thread
|
||||
* under separate synchronization control.
|
||||
*/
|
||||
private static class ThreadVar
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* @param t sync thread
|
||||
*/
|
||||
ThreadVar(Thread t)
|
||||
{
|
||||
thread = t;
|
||||
}
|
||||
/** The Sync Thread */
|
||||
private Thread thread;
|
||||
|
||||
/**
|
||||
* Get Sync Thread
|
||||
* @return thread
|
||||
*/
|
||||
synchronized Thread get()
|
||||
{
|
||||
return thread;
|
||||
} // get
|
||||
|
||||
/**
|
||||
* Clear Sync thread
|
||||
*/
|
||||
synchronized void clear()
|
||||
{
|
||||
thread = null;
|
||||
} // clear
|
||||
} // ThreadVar
|
||||
|
||||
} // SwingWorker
|
Loading…
Reference in New Issue