001: package net.sourceforge.tracelog.ui;
002:
003: import net.sourceforge.tracelog.utils.ProjectProperties;
004:
005: import org.apache.log4j.Logger;
006: import org.eclipse.swt.widgets.Composite;
007: import org.eclipse.swt.widgets.Shell;
008:
009: public class WidgetFactory {
010: private static Logger log = Logger.getLogger(WidgetFactory.class);
011: private static WidgetFactory widgetFactory;
012:
013: public static WidgetFactory getInstance() {
014: if (widgetFactory == null) {
015: widgetFactory = new WidgetFactory();
016: }
017:
018: return widgetFactory;
019: }
020:
021: private ProjectProperties projectProperties;
022:
023: private WidgetFactory() {
024: this .projectProperties = ProjectProperties.getInstance();
025: }
026:
027: public AbstractWidget createAboutShell(Shell parentShell,
028: IMediator mediator) {
029: return getWidget(parentShell, mediator, projectProperties
030: .getAboutShell());
031: }
032:
033: public AbstractWidget createHistoryShell(Shell parentShell,
034: IMediator mediator) {
035: return getWidget(parentShell, mediator, projectProperties
036: .getHistoryShell());
037: }
038:
039: public AbstractWidget createLogConfigShellColorChooser(
040: Shell parentShell, Composite parentComposite,
041: IMediator mediator) {
042: return getWidget(parentShell, parentComposite, mediator,
043: projectProperties.getOptionShellLogFileColorChooser());
044: }
045:
046: public AbstractWidget createMainShell() {
047: return getWidget(null, null, projectProperties.getMainShell());
048: }
049:
050: public AbstractWidget createMainShellButtonBar(Shell parentShell,
051: IMediator mediator) {
052: return getWidget(parentShell, mediator, projectProperties
053: .getMainShellButtonBar());
054: }
055:
056: public AbstractWidget createMainShellLogViewer(Shell parentShell,
057: IMediator mediator) {
058: return getWidget(parentShell, mediator, projectProperties
059: .getMainShellLogViewer());
060: }
061:
062: public AbstractWidget createMainShellMenuBar(Shell parentShell,
063: IMediator mediator) {
064: return getWidget(parentShell, mediator, projectProperties
065: .getMainShellMenuBar());
066: }
067:
068: public AbstractWidget createOptionShell(Shell parentShell,
069: IMediator mediator) {
070: return getWidget(parentShell, mediator, projectProperties
071: .getOptionShell());
072: }
073:
074: public AbstractWidget createOptionShellGeneral(Shell parentShell,
075: Composite parentComposite, IMediator mediator) {
076: return getWidget(parentShell, parentComposite, mediator,
077: projectProperties.getOptionShellGeneral());
078: }
079:
080: public AbstractWidget createOptionShellLogFile(Shell parentShell,
081: Composite parentComposite, IMediator mediator) {
082: return getWidget(parentShell, parentComposite, mediator,
083: projectProperties.getOptionShellLogFile());
084: }
085:
086: public AbstractWidget createOptionShellLogGroup(Shell parentShell,
087: Composite parentComposite, IMediator mediator) {
088: return getWidget(parentShell, parentComposite, mediator,
089: projectProperties.getOptionShellLogGroup());
090: }
091:
092: public AbstractWidget createTrayShell(IMediator mediator) {
093: return getWidget(null, mediator, projectProperties
094: .getTrayShell());
095: }
096:
097: private AbstractWidget getWidget(Shell parentShell,
098: Composite parentComposite, IMediator mediator,
099: String className) {
100: AbstractWidget widget = null;
101:
102: try {
103: Class<?> clazz = Class.forName(className);
104:
105: widget = (AbstractWidget) clazz.newInstance();
106:
107: if (parentShell != null) {
108: widget.setParentShell((Shell) parentShell);
109: }
110:
111: if (parentComposite != null) {
112: widget.setParentComposite(parentComposite);
113: }
114:
115: widget.setMediator(mediator);
116: } catch (Exception e) {
117: e.printStackTrace();
118: log.error(e.getMessage());
119: }
120:
121: return widget;
122: }
123:
124: private AbstractWidget getWidget(Shell parentShell,
125: IMediator mediator, String className) {
126: return getWidget(parentShell, null, mediator, className);
127: }
128: }
|