yuxc
2025-01-15 63ff693fcccf647d758fc4f300a573f6c644596e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
package vciw.preferences;
 
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
 
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.DirectoryFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
 
import vciw.Activator;
 
/**
 * This class represents a preference page that is contributed to the
 * Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>, we
 * can use the field support built into JFace that allows us to create a page
 * that is small and knows how to save, restore and apply itself.
 * <p>
 * This page is used to modify preferences only. They are stored in the
 * preference store that belongs to the main plug-in class. That way,
 * preferences can be accessed directly via the preference store.
 */
 
public class SamplePreferencePage extends FieldEditorPreferencePage implements
        IWorkbenchPreferencePage {
    private DirectoryFieldEditor VCI_Home;
    private DirectoryFieldEditor Corba_Home;
    private DirectoryFieldEditor javaHome;
    private static String VCI_Home_Path;
    private static String VCI_Corba_Path;
    private static String url = "";
    private static String username = "";
    private static String password = "";
    private static String corboInfo = "";
    private String[] columnTitles = { "index", "name", "class", "on" };
    private SortedProperties properties = new SortedProperties();
    Table table = null;
    
    private boolean initTable = false;
 
    private TableItem selectedRow = null;
 
    // private boolean reverseSort = false;
    // private String lastSelection = null;
 
    public SamplePreferencePage() {
 
        super(GRID);
        setPreferenceStore(Activator.getDefault().getPreferenceStore());
        setDescription(" DataSource and Corba Setting of VCI PlatFrom ");
 
    }
 
    /**
     * Creates the field editors. Field editors are abstractions of the common
     * GUI blocks needed to manipulate various types of preferences. Each field
     * editor knows how to save and restore itself.
     */
    public void createFieldEditors() {
        Composite composite = new Composite(getFieldEditorParent(), SWT.NULL);
        GridLayout layout = new GridLayout();
        composite.setLayout(layout);
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        data.grabExcessHorizontalSpace = true;
        composite.setLayoutData(data);
        Group groupmain = new Group(composite, 1);
        groupmain.setText("VCI Home ÉèÖÃ");
        GridData gd = new GridData(GridData.FILL_BOTH);
        groupmain.setLayoutData(gd);
        VCI_Home = new DirectoryFieldEditor(PreferenceConstants.P_PATH_VCIHOME, "VCI_Home:", groupmain);
        addSeparator(composite);
        addFirstSection(composite);
        //addSeparator(composite);
        //addSecondSection(composite);
        addSeparator(composite);
        addCorbaServerInfoSection(composite);
    }
 
    class CorbaInput extends InputDialog {
        CorbaInput(Shell paramShell, String paramString1, String paramString2,
                String paramString3, IInputValidator paramIInputValidator) {
            super(paramShell, paramString1, paramString2, paramString3,
                    paramIInputValidator);
        }
 
        private String clazzName = "";
 
        protected void okPressed() {
            clazzName = classtext.getText();
            super.okPressed();
        }
 
        private Text classtext;
 
        protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);
 
            this.classtext = new Text(composite, getInputTextStyle());
            this.classtext.setLayoutData(new GridData(768));
            this.classtext.setText("class");
            this.classtext.addModifyListener(new ModifyListener() {
                public void modifyText(ModifyEvent e) {
                    validateInput();
                }
            });
 
            return classtext;
        }
 
        public String getClassText() {
            return clazzName;
        }
    }
 
    private void addCorbaServerInfoSection(Composite composite) {
/*        GridLayout layout = new GridLayout();
        composite.setLayout(layout);
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
        data.grabExcessHorizontalSpace = true;
        composite.setLayoutData(data);
        Group groupmain = new Group(composite, 1);
        groupmain.setText("VCI Home ÉèÖÃ");
        GridData gd = new GridData(GridData.FILL_BOTH);
        groupmain.setLayoutData(gd);
        VCI_Home = new DirectoryFieldEditor(PreferenceConstants.P_PATH_VCIHOME, "VCI_Home:", groupmain);
*/
        
        Group group = new Group(composite, 1);//32);
        group.setText("Corba ·þÎñÅäÖÃ");
        GridData data = new GridData(GridData.FILL_BOTH);//4, 16777216, true, false);
        group.setLayoutData(data);
        GridLayout layout = new GridLayout();
        layout.numColumns = 3;
        group.setLayout(layout);
 
        // table
        table = new Table(group, 68356);
        GridData gridData = new GridData(GridData.FILL_BOTH);
        gridData.heightHint = convertVerticalDLUsToPixels(150);
        table.setLayoutData(gridData);
        table.setHeaderVisible(true);
        table.setLinesVisible(true);
        table.setFont(group.getFont());
 
        table.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                if (e.item != null)
                    selectedRow = (TableItem) e.item;
 
                return;
            }
        });
 
        Button buttoninit = new Button(group, SWT.PUSH);
        buttoninit.setText("ÐÂÔö");
        buttoninit.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                if (properties.get("servicecount") == null) {
                    MessageDialog.openInformation(getShell(), "Ìáʾ", "Çë³õʼ»¯");
                    return;
                }
 
                IInputValidator validator = new IInputValidator() {
                    public String isValid(String newText) {
                        return ((newText.length() == 0) ? "" : null);
                    }
                };
                CorbaInput dialog = new CorbaInput(getShell(), "corba service setting", "", "name", validator);
                int result = dialog.open();
                if (result != 0) {
                    return;
                }
                
                String name = dialog.getValue();
                String clazz = dialog.getClassText();
                int newrow = Integer.parseInt((String) properties.get("servicecount"));
                String index = Integer.toString(newrow);
 
                TableItem item = new TableItem(table, newrow);
                item.setText(new String[] { index, name, clazz, "Y" });
                // save
                // properties.put("service" + newrow + ".name", name);
                // properties.put("service" + newrow + ".class", clazz);
 
                // /
                File file = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_VCIHOME) + "\\src\\properties\\conf.properties");
                InputStream inStream = null;
                OutputStream out = null;
                try {
                    inStream = new FileInputStream(file);
                    properties.load(inStream);
                    if (inStream != null) {
                        inStream.close();
                    }
 
                    out = new FileOutputStream(file);
                    properties.setProperty("service" + newrow + ".name", name);
 
                    properties.setProperty("service" + newrow + ".class", clazz);
                    properties.setProperty("servicecount", newrow + 1 + "");
                    properties.store(out, "conf.properties version by Eclipse");
                    if (out != null) {
                        out.close();
                    }
 
                } catch (IOException ecx) {
                    MessageDialog.openInformation(getShell(), "Ìáʾ", ecx.getMessage());
                }
 
            }
 
        });
 
        Button buttondel = new Button(group, SWT.PUSH);
        buttondel.setText("ɾ³ý");
        buttondel.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                if (selectedRow != null) {
                    boolean istrue = MessageDialog.openConfirm(getShell(), "Ìáʾ", "ÊÇ·ñɾ³ý");
                    if (istrue) {
                        int row = 0;
                        // table.remove(table.get);
                        TableItem[] items = table.getItems();
                        for (int i = 0; i < items.length; i++) {
                            if (items[i].getText().equals(selectedRow.getText())) {
                                row = i;
                                break;
                            }
                        }
                        table.remove(row);
 
                        File file = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_VCIHOME) + "\\src\\properties\\conf.properties");
                        InputStream inStream = null;
                        OutputStream out = null;
                        try {
                            inStream = new FileInputStream(file);
                            properties.load(inStream);
                            if (inStream != null) {
                                inStream.close();
                            }
 
                            out = new FileOutputStream(file);
 
                            // properties.remove("service" + (row) + ".name");
                            // properties.remove("service" + (row) + ".class");
 
                            
                            properties.setProperty("service" + row + ".class", "");
 
                            properties.setProperty("service" + row + ".name", "");
                            properties.setProperty("servicecount", Integer.parseInt((String) properties.get("servicecount")) - 1 + "");
                            properties.store(out, "conf.properties version by Eclipse");
                            if (out != null) {
                                out.close();
                            }
 
                        } catch (IOException ecx) {
                            MessageDialog.openInformation(getShell(), "Ìáʾ",
                                    ecx.getMessage());
                        }
 
                    } else {
                        return;
                    }
 
                }
            }
 
        });
 
        int[] columnWidths = { convertHorizontalDLUsToPixels(35),
                convertHorizontalDLUsToPixels(100),
                convertHorizontalDLUsToPixels(140),
                convertHorizontalDLUsToPixels(35),
                convertHorizontalDLUsToPixels(130) };
 
        for (int i = 0; i < columnTitles.length; ++i) {
            TableColumn tableColumn = new TableColumn(table, 0);
            tableColumn.setWidth(columnWidths[i]);
            tableColumn.setText(this.columnTitles[i]);
            final int columnIndex = i;
            tableColumn.addSelectionListener(new SelectionAdapter() {
 
                public void widgetSelected(SelectionEvent e) {
                    sort(columnIndex);
                }
 
            });
        }
    }
 
    @SuppressWarnings({ "unchecked", "rawtypes" })
    private void sort(int column) {
        TableItem[] items = table.getItems();
        Arrays.sort(items, new Comparator() {
            public int compare(Object a, Object b) {
                TableItem info1 = (TableItem) a;
                TableItem info2 = (TableItem) b;
                return info2.getText(0).compareTo(info1.getText(0));
            }
        });
        System.out.println();
        // table.removeAll();
        // for (int i = 0; i < sorted.length; i++) {
        // TableItem item = new TableItem(table, i);
        // item.setText(sorted[i].getText());
        // }
        // for (int i = 0; i < items.length; ++i) {
        // items[i].setText(createRow(this.bundleGroupInfos[i]));
        // items[i].setData(this.bundleGroupInfos[i]);
        // }
    }
 
    private void addFirstSection(Composite parent) {
        
        //Composite composite = createDefaultComposite(parent);
        Group groupDB = new Group(parent, 1);
        groupDB.setText("²ÎÊýÉèÖÃ");
        GridData gd = new GridData(GridData.FILL_BOTH);
        groupDB.setLayoutData(gd);
        
 
        final StringFieldEditor dbIP = new StringFieldEditor(PreferenceConstants.P_STRING_URL_IP, "Êý¾Ý¿âµØÖ·  (&A):", groupDB);
        addField(dbIP);
 
        //addField(new StringFieldEditor(PreferenceConstants.P_STRING_URL_IP, "Êý¾Ý¿âµØÖ· &ip:", group));
        
        final StringFieldEditor dbInstance = new StringFieldEditor(PreferenceConstants.P_STRING_URL_INSTANCE, "Êý¾Ý¿âʵÀý  (&D):", groupDB);
        addField(dbInstance);
        
        final StringFieldEditor dbUser = new StringFieldEditor(PreferenceConstants.P_STRING_USER, "Óû§ (&U):", groupDB);
        addField(dbUser);
        
        final StringFieldEditor dbPws = new StringFieldEditor(PreferenceConstants.P_STRING_PWD, "ÃÜÂë  (&P):", groupDB);
        addField(dbPws);
 
        javaHome = new DirectoryFieldEditor(PreferenceConstants.java_home, "Java home:", groupDB);
        addField(javaHome);
 
        addField(VCI_Home);
        
        Group groupCorba = new Group(parent, 1);
        groupCorba.setText("Corba ÉèÖÃ");
        GridData gdCorba = new GridData(GridData.FILL_BOTH);
        groupCorba.setLayoutData(gdCorba);
        
        final StringFieldEditor dbCorbaIP = new StringFieldEditor(PreferenceConstants.P_PATH_COMBOIP, "Corba µØÖ·(&I):", groupCorba);
        addField(dbCorbaIP);
 
 
        final StringFieldEditor corbaCommand = new StringFieldEditor(PreferenceConstants.combo_command, "Corba ÃüÁî(&C):", groupCorba);
        addField(corbaCommand);
 
        Corba_Home = new DirectoryFieldEditor(PreferenceConstants.P_PATH_COMBOHOME, "Corba_&Home:", groupCorba);
        addField(Corba_Home);
 
//        Group groupOp = new Group(parent, 1);
//        groupOp.setText("²Ù×÷");
//        GridData opCorba = new GridData(GridData.FILL_BOTH);
//        groupCorba.setLayoutData(opCorba);
        Group groupOP = new Group(parent, 1);//32);
        groupOP.setText("²Ù×÷");
        GridData dataOP = new GridData(GridData.FILL_BOTH);//4, 16777216, true, false);
        groupOP.setLayoutData(dataOP);
        GridLayout layout = new GridLayout();
        layout.numColumns = 3;
        groupOP.setLayout(layout);
 
 
        Button buttoninit = new Button(groupOP, SWT.PUSH);
        buttoninit.setText("³õʼ»¯...");
        buttoninit.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                int returnint = resetEclipseHomeVariable();
                if (returnint == 1) {
                    return;
                }
 
                String psdefault_vcihome = VCI_Home.getStringValue();
                if (psdefault_vcihome != null && !psdefault_vcihome.equals("")) {
                    // ²éѯxml
                    getXMlInfo(psdefault_vcihome);
                    getPreferenceStore().setValue(PreferenceConstants.P_PATH_VCIHOME, psdefault_vcihome);
                    
                    if (Corba_Home.getStringValue().equals("")) {
                        Corba_Home.setStringValue(psdefault_vcihome + "\\JacORB");
                        getPreferenceStore().setValue(PreferenceConstants.P_PATH_COMBOHOME, psdefault_vcihome + "\\JacORB");
                    }
                    
                    if (getPreferenceStore().getString(PreferenceConstants.combo_command).equals("")) {
                        getPreferenceStore().setValue(PreferenceConstants.combo_command, "ns -p 30000");
                    }
                    
                    if (javaHome.getStringValue().equals("")) {
                        javaHome.setStringValue(psdefault_vcihome + "\\jre");
                        getPreferenceStore().setValue(PreferenceConstants.java_home, psdefault_vcihome + "\\jre");
                    }
                    
                    getPreferenceStore().setValue(PreferenceConstants.P_STRING_URL_IP, getIP());
                    getPreferenceStore().setValue(PreferenceConstants.P_STRING_URL_INSTANCE, getInstance());
 
                    getPreferenceStore().setValue(PreferenceConstants.P_STRING_USER, username);
                    getPreferenceStore().setValue(PreferenceConstants.P_STRING_PWD, password);
                    corboInfo = getCombaInfo(psdefault_vcihome);
                    // ³õʼ»¯
                    initCorbaServer();
                    getPreferenceStore().setValue(PreferenceConstants.P_PATH_COMBOIP, getCombaip());
 
                }
                initialize();
                MessageDialog.openInformation(getShell(), "Ìáʾ", "³õʼ»¯Íê³É" + "\n");
            }
        });
 
        Button button = new Button(groupOP, SWT.PUSH);
        button.setText("²âÊÔÊý¾Ý¿â ...");
        button.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                try {
                    testDBConnect();
                    // ±£´æÊý¾Ý¿âÐÅÏ¢
                    saveXML();
                    // ±£´æCombaÐÅÏ¢
                    setCombaInfo();
                } catch (SQLException e1) {
                    MessageDialog.openInformation(getShell(), "Ìáʾ", "Êý¾Ý¿âÁ¬½Óʧ°Ü" + "\n" + e1.getMessage());
                }
            }
        });
 
        Button buttonComba = new Button(groupOP, SWT.PUSH);
        buttonComba.setText("Æô¶¯Corba·þÎñ...");
        buttonComba.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                if (Corba_Home.getStringValue().equals("")) {
                    MessageDialog.openInformation(getShell(), "Ìáʾ", "ÇëÑ¡ÔñVCI_Corba·¾¶");
                    return;
 
                }
                getPreferenceStore().setValue(PreferenceConstants.P_PATH_COMBOHOME, Corba_Home.getStringValue());
                getPreferenceStore().setValue(PreferenceConstants.java_home, javaHome.getStringValue());
                getPreferenceStore().setValue(PreferenceConstants.combo_command, corbaCommand.getStringValue());
 
                runCorba();
            }
        });
 
    }
 
    private void initCorbaServer() {
        if (initTable == true) {
            // return;
        }
        table.removeAll();
        for (int i = 0; i < Integer.parseInt((String) properties.get("servicecount")); i++) {
            String index = Integer.toString(i);
            String name = (String) properties.get("service" + i + ".name");
            String clazz = (String) properties.get("service" + i + ".class");
            TableItem item = new TableItem(table, i);
            item.setText(new String[] { index, name, clazz, "Y" });
        }
        initTable = true;
    }
 
