source: main/trunk/gli/src/org/greenstone/gatherer/gui/PreviewButton.java

Last change on this file was 37326, checked in by davidb, 15 months ago

Initial set of changes that allows the webswing version of GLI call a Javascript callback hander

  • Property svn:keywords set to Author Date Id Revision
File size: 5.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 * Copyright (C) 2006 New Zealand Digital Library Project
9 *
10 * <BR><BR>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * <BR><BR>
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * <BR><BR>
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *########################################################################
30 */
31package org.greenstone.gatherer.gui;
32
33import java.awt.*;
34import java.awt.event.*;
35import javax.swing.*;
36
37import org.webswing.toolkit.api.WebswingUtil;
38
39import org.greenstone.gatherer.Configuration;
40import org.greenstone.gatherer.Dictionary;
41import org.greenstone.gatherer.Gatherer;
42import org.greenstone.gatherer.collection.CollectionManager;
43import org.greenstone.gatherer.greenstone.LocalLibraryServer;
44import org.greenstone.gatherer.greenstone3.ServletConfiguration;
45import org.greenstone.gatherer.util.StaticStrings;
46
47
48public class PreviewButton
49 extends GLIButton {
50
51
52 static final public int HOME_PAGE = 1;
53 static final public int SEARCH_PAGE = 2;
54 static final public int CLASSIFIER_PAGE = 3;
55 static final public int DOCUMENT_PAGE = 4;
56
57 private String preview_address;
58 private int page_type = HOME_PAGE;
59 private boolean variable_preview = false;
60
61 private PreviewButtonOwner owner = null;
62 public PreviewButton() {
63 super();
64 PreviewButtonListener pbl = new PreviewButtonListener();
65 addActionListener(pbl);
66 }
67 public PreviewButton(String text, String tooltip) {
68 super(text, tooltip);
69 PreviewButtonListener pbl = new PreviewButtonListener();
70 addActionListener(pbl);
71 }
72
73 public void setOwner(PreviewButtonOwner o) {
74 owner = o;
75 }
76 public void setVariablePreview(boolean vp) {
77 variable_preview = vp;
78 }
79 protected void configureHomeURL() {
80 // we could be working with standalone collections or collection groups
81 // so getting a collection-name may have a collection group prefix
82 // This means CollectionManager.getLoadedCollectionName() needs to (and does) return (colgroup/)subcolname
83 String collGroupWithName = CollectionManager.getLoadedCollectionName(true);
84
85 // set up the home page for the current collection
86 if (Gatherer.GS3) { // GLI for GS3 case
87 if(Configuration.library_url == null) {// && !Configuration.fedora_info.isActive()) {
88 Gatherer.missingEXEC();
89 }
90 // if we now finally have a library URL, then continue with previewing
91 if(Configuration.library_url != null) {
92 // don't do anything fancy here
93 preview_address = Configuration.library_url.toString() + Configuration.getServletPath()
94 + "?a=p&sa=about&c=" + collGroupWithName + "&l=" + Configuration.getLanguage();
95 }
96 return;
97 }
98
99 if(Gatherer.isLocalLibrary) {
100 // check that the local library server is still running - doesn't do anything if it's not supposed to be running
101 // !! Don't like this here
102 LocalLibraryServer.checkServerRunning();
103 if(LocalLibraryServer.isURLPending()) {
104 // Remind the user to press Enter Library, and return from this method
105 JOptionPane.showMessageDialog(Gatherer.g_man,
106 Dictionary.get("General.LLS_Not_Started"),
107 Dictionary.get("General.LLS_Not_Started_Title"),
108 JOptionPane.INFORMATION_MESSAGE);
109 preview_address = null;
110 return;
111 }
112 }
113 // FLI or GLI for GS2 case (no library_url)
114 if(Configuration.fedora_info.isActive()) {
115 preview_address = Configuration.library_url.toString() + "?pid=true&title=true&terms=&query=pid~greenstone:"+collGroupWithName+"*&maxResults=20";
116 //+ "&l=" + Configuration.getLanguage();
117 } else {
118 preview_address = Configuration.library_url.toString() + "?c=" + collGroupWithName + "&l=" + Configuration.getLanguage();
119 }
120
121 String main_args = "&a=p&p=about";
122 /* this code is for switching the preview page depending on what
123 is currently active. but it is not complete yet
124 String main_args = null;
125 String params = null;
126 if (!variable_preview || owner == null) {
127 main_args = "&a=p&p=about";
128 } else {
129 page_type = owner.getPageType();
130 params = owner.getPageParams();
131
132 switch (page_type) {
133 case SEARCH_PAGE:
134 main_args = "&a=q&q="+params;
135 break;
136 case CLASSIFIER_PAGE:
137 main_args = "&a=d&cl="+params;
138 break;
139 case DOCUMENT_PAGE:
140 main_args = "&a=d&d="+params;
141 break;
142 case HOME_PAGE:
143 default:
144 main_args = "&a=p&p=about";
145
146
147 }
148
149
150 }
151 */
152 preview_address += main_args+StaticStrings.TIMESTAMP_ARGUMENT + System.currentTimeMillis();
153
154 }
155 private class PreviewButtonListener
156 implements ActionListener {
157
158 public void actionPerformed(ActionEvent event) {
159 Gatherer.c_man.saveCollection();
160
161 configureHomeURL();
162
163 if (Gatherer.GS3) {
164 // we need to rerun the convert in case the format stuff has changed
165 //for gs3, we don't need this anymore: Gatherer.c_man.convertToGS3Collection();
166 Gatherer.configGS3Server(Configuration.site_name, ServletConfiguration.ADD_COMMAND + Gatherer.c_man.getLoadedCollectionName());
167 }
168
169 if(preview_address != null) {
170 if (Gatherer.isWebswing) {
171 WebswingUtil.getWebswingApi().sendActionEvent("previewURL", preview_address, null);
172 }
173 else {
174 Gatherer.spawnBrowser(preview_address);
175 }
176 }
177
178
179
180 }
181
182 }
183
184}
Note: See TracBrowser for help on using the repository browser.