Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

FODBSync4JSourcePanel.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
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   // ------------------------------------------------------------ Private data
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     // set layout
00097     this.setLayout(null);
00098 
00099     // set properties of label, position and border
00100     //  referred to the title of the panel
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     // add all components to the panel
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 // ----------------------------------------------------------- Private methods
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 }

Generated on Wed Dec 14 21:05:33 2005 for OpenMobileIS by  doxygen 1.4.4