KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > feature > data > DataFeatureBar


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: DataFeatureBar.java,v 1.4 2003/04/27 13:49:40 per_nyfelt Exp $
8
package org.ozoneDB.adminGui.feature.data;
9
10 import org.ozoneDB.adminGui.res.Images;
11 import org.ozoneDB.adminGui.main.AdminGui;
12 import org.ozoneDB.adminGui.widget.MessageBox;
13 import org.ozoneDB.adminGui.util.ThreadWorker;
14 import org.ozoneDB.adminGui.feature.ActionBar;
15 import org.ozoneDB.adminGui.feature.InfoPanel;
16
17 import javax.swing.*;
18 import java.awt.*;
19 import java.awt.event.ActionListener JavaDoc;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.io.File JavaDoc;
22
23 /**
24  * @author Per Nyfelt
25  */

26 public class DataFeatureBar extends ActionBar {
27
28     private InfoPanel dataInfoPanel;
29     private GridBagConstraints gbc = new GridBagConstraints();
30
31     public DataFeatureBar(DataInfoPanel dataInfoPanel) {
32         this.dataInfoPanel = dataInfoPanel;
33         addComponents();
34     }
35
36     protected void addComponents() {
37
38         this.removeAll();
39         //gbc.gridx = GridBagConstraints.REMAINDER;
40
gbc.insets = new Insets(1, 5, 1, 5);
41         gbc.fill = GridBagConstraints.HORIZONTAL;
42         gbc.gridy = 0;
43
44         // Add label
45
//gbc.anchor = GridBagConstraints.SOUTHWEST;
46
//gbc.weighty = .3;
47
add(new ActionButton("named objects", Images.DATA_OBJECT_NAMES, new NamedObjectsLister()), gbc);
48
49         gbc.gridy++;
50         add(new ActionButton("backup", Images.DATA_BACKUP, new BackupListener()), gbc);
51
52         gbc.gridy++;
53         add(new ActionButton("restore", Images.DATA_RESTORE, new RestoreListener()), gbc);
54     }
55
56     private class NamedObjectsLister implements ActionListener JavaDoc {
57         public void actionPerformed(ActionEvent JavaDoc event) {
58             System.out.println("list all named objects");
59             String JavaDoc[] objectNames = new String JavaDoc[0];
60             try {
61                 objectNames = AdminGui.instance().getDb().objectNames();
62             } catch (Exception JavaDoc e) {
63                 dataInfoPanel.setDisplay(new JTextArea("Unable to retrieve object names: " + e.getMessage()));
64             }
65             if (objectNames.length == 0) {
66                 dataInfoPanel.setDisplay(new JTextArea("No named objects found."));
67             } else {
68                 JTextArea display = new JTextArea();
69                 for (int i = 0; i < objectNames.length; i++) {
70                     display.append(objectNames[i] + "\n");
71                 }
72                 dataInfoPanel.setDisplay(display);
73             }
74         }
75     }
76
77     private class BackupListener implements ActionListener JavaDoc {
78         public void actionPerformed(ActionEvent JavaDoc event) {
79             System.out.println("perform backup");
80             ThreadWorker worker = new ThreadWorker() {
81                 public Object JavaDoc construct() {
82                     JFileChooser fileChooser = new JFileChooser();
83                     fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
84                     fileChooser.showOpenDialog(DataFeatureBar.this);
85                     return fileChooser.getSelectedFile();
86                 }
87
88                 public void finished() {
89                     try {
90                         BackupWorker.backup((File JavaDoc) get());
91                     } catch (Exception JavaDoc e) {
92                         e.printStackTrace();
93                         MessageBox.showError("Backup failed", "Unable to backup: " + e);
94                     }
95                 }
96             };
97             worker.start();
98         }
99     }
100
101     private class RestoreListener implements ActionListener JavaDoc {
102         public void actionPerformed(ActionEvent JavaDoc event) {
103             System.out.println("perform restore");
104
105             ThreadWorker worker = new ThreadWorker() {
106                 public Object JavaDoc construct() {
107                     JFileChooser fileChooser = new JFileChooser();
108                     fileChooser.showOpenDialog(DataFeatureBar.this);
109                     return fileChooser.getSelectedFile();
110                 }
111
112                 public void finished() {
113                     try {
114                         BackupWorker.restore((File JavaDoc) get());
115                     } catch (Exception JavaDoc e) {
116                         MessageBox.showError("Restore failed", "Unable to restore: " + e);
117                     }
118                 }
119             };
120             worker.start();
121
122         }
123     }
124 }
125
Popular Tags