//    private void addSecondSection(Composite parent) {
//        //Composite composite = createDefaultComposite(parent);
//        //Group groupHome = new Group(composite, 1);
//        Group groupCorba = new Group(parent, 1);
//        groupCorba.setText("Corba ÉèÖÃ");
//        GridData gd = new GridData(GridData.FILL_BOTH);
//        groupCorba.setLayoutData(gd);
//        Corba_Home = new DirectoryFieldEditor(PreferenceConstants.P_PATH_COMBOHOME, "&Corba_Home:", groupCorba);
//        addField(Corba_Home);
//
//        // addSeparator(composite);
//        //Composite compositeCommand = createDefaultComposite(parent);
//        //Group groupCommand = new Group(compositeCommand, 1);
////        Group groupCommand = new Group(parent, 1);
////        groupCommand.setText("Corba CommandÉèÖÃ");
////        GridData gdCommand = new GridData(GridData.FILL_BOTH);
////        groupCommand.setLayoutData(gdCommand);
//        final StringFieldEditor corbaCommand = new StringFieldEditor(PreferenceConstants.combo_command, "Corba ÃüÁî:", groupCorba);
//        addField(corbaCommand);
//
//        //final DirectoryFieldEditor 
//        javaHome = new DirectoryFieldEditor(PreferenceConstants.java_home, "Java home:", groupCorba);
//        addField(javaHome);
//
//        Button buttonComba = new Button(groupCorba, SWT.PUSH);
//        buttonComba.setText("Æô¶¯Corba·þÎñ...");
//        buttonComba.addSelectionListener(new SelectionAdapter() {
//            public void widgetSelected(SelectionEvent e) {
//                if (Corba_Home.getStringValue().equals("")) {
//                    MessageDialog.openInformation(getShell(), "Ìáʾ", "ÇëÑ¡ÔñVCI_Corba·¾¶");
//                    return;
//
//                }
//                getPreferenceStore().setValue(PreferenceConstants.P_PATH_COMBOHOME, Corba_Home.getStringValue());
//                getPreferenceStore().setValue(PreferenceConstants.java_home, javaHome.getStringValue());
//                getPreferenceStore().setValue(PreferenceConstants.combo_command, corbaCommand.getStringValue());
//
//                runComba();
//            }
//        });
//
//    }
 
