| 1 | |
package org.jtheque.core.managers.view.impl.frame.abstraction; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import org.jtheque.core.managers.Managers; |
| 20 | |
import org.jtheque.core.managers.beans.IBeansManager; |
| 21 | |
import org.jtheque.core.managers.error.IErrorManager; |
| 22 | |
import org.jtheque.core.managers.error.JThequeError; |
| 23 | |
import org.jtheque.core.managers.language.ILanguageManager; |
| 24 | |
import org.jtheque.core.managers.language.Internationalizable; |
| 25 | |
import org.jtheque.core.managers.resource.IResourceManager; |
| 26 | |
import org.jtheque.core.managers.view.able.IViewManager; |
| 27 | |
import org.jtheque.core.managers.view.able.IWindowView; |
| 28 | |
import org.jtheque.core.managers.view.able.components.IModel; |
| 29 | |
import org.jtheque.core.managers.view.impl.actions.ActionFactory; |
| 30 | |
import org.jtheque.core.managers.view.impl.components.ExtendedGlassPane; |
| 31 | |
import org.jtheque.core.managers.view.impl.components.InfiniteWaitFigure; |
| 32 | |
import org.jtheque.core.managers.view.impl.components.WaitFigure; |
| 33 | |
import org.jtheque.utils.collections.ArrayUtils; |
| 34 | |
|
| 35 | |
import javax.swing.Action; |
| 36 | |
import javax.swing.JDialog; |
| 37 | |
import javax.swing.JFrame; |
| 38 | |
import java.awt.Component; |
| 39 | |
import java.awt.Frame; |
| 40 | |
import java.awt.Image; |
| 41 | |
import java.util.ArrayList; |
| 42 | |
import java.util.Collection; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 0 | public abstract class SwingDialogView extends JDialog implements IWindowView, Internationalizable { |
| 50 | |
private String titleKey; |
| 51 | |
private Object[] titleReplaces; |
| 52 | |
|
| 53 | |
private IModel model; |
| 54 | |
|
| 55 | |
private boolean glassPaneInstalled; |
| 56 | |
private boolean waitFigureInstalled; |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
protected SwingDialogView(){ |
| 62 | 0 | this((Frame) Managers.getManager(IViewManager.class).getViews().getMainView().getImpl()); |
| 63 | 0 | } |
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
protected SwingDialogView(Frame frame) { |
| 71 | 0 | super(frame); |
| 72 | |
|
| 73 | 0 | setModal(true); |
| 74 | 0 | setResizable(true); |
| 75 | |
|
| 76 | 0 | Managers.getManager(ILanguageManager.class).addInternationalizable(this); |
| 77 | |
|
| 78 | 0 | setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); |
| 79 | 0 | setIconImage(getDefaultWindowIcon()); |
| 80 | 0 | } |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
void installGlassPane() { |
| 87 | 0 | Component glassPane = new ExtendedGlassPane(this); |
| 88 | 0 | setGlassPane(glassPane); |
| 89 | 0 | glassPane.setVisible(false); |
| 90 | 0 | } |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
void installWaitFigure() { |
| 97 | 0 | setWaitFigure(new InfiniteWaitFigure()); |
| 98 | 0 | } |
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
final ExtendedGlassPane getExtendedGlassPane() { |
| 106 | 0 | return (ExtendedGlassPane) getGlassPane(); |
| 107 | |
} |
| 108 | |
|
| 109 | |
@Override |
| 110 | |
public Component getGlassPane() { |
| 111 | 0 | installGlassPaneIfNecessary(); |
| 112 | |
|
| 113 | 0 | return super.getGlassPane(); |
| 114 | |
} |
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
public final void startWait() { |
| 120 | 0 | installWaitFigureIfNecessary(); |
| 121 | |
|
| 122 | 0 | getExtendedGlassPane().startWait(); |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
public final void stopWait() { |
| 129 | 0 | installWaitFigureIfNecessary(); |
| 130 | |
|
| 131 | 0 | getExtendedGlassPane().stopWait(); |
| 132 | 0 | } |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
protected static Image getDefaultWindowIcon() { |
| 140 | 0 | return Managers.getManager(IResourceManager.class).getImage( |
| 141 | |
"file:" + Managers.getCore().getApplication().getWindowIcon(), |
| 142 | |
Managers.getCore().getApplication().getWindowIconType()); |
| 143 | |
} |
| 144 | |
|
| 145 | |
|
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
protected final void setWaitFigure(WaitFigure waitFigure) { |
| 151 | 0 | getExtendedGlassPane().setWaitFigure(waitFigure); |
| 152 | 0 | } |
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
public static IViewManager getManager(){ |
| 160 | 0 | return Managers.getManager(IViewManager.class); |
| 161 | |
} |
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
|
| 169 | |
public static <T> T getBean(String name){ |
| 170 | 0 | return Managers.getManager(IBeansManager.class).<T>getBean(name); |
| 171 | |
} |
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
public Action getCloseAction(String key){ |
| 181 | 0 | return ActionFactory.createCloseViewAction(key, this); |
| 182 | |
} |
| 183 | |
|
| 184 | |
@Override |
| 185 | |
public void closeDown() { |
| 186 | 0 | setVisible(false); |
| 187 | 0 | } |
| 188 | |
|
| 189 | |
@Override |
| 190 | |
public void display() { |
| 191 | 0 | setVisible(true); |
| 192 | 0 | } |
| 193 | |
|
| 194 | |
@Override |
| 195 | |
public final void toFirstPlan() { |
| 196 | 0 | toFront(); |
| 197 | 0 | } |
| 198 | |
|
| 199 | |
@Override |
| 200 | |
public void sendMessage(String message, Object value) { |
| 201 | 0 | throw new UnsupportedOperationException(); |
| 202 | |
} |
| 203 | |
|
| 204 | |
@Override |
| 205 | |
public final void refresh() { |
| 206 | 0 | Managers.getManager(IViewManager.class).refresh(this); |
| 207 | 0 | } |
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
protected final void setTitleKey(String key, Object... replaces) { |
| 216 | 0 | titleKey = key; |
| 217 | |
|
| 218 | 0 | if(!ArrayUtils.isEmpty(replaces)){ |
| 219 | 0 | titleReplaces = ArrayUtils.copyOf(replaces); |
| 220 | |
} |
| 221 | |
|
| 222 | 0 | setTitle(getMessage(key, replaces)); |
| 223 | 0 | } |
| 224 | |
|
| 225 | |
@Override |
| 226 | |
public void refreshText() { |
| 227 | 0 | if (titleKey != null) { |
| 228 | 0 | setTitleKey(titleKey, titleReplaces); |
| 229 | |
} |
| 230 | 0 | } |
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
|
| 237 | |
public void setModel(IModel model) { |
| 238 | 0 | this.model = model; |
| 239 | 0 | } |
| 240 | |
|
| 241 | |
@Override |
| 242 | |
public IModel getModel() { |
| 243 | 0 | return model; |
| 244 | |
} |
| 245 | |
|
| 246 | |
@Override |
| 247 | |
public final JDialog getImpl() { |
| 248 | 0 | return this; |
| 249 | |
} |
| 250 | |
|
| 251 | |
@Override |
| 252 | |
public final boolean validateContent() { |
| 253 | 0 | Collection<JThequeError> errors = new ArrayList<JThequeError>(5); |
| 254 | |
|
| 255 | 0 | validate(errors); |
| 256 | |
|
| 257 | 0 | for (JThequeError error : errors) { |
| 258 | 0 | Managers.getManager(IErrorManager.class).addError(error); |
| 259 | |
} |
| 260 | |
|
| 261 | 0 | return errors.isEmpty(); |
| 262 | |
} |
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
protected static String getMessage(String key) { |
| 271 | 0 | return Managers.getManager(ILanguageManager.class).getMessage(key); |
| 272 | |
} |
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
protected static String getMessage(String key, Object... replaces) { |
| 282 | 0 | return Managers.getManager(ILanguageManager.class).getMessage(key, replaces); |
| 283 | |
} |
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
protected abstract void validate(Collection<JThequeError> errors); |
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
private void installGlassPaneIfNecessary() { |
| 296 | 0 | if (!glassPaneInstalled) { |
| 297 | 0 | installGlassPane(); |
| 298 | 0 | glassPaneInstalled = true; |
| 299 | |
} |
| 300 | 0 | } |
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
private void installWaitFigureIfNecessary() { |
| 306 | 0 | installGlassPaneIfNecessary(); |
| 307 | |
|
| 308 | 0 | if (!waitFigureInstalled) { |
| 309 | 0 | installWaitFigure(); |
| 310 | 0 | waitFigureInstalled = true; |
| 311 | |
} |
| 312 | 0 | } |
| 313 | |
} |