~ubuntu-branches/ubuntu/utopic/eclipse-eclox/utopic

« back to all changes in this revision

Viewing changes to eclox.ui/src/eclox/ui/wizard/NewDoxyfileWizard.java

  • Committer: Package Import Robot
  • Author(s): Graham Inggs
  • Date: 2013-07-07 20:33:10 UTC
  • Revision ID: package-import@ubuntu.com-20130707203310-a44yw80gqtc2s9ob
Tags: upstream-0.10.0
ImportĀ upstreamĀ versionĀ 0.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (C) 2003, 2004, 2007, 2008, 2013, Guillaume Brocker
 
3
 * 
 
4
 * All rights reserved. This program and the accompanying materials
 
5
 * are made available under the terms of the Eclipse Public License v1.0
 
6
 * which accompanies this distribution, and is available at
 
7
 * http://www.eclipse.org/legal/epl-v10.html
 
8
 *
 
9
 * Contributors:
 
10
 *     Guillaume Brocker - Initial API and implementation
 
11
 *
 
12
 ******************************************************************************/ 
 
13
 
 
14
package eclox.ui.wizard;
 
15
 
 
16
import org.eclipse.core.resources.IFile;
 
17
import org.eclipse.core.resources.ResourcesPlugin;
 
18
import org.eclipse.core.runtime.IPath;
 
19
import org.eclipse.jface.dialogs.MessageDialog;
 
20
import org.eclipse.jface.viewers.IStructuredSelection;
 
21
import org.eclipse.jface.wizard.Wizard;
 
22
import org.eclipse.ui.INewWizard;
 
23
import org.eclipse.ui.IWorkbench;
 
24
 
 
25
import eclox.core.doxygen.Doxygen;
 
26
import eclox.core.doxygen.InvokeException;
 
27
import eclox.core.doxygen.RunException;
 
28
import eclox.ui.Plugin;
 
29
 
 
30
/**
 
31
 * Implement the new file wizard extension to provide a way to create
 
32
 * new doxyfiles.
 
33
 * 
 
34
 * @author gbrocker
 
35
 */
 
36
public class NewDoxyfileWizard extends Wizard implements INewWizard {
 
37
        
 
38
        private IFile                                   m_doxyfile;     ///< The created doxyfile.
 
39
        private NewDoxyfileWizardPage   m_page;         ///< The wizard page used to get the file name.
 
40
        
 
41
        /**
 
42
         * Retrieves the created doxyfile.
 
43
         * 
 
44
         * @return      the created doxyfile, null if none
 
45
         */
 
46
        public IFile getDoxyfile() {
 
47
                return m_doxyfile;
 
48
        }
 
49
        
 
50
        /**
 
51
         * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
 
52
         */
 
53
        public void init( IWorkbench workbench, IStructuredSelection selection ) {
 
54
                m_page = new NewDoxyfileWizardPage( selection );
 
55
                addPage( m_page );
 
56
                setWindowTitle( "New Doxygen Configuration" );
 
57
        }
 
58
        
 
59
        /**
 
60
         * @see org.eclipse.jface.wizard.Wizard#performFinish()
 
61
         */
 
62
        public boolean performFinish() {
 
63
                for(;;) {
 
64
                        // Creates the doxyfile resource.
 
65
                        IFile   doxyfile = createFile( m_page.getContainerFullPath(), m_page.getFileName() );
 
66
                        
 
67
                        // Warn user if the doxyfile exists.
 
68
                        if( doxyfile.exists() ) {
 
69
                                MessageDialog.openWarning(getShell(), "Resource Exists", "The resource " + doxyfile.getFullPath().toString() + " already exists !" );
 
70
                                return false;
 
71
                        }
 
72
        
 
73
                        // Creates the effective resource file.
 
74
                        try {
 
75
                                Doxygen.getDefault().generate( doxyfile );
 
76
                                m_doxyfile = doxyfile;
 
77
                                return true;
 
78
                        }
 
79
                        // Doxygen returned an error.
 
80
                        catch( RunException runException ) {
 
81
                                MessageDialog.openError(getShell(), "Doxygen Error", "An error occured while running doxygen. " + runException.toString());
 
82
                                return true;
 
83
                        }
 
84
                        // Doxygen was impossible to run. 
 
85
                        catch( InvokeException invokeException ) {
 
86
                                if( Plugin.editPreferencesAfterDoxygenInvocationFailed() ) {
 
87
                                        continue;
 
88
                                }
 
89
                                
 
90
                                // Stops the wizard.
 
91
                                return true;
 
92
                        }
 
93
                }
 
94
        }
 
95
        
 
96
        /**
 
97
         * Create the resource file.
 
98
         * 
 
99
         * @param containerPath The path to the container for the resource to create.
 
100
         * @param fileName              A string containnig the name of the file resource to create.
 
101
         * 
 
102
         * @return      The created file resource. The file system's file hasn't been created at this step.
 
103
         */
 
104
        private IFile createFile( IPath containerPath, String fileName ) {
 
105
                IFile   result;
 
106
                IPath   filePath;
 
107
                String  fileExtension;
 
108
                
 
109
                filePath = containerPath.append( fileName );
 
110
                fileExtension = filePath.getFileExtension(); 
 
111
                if( (fileExtension == null || fileExtension.compareToIgnoreCase( "Doxyfile" ) != 0) && fileName.compareToIgnoreCase("Doxyfile") != 0 ) {
 
112
                        filePath = filePath.addFileExtension( "Doxyfile" );
 
113
                }
 
114
                result = ResourcesPlugin.getWorkspace().getRoot().getFile( filePath );
 
115
                return result;
 
116
        }
 
117
}