1 package org.simantics.team.ui;
\r
4 import java.io.IOException;
\r
5 import java.util.Deque;
\r
6 import java.util.LinkedList;
\r
8 import org.eclipse.core.runtime.preferences.InstanceScope;
\r
9 import org.eclipse.jface.dialogs.Dialog;
\r
10 import org.eclipse.jface.preference.IPersistentPreferenceStore;
\r
11 import org.eclipse.jface.preference.IPreferenceStore;
\r
12 import org.eclipse.jface.viewers.IStructuredSelection;
\r
13 import org.eclipse.jface.wizard.Wizard;
\r
14 import org.eclipse.jface.wizard.WizardDialog;
\r
15 import org.eclipse.swt.widgets.Display;
\r
16 import org.eclipse.ui.IImportWizard;
\r
17 import org.eclipse.ui.IWorkbench;
\r
18 import org.eclipse.ui.PlatformUI;
\r
19 import org.eclipse.ui.preferences.ScopedPreferenceStore;
\r
20 import org.simantics.db.common.utils.Logger;
\r
21 import org.simantics.db.exception.DatabaseException;
\r
22 import org.simantics.team.Activator;
\r
23 import org.simantics.team.Utils;
\r
24 import org.simantics.utils.ui.ErrorLogger;
\r
26 public class StageInitWizard extends Wizard implements IImportWizard {
\r
27 static public class Data {
\r
28 public Boolean ok = false;
\r
29 public Boolean requireExisting = false;
\r
30 public String comment; // Initial comment.
\r
31 Deque<String> recentLocations = new LinkedList<String>();;
\r
32 final File stagingFolder;
\r
33 public File teamFolder;
\r
34 public Data(File stagingFolder, File teamFolder) {
\r
35 this.stagingFolder = stagingFolder;
\r
36 this.teamFolder = teamFolder;
\r
39 public static boolean openInitWizard(final Data data)
\r
40 throws DatabaseException {
\r
41 final Display display = PlatformUI.getWorkbench().getDisplay();
\r
42 display.syncExec(new Runnable() {
\r
45 StageInitWizard stageInitWizard = new StageInitWizard(data);
\r
46 WizardDialog dialog = new WizardDialog(display.getActiveShell(), stageInitWizard);
\r
47 if (Dialog.OK != dialog.open())
\r
54 private final Data data;
\r
55 private static final int MAX_RECENT_IMPORT_PATHS = 10;
\r
56 private boolean readPreferences(IStructuredSelection selection) {
\r
57 IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);
\r
59 data.teamFolder = Utils.getTeamFolder();
\r
60 if (null == data.teamFolder)
\r
61 data.teamFolder = new File("Default Team Folder");
\r
62 } catch (DatabaseException e) {
\r
63 Logger.defaultLogError("Failed to get team folder.", e);
\r
64 data.teamFolder = new File("Default Team Folder");
\r
66 String recentPathsPref = store.getString(Preferences.RECENT_TEAM_FOLDERS);
\r
67 data.recentLocations = Preferences.decodePaths(recentPathsPref);
\r
70 private void writePreferences() throws IOException {
\r
71 IPersistentPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID);
\r
72 store.putValue(Preferences.CURRENT_TEAM_FOLDER, data.teamFolder.getAbsolutePath());
\r
73 store.putValue(Preferences.RECENT_TEAM_FOLDERS, Preferences.encodePaths(data.recentLocations));
\r
74 if (store.needsSaving())
\r
77 public StageInitWizard(Data data) {
\r
79 setWindowTitle("Staging Init");
\r
80 setNeedsProgressMonitor(true);
\r
83 public void init(IWorkbench workbench, IStructuredSelection selection) {
\r
84 readPreferences(selection);
\r
87 public void addPages() {
\r
89 addPage(new StageInitPage(data));
\r
92 public boolean performFinish() {
\r
94 data.recentLocations.addFirst(data.teamFolder.getAbsolutePath());
\r
95 Preferences.removeDuplicates(data.recentLocations);
\r
96 if (data.recentLocations.size() > MAX_RECENT_IMPORT_PATHS)
\r
97 data.recentLocations.pollLast();
\r
99 } catch (IOException e) {
\r
100 ErrorLogger.defaultLogError("Failed to write preferences", e);
\r