### Eclipse Workspace Patch 1.0 #P org.eclipse.photran.ui Index: plugin.xml =================================================================== RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.ui/plugin.xml,v retrieving revision 1.20 diff -u -r1.20 plugin.xml --- plugin.xml 11 Feb 2009 18:00:52 -0000 1.20 +++ plugin.xml 23 Jul 2009 18:38:39 -0000 @@ -230,4 +230,16 @@ id="sourceViewerConfig" name="Source Viewer Configuration" schema="schema/sourceViewerConfig.exsd"/> + + + + + + + + #P org.eclipse.photran.core Index: plugin.xml =================================================================== RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.core/plugin.xml,v retrieving revision 1.16 diff -u -r1.16 plugin.xml --- plugin.xml 27 Aug 2008 21:38:59 -0000 1.16 +++ plugin.xml 23 Jul 2009 18:38:40 -0000 @@ -129,4 +129,18 @@ priority="high"/> + + + + + + + + + + Index: src/org/eclipse/photran/core/FProjectNature.java =================================================================== RCS file: src/org/eclipse/photran/core/FProjectNature.java diff -N src/org/eclipse/photran/core/FProjectNature.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/photran/core/FProjectNature.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - initial API and implementation + *******************************************************************************/ + +package org.eclipse.photran.core; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IProjectNature; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * This file copied (mostly) from org.eclipse.cdt.core.CProjectNature. + * + * @author Matt Scarpino + */ +public class FProjectNature implements IProjectNature { + + public static final String F_NATURE_ID = "org.eclipse.photran.core.fnature"; //$NON-NLS-1$ + + private IProject fProject; + + public FProjectNature() { + } + + public FProjectNature(IProject project) { + setProject(project); + } + + public static void addFNature(IProject project, IProgressMonitor mon) throws CoreException { + addNature(project, F_NATURE_ID, mon); + } + + public static void removeFNature(IProject project, IProgressMonitor mon) throws CoreException { + removeNature(project, F_NATURE_ID, mon); + } + + /** + * Utility method for adding a nature to a project. + * + * @param project + * the project to add the nature + * @param natureId + * the id of the nature to assign to the project + * @param monitor + * a progress monitor to indicate the duration of the operation, + * or null if progress reporting is not required. + * + */ + public static void addNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException { + IProjectDescription description = project.getDescription(); + String[] prevNatures = description.getNatureIds(); + for(int i=0; inull if progress reporting is not required. + */ + public static void removeNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException { + IProjectDescription description = project.getDescription(); + String[] prevNatures = description.getNatureIds(); + List newNatures = new ArrayList(Arrays.asList(prevNatures)); + newNatures.remove(natureId); + description.setNatureIds((String[])newNatures.toArray(new String[newNatures.size()])); + project.setDescription(description, monitor); + } + + /** + * @see IProjectNature#configure + */ + public void configure() throws CoreException { + } + + /** + * @see IProjectNature#deconfigure + */ + public void deconfigure() throws CoreException { + } + + /** + * @see IProjectNature#getProject + */ + public IProject getProject() { + return fProject; + } + + /** + * @see IProjectNature#setProject + */ + public void setProject(IProject project) { + fProject = project; + } +} + #P org.eclipse.photran.cdtinterface Index: src/org/eclipse/photran/cdtinterface/ui/FortranProjectWizard.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.cdtinterface/src/org/eclipse/photran/cdtinterface/ui/FortranProjectWizard.java,v retrieving revision 1.2 diff -u -r1.2 FortranProjectWizard.java --- src/org/eclipse/photran/cdtinterface/ui/FortranProjectWizard.java 16 Aug 2007 22:49:56 -0000 1.2 +++ src/org/eclipse/photran/cdtinterface/ui/FortranProjectWizard.java 23 Jul 2009 18:38:41 -0000 @@ -10,15 +10,29 @@ *******************************************************************************/ package org.eclipse.photran.cdtinterface.ui; +import java.io.ByteArrayInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.util.ArrayList; +import java.util.Iterator; + import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; import org.eclipse.cdt.ui.newui.UIMessages; import org.eclipse.cdt.ui.wizards.CDTCommonProjectWizard; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.photran.core.FProjectNature; /** * @author ??? + * @author Matt Scarpino - 7/20/2009 - Updated to include Fortran nature in project */ public class FortranProjectWizard extends CDTCommonProjectWizard { @@ -31,18 +45,100 @@ public String[] getNatures() { - return new String[] { CProjectNature.C_NATURE_ID }; + return new String[] { FProjectNature.F_NATURE_ID, CProjectNature.C_NATURE_ID }; } + /** + * This method is called immediately after the createIProject() method in + * the CDTCommonProjectWizard class + */ protected IProject continueCreation(IProject prj) { try { - CProjectNature.addCNature(prj, new NullProgressMonitor()); + // Add C nature to the project + CProjectNature.addCNature(prj, new NullProgressMonitor()); + + // Add Fortran nature to the project + FProjectNature.addFNature(prj, new NullProgressMonitor()); } catch (CoreException e) {} return prj; - } + } + + /** + * This method is called within the performFinish() method of the + * CDTCommonProjectWizard class. Among other things, it sets the Photran + * nature first in the project's nature list. This ensures that the project + * will be displayed as a Fortran project in the Photran navigator. + */ + protected boolean setCreated() throws CoreException + { + ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); + + ICProjectDescription des = mngr.getProjectDescription(newProject, false); + if(des.isCdtProjectCreating()) + { + des = mngr.getProjectDescription(newProject, true); + des.setCdtProjectCreated(); + mngr.setProjectDescription(newProject, des, false, null); + return true; + } + + // Access the .project file in the recently-created project + final IFile projFile = (IFile)newProject.findMember(IProjectDescription.DESCRIPTION_FILE_NAME); + if(projFile.exists()) + { + try + { + // Create a list of lines in .project file + RandomAccessFile raFile = new RandomAccessFile(projFile.getLocation().toOSString(), "rws"); + ArrayList lineList = new ArrayList(); + String line; + while((line = raFile.readLine()) != null) + lineList.add(line); + raFile.close(); + + // Find the natures in the list + Iterator itr = lineList.iterator(); + int first_index = 0, phot_index = 0; + while (itr.hasNext()) + { + line = (String)itr.next(); + if(line.trim().equals("")) + first_index = lineList.indexOf(line) + 1; + else if(line.contains("photran")) + phot_index = lineList.indexOf(line); + } + + // Swap the photran nature with the first nature + String temp = (String)lineList.get(first_index); + lineList.set(first_index, lineList.get(phot_index)); + lineList.set(phot_index, temp); + + // Write the new lines to the .project file + itr = lineList.iterator(); + StringBuffer content = new StringBuffer(""); + while (itr.hasNext()) + { + content.append((String)itr.next() + "\n"); + } + projFile.setContents(new ByteArrayInputStream(content.toString().getBytes()), IFile.FORCE, null); + // Deallocate + lineList.clear(); + } + catch (FileNotFoundException e) { + e.printStackTrace(); + } + catch (IOException e) { + e.printStackTrace(); + } + catch (CoreException e) { + e.printStackTrace(); + } + } + return false; + } } Index: src/org/eclipse/photran/cdtinterface/ui/FortranView.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.photran/org.eclipse.photran.cdtinterface/src/org/eclipse/photran/cdtinterface/ui/FortranView.java,v retrieving revision 1.3 diff -u -r1.3 FortranView.java --- src/org/eclipse/photran/cdtinterface/ui/FortranView.java 16 Aug 2007 22:49:56 -0000 1.3 +++ src/org/eclipse/photran/cdtinterface/ui/FortranView.java 23 Jul 2009 18:38:41 -0000 @@ -11,13 +11,22 @@ package org.eclipse.photran.cdtinterface.ui; import org.eclipse.cdt.internal.ui.cview.CView; +import org.eclipse.cdt.internal.ui.cview.CViewLabelProvider; +import org.eclipse.cdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; +import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; +import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider; /** * The Fortran Projects View is just the C/C++ Projects View with a different name. * * @author Jeff Overbey + * @author Matt Scarpino - 7/20/2009 - Updated to access Fortran-specific label provider. */ public class FortranView extends CView { public static final String FORTRAN_VIEW_ID = "org.eclipse.photran.ui.FortranView"; -} + + protected CUILabelProvider createLabelProvider() { + return new FViewLabelProvider(AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS, AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS | CElementImageProvider.SMALL_ICONS); + } +} \ No newline at end of file Index: src/org/eclipse/photran/cdtinterface/ui/FViewLabelProvider.java =================================================================== RCS file: src/org/eclipse/photran/cdtinterface/ui/FViewLabelProvider.java diff -N src/org/eclipse/photran/cdtinterface/ui/FViewLabelProvider.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/photran/cdtinterface/ui/FViewLabelProvider.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2009 Matthew Scarpino, Eclipse Engineering LLC + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + *******************************************************************************/ +package org.eclipse.photran.cdtinterface.ui; + +import org.eclipse.cdt.internal.core.model.TranslationUnit; +import org.eclipse.cdt.internal.ui.cview.CViewLabelProvider; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.photran.cdtinterface.CDTInterfacePlugin; +import org.eclipse.swt.graphics.Image; + +/** + * This class provides images to the FortranView. Specifically, it checks for the contentType + * of source files in the view and returns the Photran icon for files with Fortran-based content. + * + * @author Matt Scarpino + */ +public class FViewLabelProvider extends CViewLabelProvider +{ + public static final String FIXED_FORM_CONTENT_TYPE = "org.eclipse.photran.core.fixedFormFortranSource"; + public static final String FREE_FORM_CONTENT_TYPE = "org.eclipse.photran.core.freeFormFortranSource"; + + Image fortranFileImage; + + public FViewLabelProvider(int textFlags, int imageFlags) + { + super(textFlags, imageFlags); + } + + // This is something of a hack. Originally I tried using AdapterFactory objects and WorkspaceAdapters, + // but they never seemed to work. This works, but it's not particularly elegant and the image only + // shows up in the Fortran navigator. + public Image getImage(Object element) + { + if (element instanceof TranslationUnit) + { + String fileName = ((TranslationUnit)element).getFile().getName(); + IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(fileName); + if(contentType.getId().equals(FIXED_FORM_CONTENT_TYPE) || contentType.getId().equals(FREE_FORM_CONTENT_TYPE)) + { + if(fortranFileImage == null) { + fortranFileImage = CDTInterfacePlugin.getImageDescriptor("icons/obj16/f_file_obj.gif").createImage(); + } + return fortranFileImage; + } + } + return super.getImage(element); + } + + public void dispose() { + if(fortranFileImage != null) + fortranFileImage.dispose(); + super.dispose(); + } +}