source: gli/trunk/src/org/greenstone/gatherer/gems/NewMetadataElementNamePrompt.java@ 18412

Last change on this file since 18412 was 18412, checked in by kjdon, 15 years ago

more modifications for RTL GLI, thanks to Amin Hedjazi

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: Katherine Don, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 2006 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gems;
38
39import java.awt.*;
40import java.awt.event.*;
41import javax.swing.*;
42
43import org.greenstone.gatherer.Configuration;
44import org.greenstone.gatherer.Dictionary;
45import org.greenstone.gatherer.gui.GLIButton;
46import org.greenstone.gatherer.gui.ModalDialog;
47
48public class NewMetadataElementNamePrompt
49 extends ModalDialog {
50 private Dimension SIZE = new Dimension(350, 120);
51
52 private boolean cancelled = false;
53 private String element_name = null;
54 private JTextField name_textfield = null;
55 private JDialog prompt;
56 private Object model;
57 public NewMetadataElementNamePrompt(Frame parent, boolean subelement, Object model) {
58 super(parent, true);
59 setSize(SIZE);
60 prompt = this;
61 this.model = model;
62 JPanel content_pane = (JPanel) getContentPane();
63 content_pane.setOpaque(true);
64 content_pane.setComponentOrientation(Dictionary.getOrientation());
65
66 JLabel name_label = new JLabel();
67 name_label.setComponentOrientation(Dictionary.getOrientation());
68 if (subelement) {
69 setTitle(Dictionary.get("GEMS.NewMetadataElementNamePrompt.SubTitle"));
70 name_label.setText(Dictionary.get("GEMS.NewMetadataElementNamePrompt.SubName"));
71 } else {
72 setTitle(Dictionary.get("GEMS.NewMetadataElementNamePrompt.Title"));
73 name_label.setText(Dictionary.get("GEMS.NewMetadataElementNamePrompt.Name"));
74 }
75
76 name_textfield = new JTextField();
77 name_textfield.setComponentOrientation(Dictionary.getOrientation());
78 name_textfield.addKeyListener(new KeyAdapter() {
79 public void keyPressed(KeyEvent e) {
80 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
81 //same as clicking OK button
82 validateElementName();
83 }
84 }
85 });
86
87 JPanel details_pane = new JPanel();
88 details_pane.setComponentOrientation(Dictionary.getOrientation());
89 details_pane.setLayout(new GridLayout(2,1));
90 details_pane.add(name_label);
91 details_pane.add(name_textfield);
92
93 JPanel button_pane = new JPanel();
94 button_pane.setLayout(new GridLayout(1,2));
95 GLIButton ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
96 GLIButton cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
97 button_pane.add(ok_button);
98 button_pane.add(cancel_button);
99
100 // Add listeners
101 ok_button.addActionListener(new ActionListener() {
102 public void actionPerformed(ActionEvent event) {
103 validateElementName();
104 }
105 });
106 cancel_button.addActionListener(new ActionListener() {
107 public void actionPerformed(ActionEvent event) {
108 cancelled = true;
109 prompt.dispose();
110 }
111 });
112
113 content_pane.setLayout(new BorderLayout(5,5));
114 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
115 content_pane.add(details_pane, BorderLayout.CENTER);
116 content_pane.add(button_pane, BorderLayout.SOUTH);
117
118 Dimension screen_size = Configuration.screen_size;
119 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
120 setVisible(true);
121
122 }
123
124 public String getName() {
125 return element_name;
126 }
127
128 public boolean isCancelled() {
129 return cancelled;
130 }
131
132 private void validateElementName() {
133 String name = name_textfield.getText();
134 if (name.equals("")) {
135 JOptionPane.showMessageDialog(prompt,Dictionary.get("GEMS.NewMetadataElementNamePrompt.EmptyName_Error_Message"), Dictionary.get("GEMS.NewMetadataElementNamePrompt.Name_Error"), JOptionPane.ERROR_MESSAGE);
136 return;
137 }
138 boolean already_used = false;
139 if (model instanceof MetadataSetModel) {
140 already_used = ((MetadataSetModel)model).doesChildWithThisNameExist(name);
141 } else if (model instanceof MetadataElementModel) {
142 already_used = ((MetadataElementModel)model).doesChildWithThisNameExist(name);
143 }
144 if (!already_used) {
145 element_name = name;
146 prompt.dispose();
147 } else {
148 JOptionPane.showMessageDialog(prompt,Dictionary.get("GEMS.NewMetadataElementNamePrompt.Name_Error_Message"), Dictionary.get("GEMS.NewMetadataElementNamePrompt.Name_Error"), JOptionPane.ERROR_MESSAGE);
149 }
150 }
151}
Note: See TracBrowser for help on using the repository browser.