00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.openmobileis.synchro.sync4j.server;
00026
00027 import java.awt.Rectangle;
00028 import java.awt.event.ActionEvent;
00029 import java.awt.event.ActionListener;
00030 import java.io.Serializable;
00031 import java.util.Properties;
00032
00033 import javax.swing.JButton;
00034 import javax.swing.JLabel;
00035 import javax.swing.JTextField;
00036 import javax.swing.SwingConstants;
00037 import javax.swing.border.TitledBorder;
00038
00039 import org.openmobileis.common.util.log.LogManager;
00040 import org.openmobileis.database.fastobjectdb.db.test.synchro.sync4j.TestFODBSync4JSource;
00041
00042 import sync4j.framework.engine.source.ContentType;
00043 import sync4j.framework.engine.source.SyncSourceInfo;
00044 import sync4j.syncadmin.AdminException;
00045 import sync4j.syncadmin.ui.SourceManagementPanel;
00046
00053 public class FODBSync4JSourcePanel extends SourceManagementPanel implements Serializable {
00054
00058 public static final String NAME_ALLOWED_CHARS
00059 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_.";
00060
00061
00063 private JLabel panelName = new JLabel();
00064
00066 private TitledBorder titledBorder1;
00067
00068 private JLabel nameLabel = new JLabel() ;
00069 private JTextField nameValue = new JTextField() ;
00070 private JLabel typeLabel = new JLabel() ;
00071 private JTextField typeValue = new JTextField() ;
00072 private JLabel sourceUriLabel = new JLabel() ;
00073 private JTextField sourceUriValue = new JTextField() ;
00074
00075 private JButton confirmButton = new JButton() ;
00076
00077 private FODBSync4JSource syncSource = null ;
00081 public FODBSync4JSourcePanel() {
00082 super();
00083 System.out.println("Start FODBSync4JSourcePanel");
00084 notifyError(new AdminException("init client panel"));
00085
00086 Properties props = new Properties();
00087 props.setProperty("LOGFILE", "c:\\logs4j.txt");
00088 LogManager.registerLogManager(props);
00089 this.init();
00090 }
00095 private void init(){
00096
00097 this.setLayout(null);
00098
00099
00100
00101 titledBorder1 = new TitledBorder("");
00102
00103 panelName.setFont(titlePanelFont);
00104 panelName.setText("Edit Dummy SyncSource");
00105 panelName.setBounds(new Rectangle(14, 5, 316, 28));
00106 panelName.setAlignmentX(SwingConstants.CENTER);
00107 panelName.setBorder(titledBorder1);
00108
00109 sourceUriLabel.setText("Source URI: ");
00110 sourceUriLabel.setFont(defaultFont);
00111 sourceUriLabel.setBounds(new Rectangle(14, 60, 150, 18));
00112 sourceUriValue.setFont(new java.awt.Font("Arial", 0, 12));
00113 sourceUriValue.setBounds(new Rectangle(170, 60, 350, 18));
00114
00115 nameLabel.setText("Name: ");
00116 nameLabel.setFont(defaultFont);
00117 nameLabel.setBounds(new Rectangle(14, 90, 150, 18));
00118 nameValue.setFont(new java.awt.Font("Arial", 0, 12));
00119 nameValue.setBounds(new Rectangle(170, 90, 350, 18));
00120
00121 typeLabel.setText("Type: ");
00122 typeLabel.setFont(defaultFont);
00123 typeLabel.setBounds(new Rectangle(14, 120, 150, 18));
00124 typeValue.setFont(new java.awt.Font("Arial", 0, 12));
00125 typeValue.setBounds(new Rectangle(170, 120, 350, 18));
00126
00127 confirmButton.setFont(defaultFont);
00128 confirmButton.setText("Add");
00129 confirmButton.setBounds(170, 200, 70, 25);
00130
00131 confirmButton.addActionListener(new ActionListener() {
00132 public void actionPerformed(ActionEvent event ) {
00133 try {
00134 validateValues();
00135 getValues();
00136 if (getState() == STATE_INSERT) {
00137 FODBSync4JSourcePanel.this.actionPerformed(new ActionEvent(FODBSync4JSourcePanel.this, ACTION_EVENT_INSERT, event.getActionCommand()));
00138 } else {
00139 FODBSync4JSourcePanel.this.actionPerformed(new ActionEvent(FODBSync4JSourcePanel.this, ACTION_EVENT_UPDATE, event.getActionCommand()));
00140 }
00141 } catch (Exception e) {
00142 notifyError(new AdminException(e.getMessage()));
00143 }
00144 }
00145 });
00146
00147
00148 this.add(panelName , null);
00149 this.add(nameLabel , null);
00150 this.add(nameValue , null);
00151 this.add(typeLabel , null);
00152 this.add(typeValue , null);
00153 this.add(sourceUriLabel , null);
00154 this.add(sourceUriValue , null);
00155 this.add(confirmButton , null);
00156
00157 }
00158
00165 public void updateForm() {
00166 if (!(getSyncSource() instanceof TestFODBSync4JSource)) {
00167 notifyError(
00168 new AdminException(
00169 "This is not an DummySyncSource! Unable to process SyncSource values."
00170 )
00171 );
00172 return;
00173 }
00174 if (getState() == STATE_INSERT) {
00175 confirmButton.setText("Add");
00176 } else if (getState() == STATE_UPDATE) {
00177 confirmButton.setText("Save");
00178 }
00179
00180 this.syncSource = (TestFODBSync4JSource) getSyncSource();
00181
00182 sourceUriValue.setText(syncSource.getSourceURI() );
00183 nameValue.setText (syncSource.getName() );
00184
00185 if (this.syncSource.getSourceURI() != null) {
00186 sourceUriValue.setEditable(false);
00187 }
00188 }
00189
00190
00201 private void validateValues() throws IllegalArgumentException {
00202 String value = null;
00203
00204 value = nameValue.getText();
00205
00206
00207 value = typeValue.getText();
00208
00209 value = sourceUriValue.getText();
00210 }
00211
00215 private void getValues() {
00216 syncSource.setSourceURI (sourceUriValue.getText().trim());
00217 syncSource.setName (nameValue.getText().trim() );
00218 syncSource.setType (typeValue.getText().trim() );
00219
00220 ContentType[] contentTypes = new ContentType[] {
00221 new ContentType("text/plain", "1.0")
00222 };
00223
00224
00225 syncSource.setInfo(new SyncSourceInfo(contentTypes, 0));
00226 }
00227 }