001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.project.ui.internal.actions;
018:
019: import net.refractions.udig.project.internal.ProjectPlugin;
020: import net.refractions.udig.project.ui.internal.Messages;
021:
022: import org.eclipse.core.runtime.IProgressMonitor;
023: import org.eclipse.core.runtime.IStatus;
024: import org.eclipse.core.runtime.Status;
025: import org.eclipse.core.runtime.jobs.Job;
026: import org.eclipse.jface.action.IAction;
027: import org.eclipse.jface.viewers.ISelection;
028: import org.eclipse.swt.widgets.DirectoryDialog;
029: import org.eclipse.swt.widgets.Display;
030: import org.eclipse.ui.IViewActionDelegate;
031: import org.eclipse.ui.IViewPart;
032: import org.eclipse.ui.IWorkbenchWindow;
033: import org.eclipse.ui.IWorkbenchWindowActionDelegate;
034:
035: /**
036: * Opens a Project ..
037: *
038: * @author jeichar
039: * @since 0.3
040: */
041: public class OpenProject implements IViewActionDelegate,
042: IWorkbenchWindowActionDelegate {
043:
044: private volatile Job job;
045:
046: /**
047: * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
048: */
049: public void init(IViewPart view) {
050: // do nothing
051: }
052:
053: /**
054: * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
055: */
056: public void run(IAction action) {
057:
058: DirectoryDialog dialog = new DirectoryDialog(Display
059: .getDefault().getActiveShell());
060: dialog.setFilterPath(Messages.OpenProject_newProject_filename);
061: dialog.setMessage(Messages.OpenProject_selectProject);
062: dialog.setText(Messages.OpenProject_openProject);
063: final String path = dialog.open();
064: if (path == null)
065: return;
066:
067: if (job == null) {
068: synchronized (this ) {
069: if (job == null) {
070: job = new Job(
071: Messages.OpenProject_openProject_title) {
072:
073: protected IStatus run(IProgressMonitor monitor) {
074: ProjectPlugin.getPlugin()
075: .getProjectRegistry().getProject(
076: path);
077: return Status.OK_STATUS;
078: }
079:
080: };
081:
082: }
083: }
084: }
085: job.schedule();
086:
087: }
088:
089: /**
090: * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
091: * org.eclipse.jface.viewers.ISelection)
092: */
093: public void selectionChanged(IAction action, ISelection selection) {
094: // do nothing
095: }
096:
097: /*
098: * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
099: */
100: public void dispose() {
101: // okay then
102: }
103:
104: /*
105: * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
106: */
107: public void init(IWorkbenchWindow window) {
108: //
109: }
110:
111: }
|