source: main/trunk/gli/src/org/greenstone/gatherer/gui/FormatPane.java@ 32706

Last change on this file since 32706 was 24424, checked in by ak19, 13 years ago

The preview button was becoming enabled if the user clicked on a GS3 format statement even when the collection is still unbuilt. So it no longer enables the preview button if the collection is unbuilt.

  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 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: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 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.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import javax.swing.*;
42
43import org.greenstone.gatherer.Dictionary;
44import org.greenstone.gatherer.Gatherer;
45import org.greenstone.gatherer.cdm.CollectionDesignManager;
46import org.greenstone.gatherer.cdm.FormatManager;
47import org.greenstone.gatherer.cdm.Format;
48import org.greenstone.gatherer.cdm.Format4gs3Manager;
49import org.greenstone.gatherer.cdm.Format4gs3;
50import org.greenstone.gatherer.cdm.DOMProxyListEntry;
51import org.greenstone.gatherer.cdm.Control;
52import org.greenstone.gatherer.Configuration;
53import org.greenstone.gatherer.shell.GShell;
54import org.greenstone.gatherer.shell.GShellEvent;
55import org.greenstone.gatherer.shell.GShellListener;
56
57public class FormatPane
58extends BaseConfigPane
59implements PreviewButtonOwner,GShellListener{
60
61
62 /** The button for viewing the collection. */
63 private static PreviewButton preview_button = null;
64 private boolean buildCanceled = false;
65
66 /** The constructor. */
67 public FormatPane () {
68 super ();
69 if (Gatherer.GS3) {
70 contents = new String []{ "CDM.GUI.General", "CDM.GUI.SearchMetadata", "CDM.GUI.Formats", "CDM.GUI.Translation" };
71 } else {
72 contents = new String []{ "CDM.GUI.General", "CDM.GUI.SearchMetadata", "CDM.GUI.Formats", "CDM.GUI.Translation", "CDM.GUI.SuperCollection","CDM.GUI.Macros", "CDM.GUI.DepositorMetadata" };
73 }
74 JPanel side_panel = new JPanel ();
75 side_panel.setComponentOrientation(Dictionary.getOrientation());
76 side_panel.setLayout (new BorderLayout ());
77 remove (tree_pane);
78 side_panel.add (tree_pane, BorderLayout.CENTER);
79 JPanel preview_pane = new JPanel ();
80 preview_pane.setComponentOrientation(Dictionary.getOrientation());
81
82 preview_pane.setLayout (new BorderLayout ());
83 preview_pane.setBorder (BorderFactory.createEmptyBorder (5,0,0,0));
84
85 preview_button = new PreviewButton (Dictionary.get ("CreatePane.Preview_Collection"), Dictionary.get ("CreatePane.Preview_Collection_Tooltip"));
86 preview_button.setEnabled (true);
87 preview_button.setVariablePreview (true);
88 preview_button.setOwner (this);
89 preview_pane.add (preview_button, BorderLayout.CENTER);
90
91
92 preview_button.addActionListener (new ActionListener () {
93 public void actionPerformed (ActionEvent event) {
94 if (view != null) {
95 view.loseFocus ();
96 }
97
98 if (buildCanceled){
99 WarningDialog dialog = new WarningDialog ("warning.ShowPreviousCollection", Dictionary.get ("ShowPreviousCollection.Title"), Dictionary.get ("ShowPreviousCollection.Message"), null, false);
100 dialog.display ();
101 dialog.dispose ();
102 }
103 }
104
105 });
106 side_panel.add (preview_pane, BorderLayout.SOUTH);
107
108 add (side_panel, BorderLayout.LINE_START);
109 }
110
111 public void gainFocus (){
112
113 if (Gatherer.c_man.built () && Configuration.library_url != null) {
114 preview_button.setEnabled (true);
115 }
116 else{
117 preview_button.setEnabled (false);
118 }
119
120 }
121 public static void setPreviewButton (boolean ready_to_preview) {
122 // if we're asked to enable the preview button, yet the collection is still
123 // unbuilt (as could happen when someone clicks on a format statement before
124 // building the collection), then shouldn't enable previewing.
125 if(ready_to_preview && !Gatherer.c_man.built()) {
126 ready_to_preview = false;
127 }
128 preview_button.setEnabled (ready_to_preview);
129 }
130
131 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
132 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
133 */
134 public synchronized void message (GShellEvent event) {
135 // We don't care.
136 }
137
138
139 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell begins its task. Implementation side-effect, not actually used.
140 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
141 */
142 public synchronized void processBegun (GShellEvent event) {
143 buildCanceled = false;
144 }
145
146 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
147 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
148 */
149 public synchronized void processComplete (GShellEvent event) {
150 if(event.getStatus () == GShell.OK) {
151 if(event.getType () == GShell.BUILD) {
152 buildCanceled = false;
153 }
154 }
155 else {
156 buildCanceled = true;
157 }
158 }
159
160
161
162 protected Control getSubControls (String type) {
163 if(type.equals ("CDM.GUI.General")) {
164 return CollectionDesignManager.general_manager.getControls ();
165 }
166 if (type.equals ("CDM.GUI.SearchMetadata")) {
167 return CollectionDesignManager.searchmetadata_manager.getControls ();
168 }
169 if(type.equals ("CDM.GUI.Formats")) {
170 return CollectionDesignManager.format_manager.getControls ();
171 }
172 if (type.equals ("CDM.GUI.Translation")) {
173 return CollectionDesignManager.translation_manager.getControls ();
174 }
175 if (type.equals ("CDM.GUI.Macros")) {
176 return CollectionDesignManager.macros_manager.getControls ();
177 }
178 if(type.equals ("CDM.GUI.SuperCollection")) {
179 return CollectionDesignManager.supercollection_manager.getControls ();
180 }
181 if(type.equals ("CDM.GUI.DepositorMetadata")) {
182 return CollectionDesignManager.depositormetadata_manager.getControls ();
183 }
184 return null;
185 }
186
187 private int page_type = PreviewButton.HOME_PAGE;
188 private String page_params = "";
189 public int getPageType () {
190 System.err.println ("view type = "+view_type);
191 if (view_type.equals ("CDM.GUI.General") || view_type.equals ("CDM.GUI.Translation")) {
192 page_type = PreviewButton.HOME_PAGE;
193 } else {
194
195 if (Gatherer.GS3 == true) {
196 Format4gs3 current_format = ((Format4gs3Manager.FormatControl)view).getCurrentFormat ();
197 String feature_name = current_format.getFeatureName ();
198
199 if (feature_name.equals ("browse")) {
200 page_type = PreviewButton.CLASSIFIER_PAGE;
201 page_params = "CL1";
202 } else
203 if (feature_name.startsWith ("CL")) {
204 page_type = PreviewButton.CLASSIFIER_PAGE;
205 page_params = current_format.getFeatureName ();
206 }
207 else if (feature_name.startsWith ("display")) {
208 page_type = PreviewButton.DOCUMENT_PAGE;
209 page_params = "HASH01e4da6100fdbb11b7ef244b";
210 }
211 else if (feature_name.equals ("search")) {
212 page_type = PreviewButton.SEARCH_PAGE;
213 page_params = "the";
214 } else { // HOME_PAGE
215 }
216 } else {
217 Format current_format = ((FormatManager.FormatControl)view).getCurrentFormat ();
218 String feature_name = current_format.getFeatureName ();
219 System.err.println ("current format = "+feature_name);
220 if (feature_name.equals ("")) {
221 // must be modifying VList or HList
222 // what should we do???
223 page_type = PreviewButton.CLASSIFIER_PAGE;
224 page_params = "CL1";
225 }
226 if (feature_name.startsWith ("CL")) {
227 page_type = PreviewButton.CLASSIFIER_PAGE;
228 page_params = current_format.getFeatureName ();
229 }
230 else if (feature_name.startsWith ("Document")) {
231 page_type = PreviewButton.DOCUMENT_PAGE;
232 page_params = "HASH01e4da6100fdbb11b7ef244b";
233 }
234 else if (feature_name.equals ("Search")) {
235 page_type = PreviewButton.SEARCH_PAGE;
236 page_params = "the";
237 }
238 }
239 }
240 return page_type;
241 }
242
243 public String getPageParams () {
244 return page_params;
245 }
246
247}
Note: See TracBrowser for help on using the repository browser.