001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.internal.ui;
016:
017: import net.refractions.udig.core.internal.CorePlugin;
018: import net.refractions.udig.ui.UDIGDragDropUtilities;
019: import net.refractions.udig.ui.WorkbenchConfiguration;
020: import net.refractions.udig.ui.preferences.PreferenceConstants;
021:
022: import org.eclipse.core.runtime.Platform;
023: import org.eclipse.jface.preference.IPreferenceStore;
024: import org.eclipse.ui.PlatformUI;
025: import org.eclipse.ui.application.ActionBarAdvisor;
026: import org.eclipse.ui.application.IActionBarConfigurer;
027: import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
028: import org.eclipse.ui.application.WorkbenchWindowAdvisor;
029: import org.osgi.service.prefs.Preferences;
030:
031: /**
032: * Public base class for configuring a workbench window.
033: * <p>
034: * The workbench window advisor object is created in response to a workbench
035: * window being created (one per window), and is used to configure the window.
036: * </p>
037: * <p>
038: * An application should declare a subclass of
039: * <code>WorkbenchWindowAdvisor</code> and override methods to configure
040: * workbench windows to suit the needs of the particular application.
041: * </p>
042: * <p>
043: * The following advisor methods are called at strategic points in the workbench
044: * window's lifecycle (as with the workbench advisor, all occur within the
045: * dynamic scope of the call to
046: * {@link PlatformUI#createAndRunWorkbench PlatformUI.createAndRunWorkbench}):
047: * <ul>
048: * <li><code>preWindowOpen</code> - called as the window is being opened; use
049: * to configure aspects of the window other than actions bars</li>
050: * <li><code>postWindowRestore</code> - called after the window has been
051: * recreated from a previously saved state; use to adjust the restored window</li>
052: * <li><code>postWindowCreate</code> - called after the window has been
053: * created, either from an initial state or from a restored state; used to
054: * adjust the window</li>
055: * <li><code>openIntro</code> - called immediately before the window is
056: * opened in order to create the introduction component, if any.</li>
057: * <li><code>postWindowOpen</code> - called after the window has been opened;
058: * use to hook window listeners, etc.</li>
059: * <li><code>preWindowShellClose</code> - called when the window's shell is
060: * closed by the user; use to pre-screen window closings</li>
061: * </ul>
062: * </p>
063: *
064: * @author cole.markham
065: * @since 1.0.0
066: */
067: public class UDIGWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
068:
069: /**
070: * Constructor
071: *
072: * @param configurer
073: */
074: public UDIGWorkbenchWindowAdvisor(
075: IWorkbenchWindowConfigurer configurer) {
076: super (configurer);
077: }
078:
079: @Override
080: public void preWindowOpen() {
081: super .preWindowOpen();
082: IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
083: WorkbenchConfiguration configuration = lookupConfiguration();
084: configuration.configureWorkbench(configurer);
085:
086: UDIGDragDropUtilities.registerUDigDND(configurer);
087: }
088:
089: private WorkbenchConfiguration lookupConfiguration() {
090:
091: Class interfaceClass = WorkbenchConfiguration.class;
092: String prefConstant = PreferenceConstants.P_WORKBENCH_CONFIGURATION;
093: String xpid = WorkbenchConfiguration.XPID;
094: String idField = WorkbenchConfiguration.ATTR_ID;
095: String classField = WorkbenchConfiguration.ATTR_CLASS;
096:
097: WorkbenchConfiguration config = (WorkbenchConfiguration) UiPlugin
098: .lookupConfigurationObject(interfaceClass, UiPlugin
099: .getDefault().getPreferenceStore(),
100: UiPlugin.ID, prefConstant, xpid, idField,
101: classField);
102:
103: if (config == null) {
104: return new UDIGWorkbenchConfiguration();
105:
106: }
107: return config;
108: }
109:
110: @Override
111: public ActionBarAdvisor createActionBarAdvisor(
112: IActionBarConfigurer configurer) {
113: return new UDIGActionBarAdvisor(configurer);
114: }
115:
116: @Override
117: public void postWindowOpen() {
118: super .postWindowOpen();
119: try {
120: Preferences userPreferences = UiPlugin.getUserPreferences();
121: if (!userPreferences
122: .nodeExists("net.refractions.udig.ui.firstRun")) { //$NON-NLS-1$
123: firstRun();
124: } else {
125: showTip();
126: }
127: } catch (Exception e) {
128: UiPlugin.log("", e); //$NON-NLS-1$
129: }
130: }
131:
132: private void showTip() {
133:
134: try {
135: IPreferenceStore store = UiPlugin.getDefault()
136: .getPreferenceStore();
137: if (store.getBoolean(PreferenceConstants.P_SHOW_TIPS)
138: && TipDialog.hasTips()
139: && !CorePlugin.isDeveloping()) {
140: TipDialog dialog = new TipDialog(this
141: .getWindowConfigurer().getWindow().getShell());
142: dialog.setBlockOnOpen(false);
143: dialog.open();
144: }
145: } catch (Exception e) {
146: UiPlugin.log("", e); //$NON-NLS-1$
147: }
148: }
149:
150: private void firstRun() throws Exception {
151: // getWindowConfigurer().getWindow().getShell().setMaximized(true);
152: Preferences userPreferences = UiPlugin.getUserPreferences();
153: userPreferences
154: .node("net.refractions.udig.ui.firstRun").putBoolean("net.refractions.udig.ui.isFirstRun", false); //$NON-NLS-1$ //$NON-NLS-2$
155:
156: if (Platform.getOS().equals(Platform.OS_LINUX)) {
157: LinuxAdvancedDialog dialog = new LinuxAdvancedDialog(
158: getWindowConfigurer().getWindow().getShell());
159: dialog.open();
160: }
161: }
162: }
|