001: package com.xoetrope.editor.eclipse;
002:
003: import java.util.HashMap;
004: import java.util.Iterator;
005: import java.util.prefs.Preferences;
006:
007: import javax.swing.JOptionPane;
008:
009: import net.xoetrope.editor.project.XEditorProject;
010: import net.xoetrope.editor.project.XEditorProjectManager;
011: import com.xoetrope.editor.lm.XModuleRegistrationDialog;
012: import net.xoetrope.xui.helper.XuiUtilities;
013:
014: import org.eclipse.jface.action.IAction;
015: import org.eclipse.jface.viewers.ISelection;
016: import org.eclipse.ui.IWorkbenchWindow;
017: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
018:
019: /**
020: * Check the project initialization and set default properties as needed
021: * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
022: * the GNU Public License (GPL), please see license.txt for more details. If
023: * you make commercial use of this software you must purchase a commercial
024: * license from Xoetrope.</p>
025: * <p> $Revision: 1.8 $</p>
026: */
027: public class XuiProProjectChooserAction implements
028: IWorkbenchWindowActionDelegate {
029: private IWorkbenchWindow window;
030:
031: /**
032: * Creates a new instance of XuiProProjectCheck
033: */
034: public XuiProProjectChooserAction() {
035: }
036:
037: /**
038: * The action has been activated. The argument of the method represents the
039: * 'real' action sitting in the workbench UI.
040: *
041: * @see IWorkbenchWindowActionDelegate#run
042: */
043: public void run(IAction action) {
044: int numProjects = XEditorProjectManager.getNumProjects();
045: XEditorProject currentProject = (XEditorProject) XEditorProjectManager
046: .getCurrentProject();
047: String[] possibilities = new String[numProjects];
048: int idx = 0;
049: HashMap<String, XEditorProject> projects = XEditorProjectManager
050: .getProjects();
051: Iterator<String> iter = projects.keySet().iterator();
052: while (iter.hasNext()) {
053: XEditorProject proj = projects.get(iter.next());
054: possibilities[idx++] = proj.getProjectTitle() + ": "
055: + proj.getPath();
056: }
057:
058: String s = (String) JOptionPane.showInputDialog(null,
059: "Select the current project:", "Project chooser",
060: JOptionPane.PLAIN_MESSAGE, null, possibilities,
061: currentProject.getProjectTitle() + ": "
062: + currentProject.getPath());
063:
064: //If a string was returned, say so.
065: if (s != null)
066: XEditorProjectManager.setCurrentProject(s.substring(s
067: .indexOf(": ") + 2));
068: }
069:
070: /**
071: * Selection in the workbench has been changed. We can change the state of the
072: * 'real' action here if we want, but this can only happen after the delegate
073: * has been created.
074: *
075: * @see IWorkbenchWindowActionDelegate#selectionChanged
076: */
077: public void selectionChanged(IAction action, ISelection selection) {
078: action.setEnabled(XEditorProjectManager
079: .isUserRegistered("XUI Pro")
080: && (XEditorProjectManager.getNumProjects() > 1));
081: }
082:
083: /**
084: * We can use this method to dispose of any system resources we previously
085: * allocated.
086: *
087: * @see IWorkbenchWindowActionDelegate#dispose
088: */
089: public void dispose() {
090: }
091:
092: /**
093: * We will cache window object in order to be able to provide parent shell for
094: * the message dialog.
095: *
096: * @see IWorkbenchWindowActionDelegate#init
097: */
098: public void init(IWorkbenchWindow window) {
099: this.window = window;
100: }
101: }
|