//    private Composite createDefaultComposite(Composite parent) {
//        Composite composite = new Composite(parent, SWT.NULL);
//        GridLayout layout = new GridLayout();
//        layout.numColumns = 2;
//        composite.setLayout(layout);
//
//        GridData data = new GridData();
//        data.verticalAlignment = GridData.FILL_BOTH;
//        data.horizontalAlignment = GridData.FILL_BOTH;
//        composite.setLayoutData(data);
//
//        return composite;
//    }
 
    private void addSeparator(Composite parent) {
 
        Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
        GridData gridData = new GridData();
        gridData.horizontalAlignment = GridData.FILL;
        gridData.grabExcessHorizontalSpace = true;
        separator.setLayoutData(gridData);
    }
 
    private void runCorba() {
        try {
            setCombaRun();
            Runtime.getRuntime().exec("cmd /c start " + getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME) + "\\run.bat /k");
            // p.waitFor();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    private String getInstance() {
        String Instance = "";
        if (url != null) {
            String[] urls = url.split(":");
            Instance = urls[urls.length - 1];
        }
        return Instance;
    }
 
    private void testDBConnect() throws SQLException {
        Connection conn = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            String url = "jdbc:oracle:thin:@"  
                    + getPreferenceStore().getString(PreferenceConstants.P_STRING_URL_IP)
                    + ":1521:"
                    + getPreferenceStore().getString(PreferenceConstants.P_STRING_URL_INSTANCE);
            String user = getPreferenceStore().getString(PreferenceConstants.P_STRING_USER);
            String pwd = getPreferenceStore().getString(PreferenceConstants.P_STRING_PWD);
            conn = DriverManager.getConnection(url, user, pwd);
            conn.createStatement();
            if (conn != null) {
                MessageDialog.openInformation(this.getShell(), "Ìáʾ", "Êý¾Ý¿âÁ¬½Ó³É¹¦");
            }
        } catch (ClassNotFoundException e) {
            MessageDialog.openInformation(this.getShell(), "Ìáʾ", "Êý¾Ý¿âÁ¬½Óʧ°Ü" + "\n" + e.getMessage());
        } catch (SQLException e) {
            MessageDialog.openInformation(this.getShell(), "Ìáʾ", "Êý¾Ý¿âÁ¬½Óʧ°Ü" + "\n" + e.getMessage());
        } finally {
            if (conn != null) {
                conn.close();
            }
        }
    }
 
    class SortedProperties extends Properties {
        private static final long serialVersionUID = 1L;
        private final LinkedHashSet<Object> keys = new LinkedHashSet<Object>();
 
        public Enumeration<Object> keys() {
            return Collections.enumeration(keys);
        }
 
        public Object put(Object key, Object value) {
            keys.add(key);
            return super.put(key, value);
        }
 
        public Set<Object> keySet() {
            return keys;
        }
 
        public Set<String> stringPropertyNames() {
            Set<String> set = new LinkedHashSet<String>();
            for (Object key : this.keys) {
                set.add((String) key);
            }
            return set;
        }
    }
 
    private void setCombaRun() {
        String encode = "UTF8";
        File file = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME) + "\\run.bat");
        Path path = new Path(getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME));
 
        OutputStream out = null;
        InputStream inStream = null;
        try {
            inStream = new FileInputStream(file);
            InputStreamReader iread = new InputStreamReader(inStream, encode);
            BufferedReader reader = new BufferedReader(iread);
            reader.readLine();
            reader.close();
            out = new FileOutputStream(file);
            OutputStreamWriter twriter = new OutputStreamWriter(out, encode);
            BufferedWriter writer = new BufferedWriter(twriter);
 
            // ±éÀú lib
            File targetfile = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME) + "\\lib");
            File[] jarFiles = targetfile.listFiles();
            if (jarFiles == null) {
                return;
            }
 
            List<String> platformpaths = new ArrayList<String>();
            for (int i = 0; i < jarFiles.length; i++) {
                String filename = jarFiles[i].getName();
                if (isJarFile(filename)) {
                    String jarPath = jarFiles[i].getAbsolutePath();
                    platformpaths.add(jarPath);
                }
            }
            StringBuffer s = new StringBuffer();
            s.append("set path=");
            s.append(getPreferenceStore().getString(PreferenceConstants.java_home));
            s.append("\\bin;%PATH% \n");
            s.append("SET CLASSPATH=%CLASSPATH%;");
            for (int i = 0; i < platformpaths.size(); i++) {
                s.append(platformpaths.get(i));
                s.append(";");
            }
            String title = s.toString().substring(0, s.lastIndexOf(";"));
            s.delete(0, s.length());
            s.append(title);
            s.append("\n");
 
            s.append(" cd \\ \n");
            s.append(" cd /d " + path.getDevice() + "\\ \n");
            s.append(" cd "
                    + getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME) + " \n");
            s.append(" cd bin \n");
            s.append(getPreferenceStore().getString(PreferenceConstants.combo_command));
            // s.append("ns -DOAPort=30000 \n");
            writer.append(s.toString());
            writer.flush();
            writer.close();
 
        } catch (FileNotFoundException e) {
            MessageDialog.openInformation(this.getShell(), "Ìáʾ", e.getMessage());
        } catch (UnsupportedEncodingException e) {
            MessageDialog.openInformation(this.getShell(), "Ìáʾ", e.getMessage());
        } catch (IOException e) {
            MessageDialog.openInformation(this.getShell(), "Ìáʾ", e.getMessage());
        }
    }
 
    private boolean isJarFile(String fileName) {
        if (fileName == null)
            return false;
        int last = fileName.lastIndexOf(".");
        if (last == -1) {
            return false;
        }
        String suffix = fileName.substring(fileName.lastIndexOf("."));
        if (suffix.equals(".jar"))
            return true;
        else
            return false;
    }
 
    private void setCombaInfo() {
 
        File file = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_VCIHOME) + "\\src\\properties\\conf.properties");
        InputStream inStream = null;
        OutputStream out = null;
        try {
            inStream = new FileInputStream(file);
            properties.load(inStream);
            if (inStream != null) {
                inStream.close();
            }
 
            out = new FileOutputStream(file);
            properties.setProperty("NameService", "corbaloc::" + getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOIP) + "/NameService");
            properties.store(out, "conf.properties version by Eclipse");
            if (out != null) {
                out.close();
            }
 
        } catch (IOException e) {
            MessageDialog
                    .openInformation(this.getShell(), "Ìáʾ", e.getMessage());
        }
 
    }
 
    private String getCombaInfo(String VCI_Home_Path) {
 
        File file = new File(VCI_Home_Path + "\\src\\properties\\conf.properties");
        InputStream inStream = null;
 
        try {
            inStream = new BufferedInputStream(new FileInputStream(file));
            properties.load(inStream);
            if (inStream != null) {
                inStream.close();
            }
        } catch (IOException e) {
            MessageDialog
                    .openInformation(this.getShell(), "Ìáʾ", e.getMessage());
        }
        return properties.getProperty("NameService");
    }
 
    private void saveXML() {
        Element cpElement;
 
        try {
            DocumentBuilderFactory facrtory = DocumentBuilderFactory
                    .newInstance();
            facrtory.setNamespaceAware(true);
            DocumentBuilder parser = facrtory.newDocumentBuilder();
            parser.setEntityResolver(new EntityResolver() {
 
                public InputSource resolveEntity(String publicId,
                        String systemId) throws SAXException, IOException {
                    if (publicId
                            .equals("-//Hibernate/Hibernate Configuration DTD 3.0//EN")) {
                        String path = systemId
                                .substring("http://hibernate.sourceforge.net/"
                                        .length());
                        return new InputSource(this.getClass()
                                .getResourceAsStream(path));
                    }
                    return null;
 
                }
            });
            parser.getSchema();
            facrtory.getSchema();
            facrtory.isNamespaceAware();
            Document document = parser.parse(getPreferenceStore().getString(
                    PreferenceConstants.P_PATH_VCIHOME)
                    + "\\properties\\hibernate.cfg.xml");
            cpElement = document.getDocumentElement();
            cpElement.getElementsByTagName("property");
            cpElement.getAttributeNode("name");
 
            NodeList childs = cpElement.getChildNodes();
            for (int i = 0; i < childs.getLength(); i++) {
                Node childNode = childs.item(i);
                if (childNode instanceof Element) {
                    childNode.getNodeName();
                    childNode.getFirstChild().getNodeValue();
                    Node propertychildnode = childNode.getFirstChild();
                    while (propertychildnode != null) {
                        Node node = propertychildnode.getNextSibling();
                        if (node != null && node instanceof Element) {
                            if (node.getAttributes().getNamedItem("name") == null) {
                                break;
                            }
                            Object o = node.getAttributes()
                                    .getNamedItem("name").getNodeValue();
                            if (o != null
                                    && o.toString().equals("connection.url")) {
                                String url = "jdbc:oracle:thin:@"
                                        + getPreferenceStore()
                                                .getString(
                                                        PreferenceConstants.P_STRING_URL_IP)
                                        + ":1521:"
                                        + getPreferenceStore()
                                                .getString(
                                                        PreferenceConstants.P_STRING_URL_INSTANCE);
 
                                node.setTextContent(url);
                            } else if (o != null
                                    && o.toString().equals(
                                            "connection.username")) {
                                String user = getPreferenceStore().getString(
                                        PreferenceConstants.P_STRING_USER);
 
                                node.setTextContent(user);
                            } else if (o != null
                                    && o.toString().equals(
                                            "connection.password")) {
                                String pwd = getPreferenceStore().getString(
                                        PreferenceConstants.P_STRING_PWD);
                                node.setTextContent(pwd);
                            }
                        }
                        propertychildnode = node;
                    }
 
                }
 
            }
            Source sourcexml = new DOMSource(document);
            TransformerFactory transformFactory = TransformerFactory
                    .newInstance();
            Transformer tansformer = transformFactory.newTransformer();
            tansformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, document
                    .getDoctype().getPublicId());
            tansformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, document
                    .getDoctype().getSystemId());
            Result result = new StreamResult(getPreferenceStore().getString(
                    PreferenceConstants.P_PATH_VCIHOME)
                    + "\\properties\\hibernate.cfg.xml");
            tansformer.transform(sourcexml, result);
 
        } catch (Exception localSAXException) {
            MessageDialog.openInformation(this.getShell(), "Ìáʾ",
                    localSAXException.getMessage());
        }
 
    }
 
    private void getXMlInfo(String VCI_Home_Path) {
        Element cpElement;
 
        // Configuration config = new Configuration();
        // config.setEntityResolver(new EJB3DTDEntityResolver());
        // config.configure(new File(
        // VCI_Home_Path + "\\properties\\hibernate.cfg.xml"));
 
        try {
            DocumentBuilderFactory facrtory = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder parser = facrtory.newDocumentBuilder();
            parser.setEntityResolver(new EntityResolver() {
 
                public InputSource resolveEntity(String publicId,
                        String systemId) throws SAXException, IOException {
                    if (publicId
                            .equals("-//Hibernate/Hibernate Configuration DTD 3.0//EN")) {
                        String path = systemId
                                .substring("http://hibernate.sourceforge.net/"
                                        .length());
                        return new InputSource(this.getClass()
                                .getResourceAsStream(path));
                    }
                    return null;
 
                }
            });
            cpElement = parser.parse(
                    VCI_Home_Path + "\\properties\\hibernate.cfg.xml")
                    .getDocumentElement();
 
            cpElement.getElementsByTagName("property");
            cpElement.getAttributeNode("name");
            NodeList childs = cpElement.getChildNodes();
            for (int i = 0; i < childs.getLength(); i++) {
                Node childNode = childs.item(i);
                if (childNode instanceof Element) {
                    childNode.getNodeName();
                    childNode.getFirstChild().getNodeValue();
                    Node propertychildnode = childNode.getFirstChild();
                    while (propertychildnode != null) {
                        Node node = propertychildnode.getNextSibling();
                        if (node != null && node instanceof Element) {
                            if (node.getAttributes().getNamedItem("name") == null) {
                                break;
                            }
                            Object o = node.getAttributes().getNamedItem("name").getNodeValue();
                            if (o != null && o.toString().equals("connection.url")) {
                                url = node.getTextContent();
                            } else if (o != null && o.toString().equals("connection.username")) {
                                username = node.getTextContent();
                            } else if (o != null && o.toString().equals("connection.password")) {
                                password = node.getTextContent();
                            }
                        }
                        propertychildnode = node;
                    }
 
                }
 
            }
        } catch (Exception localSAXException) {
            MessageDialog.openInformation(this.getShell(), "Ìáʾ",
                    localSAXException.getMessage());
        }
    }
 
    private String getIP() {
        String ip = "";
        if (url != null) {
            String[] urls = url.split(":");
            for (int i = 0; i < urls.length; i++) {
                if (urls[i].contains("@")) {
                    ip = urls[i].substring(urls[i].indexOf("@") + 1,
                            urls[i].length());
                }
            }
        }
        return ip;
    }
 
    private String getCombaip() {
        return corboInfo.substring(corboInfo.indexOf("::") + 2,
                corboInfo.indexOf("/"));
    }
 
    /*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
     */
    public void init(IWorkbench workbench) {
 
    }
 
    public void performApply() {
        resetEclipseHomeVariable();
        super.performApply();
 
    }
 
    public boolean performOk() {
        resetEclipseHomeVariable();
        super.performOk();
        return true;
    }
 
    /*
     * make ClassPathVariable
     */
    public int resetEclipseHomeVariable() {
        try {
            // ÉèÖÃ
            VCI_Home_Path = VCI_Home.getStringValue();
            // getPreferenceStore().setValue(PreferenceConstants.P_PATH_VCIHOME,
            // VCI_Home_Path);
            JavaCore.setClasspathVariable("VCI_HOME", new Path(VCI_Home_Path), null);
            VCI_Corba_Path = Corba_Home.getStringValue();
            JavaCore.setClasspathVariable("Comba_HOME", new Path(VCI_Corba_Path), null);
        } catch (CoreException localCoreException) {
            localCoreException.printStackTrace();
        }
        if (VCI_Home_Path.equals("")) {
            MessageDialog.openInformation(this.getShell(), "Ìáʾ", "ÇëÑ¡ÔñVCI_Home·¾¶");
            return 1;
 
        }
 
        return 0;
    }
 
    public void applyData(Object data) {
 
        super.applyData(data);
    }
 
    @SuppressWarnings("unused")
    public boolean delItemOfProperties(String key, String value)
            throws Exception {
        boolean flag = false;
        String replace = key + "=" + value + "\n";
        StringBuffer text = new StringBuffer();
        String templine;
        File file = new File(VCI_Home_Path + "\\src\\properties\\conf.properties");
        BufferedReader reader = new BufferedReader(new FileReader(file));
        while ((templine = reader.readLine()) != null) {
            // templine = templine;
        }
        return true;
    }
}