[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[stp-commits] r3243 - in org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor: META-INF src/org/eclipse/stp/sca/xmleditor src/org/eclipse/stp/sca/xmleditor/completion src/org/eclipse/stp/sca/xmleditor/completion/attributes src/org/eclipse/stp/sca/xmleditor/hyperlinks src/org/eclipse/stp/sca/xmleditor/outline src/org/eclipse/stp/sca/xmleditor/utils
|
- From: genie@xxxxxxxxxxx
- Date: Fri, 12 Jun 2009 07:06:42 -0400 (EDT)
- Delivered-to: stp-commits@eclipse.org
Author: vzurczak
Date: 2009-06-12 07:06:37 -0400 (Fri, 12 Jun 2009)
New Revision: 3243
Added:
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/hyperlinks/
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/hyperlinks/JavaFileHyperlinkDetector.java
Removed:
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/utils/ResourceExplorer.java
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/utils/filters/
Modified:
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/META-INF/MANIFEST.MF
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/Messages.java
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/StructuredTextViewerConfigurationComposite.java
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/completion/ProxyProcessor.java
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/completion/attributes/AtttributeValueProposalMaker.java
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/messages.properties
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/outline/NodeActions.java
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/outline/ScaXmlMouseMoveListener.java
org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/utils/IncludesUtils.java
Log:
Integrated the source code from the "PostGalileo" branch into the trunk.
Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/META-INF/MANIFEST.MF
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/META-INF/MANIFEST.MF 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/META-INF/MANIFEST.MF 2009-06-12 11:06:37 UTC (rev 3243)
@@ -16,7 +16,8 @@
org.eclipse.jdt.core,
org.jdom;bundle-version="1.0.0",
org.junit4,
- org.eclipse.stp.sca.common.jdt
+ org.eclipse.stp.sca.common.jdt,
+ org.eclipse.jdt.ui
Bundle-Activator: org.eclipse.stp.sca.xmleditor.ScaXmlEditorPlugin
Bundle-ClassPath: .
Bundle-ActivationPolicy: lazy
@@ -24,5 +25,4 @@
Bundle-Vendor: %providerName
Export-Package: org.eclipse.stp.sca.xmleditor;x-friends:="org.eclipse.stp.sca.formeditor",
org.eclipse.stp.sca.xmleditor.outline;x-friends:="org.eclipse.stp.sca.formeditor",
- org.eclipse.stp.sca.xmleditor.utils;x-friends:="org.eclipse.stp.sca.formeditor",
- org.eclipse.stp.sca.xmleditor.utils.filters;x-friends:="org.eclipse.stp.sca.formeditor"
+ org.eclipse.stp.sca.xmleditor.utils;x-friends:="org.eclipse.stp.sca.formeditor"
Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/Messages.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/Messages.java 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/Messages.java 2009-06-12 11:06:37 UTC (rev 3243)
@@ -23,6 +23,9 @@
// package "org.eclipse.stp.sca.xmleditor"
public static String ScaCompositeXmlEditorPlugin_1;
+ public static String ImageRegistry_0;
+ public static String ImageRegistry_2;
+
// package "org.eclipse.stp.sca.xmleditor.outline"
public static String NodeActions_1;
@@ -99,11 +102,10 @@
public static String AttributeEditionDialog_5;
- public static String ImageRegistry_0;
+ // package "org.eclipse.stp.sca.xmleditor.hyperlinks"
+ public static String JavaFileHyperlinkDetector_0;
+ public static String JavaFileHyperlinkDetector_1;
-
- public static String ImageRegistry_2;
-
// package "org.eclipse.stp.sca.xmleditor.completion.preferences"
public static String ScaPreferenceProcessor_1;
Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/StructuredTextViewerConfigurationComposite.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/StructuredTextViewerConfigurationComposite.java 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/StructuredTextViewerConfigurationComposite.java 2009-06-12 11:06:37 UTC (rev 3243)
@@ -12,9 +12,11 @@
package org.eclipse.stp.sca.xmleditor;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.stp.sca.xmleditor.completion.ProxyProcessor;
+import org.eclipse.stp.sca.xmleditor.hyperlinks.JavaFileHyperlinkDetector;
import org.eclipse.stp.sca.xmleditor.statusline.StatusLineLabelProvider;
import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML;
@@ -44,7 +46,8 @@
* being already provided by the WST XML editor) and an extension of the basic auto-completion to
* include platform specific elements.
*
- * @see org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer)
+ * @see org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration
+ * #getContentAssistant(org.eclipse.jface.text.source.ISourceViewer)
*/
@Override
protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) {
@@ -65,4 +68,22 @@
statusLineLabelProvider = new StatusLineLabelProvider();
return statusLineLabelProvider;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.editors.text.TextSourceViewerConfiguration
+ * #getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer)
+ */
+ @Override
+ public IHyperlinkDetector[] getHyperlinkDetectors( ISourceViewer sourceViewer ) {
+
+ IHyperlinkDetector[] hyperlinks = super.getHyperlinkDetectors( sourceViewer );
+ int size = hyperlinks == null ? 1 : hyperlinks.length + 1;
+ IHyperlinkDetector[] newHyperlinks = new IHyperlinkDetector[ size ];
+
+ if( hyperlinks != null )
+ System.arraycopy( hyperlinks, 0, newHyperlinks, 0, size-1 );
+
+ newHyperlinks[ size - 1 ] = new JavaFileHyperlinkDetector();
+ return newHyperlinks;
+ }
}
Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/completion/ProxyProcessor.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/completion/ProxyProcessor.java 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/completion/ProxyProcessor.java 2009-06-12 11:06:37 UTC (rev 3243)
@@ -132,9 +132,6 @@
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal> ();
XmlContextualDom xmlContextualDom = new XmlContextualDom( offset, viewer );
-// System.out.println( xmlContextualDom.toString());
-// System.out.println( xmlContextualDom.printDocument());
-
// Get DOM model and send it to the content assistants (access rules issues require minimal use).
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead( viewer.getDocument());
IDOMModel domModel = (IDOMModel) model;
Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/completion/attributes/AtttributeValueProposalMaker.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/completion/attributes/AtttributeValueProposalMaker.java 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/completion/attributes/AtttributeValueProposalMaker.java 2009-06-12 11:06:37 UTC (rev 3243)
@@ -24,7 +24,7 @@
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.stp.sca.xmleditor.completion.XmlContextualDom;
import org.eclipse.stp.sca.xmleditor.utils.IncludesUtils;
-import org.eclipse.stp.sca.xmleditor.utils.ResourceExplorer;
+import org.eclipse.stp.sca.common.jdt.utils.ResourceExplorer;
import org.eclipse.stp.sca.xmleditor.utils.ScaUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
Added: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/hyperlinks/JavaFileHyperlinkDetector.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/hyperlinks/JavaFileHyperlinkDetector.java (rev 0)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/hyperlinks/JavaFileHyperlinkDetector.java 2009-06-12 11:06:37 UTC (rev 3243)
@@ -0,0 +1,192 @@
+/******************************************************************************
+ * Copyright (c) 2009, EBM WebSourcing
+ * 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:
+ * EBM WebSourcing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.stp.sca.xmleditor.hyperlinks;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.stp.sca.common.jdt.utils.DomUtils;
+import org.eclipse.stp.sca.common.jdt.utils.ResourceExplorer;
+import org.eclipse.stp.sca.xmleditor.Messages;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Hyper links to open Java files referenced in composites and component types.
+ * @author Vincent Zurczak - EBM WebSourcing
+ */
+public class JavaFileHyperlinkDetector implements IHyperlinkDetector {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector
+ * #detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
+ */
+ public IHyperlink[] detectHyperlinks(
+ ITextViewer textViewer, final IRegion region, boolean canShowMultipleHyperlinks ) {
+
+ // Get the element associated with the current offset
+ IDocument document = textViewer.getDocument();
+ Node node = getNodeByOffset( document, region.getOffset());
+ if( node != null ) {
+
+ Element elt = null;
+ if( node.getNodeType() == Node.ELEMENT_NODE )
+ elt = (Element) node;
+ else if( node.getNodeType() == Node.ATTRIBUTE_NODE )
+ elt = ((Attr) node).getOwnerElement();
+
+ if( elt == null )
+ return null;
+
+ // Check if this element is a Java interface or implementation...
+ // ... and get the class name
+ String name = DomUtils.getNodeName( elt ).toLowerCase();
+ String className = null;
+ if( name.equals( "interface.java" )) //$NON-NLS-1$
+ className = elt.getAttribute( "interface" ); //$NON-NLS-1$
+ if( name.equals( "implementation.java" )) //$NON-NLS-1$
+ className = elt.getAttribute( "class" ); //$NON-NLS-1$
+
+ if( className == null )
+ return null;
+
+ // Check that the class name is contained in the hovered line...
+ // ... and compute the associated region to highlight the link
+ IRegion nodeRegion = region;
+ try {
+ IRegion lineRegion = document.getLineInformationOfOffset( region.getOffset());
+ String lineText = document.get( lineRegion.getOffset(), lineRegion.getLength());
+
+ if( lineText.contains( className )) {
+ int length = className.length();
+ int start = lineRegion.getOffset() + lineText.indexOf( className );
+ nodeRegion = new Region( start, length );
+ }
+ else
+ return null;
+
+ } catch( BadLocationException e ) {
+ e.printStackTrace();
+ }
+
+ // Check that the class name exists in the current project...
+ // ... and that the project is a Java project
+ IFile file = ResourceExplorer.getIFileFromEditor();
+ if( file == null )
+ return null;
+
+ IProject project = file.getProject();
+ try {
+ if( ! project.hasNature( JavaCore.NATURE_ID ))
+ return null;
+ } catch( CoreException e1 ) {
+ e1.printStackTrace();
+ return null;
+ }
+
+ IJavaProject jp = JavaCore.create( project );
+ try {
+ final IType type = jp.findType( className );
+
+ // If the type exists, create a hyper link
+ final String cl = className;
+ final IRegion nr = nodeRegion;
+ IHyperlink pomHyperlink = new IHyperlink() {
+
+ public IRegion getHyperlinkRegion() {
+ return nr;
+ }
+
+ public String getHyperlinkText() {
+ return cl;
+ }
+
+ public String getTypeLabel() {
+ return "Java SCA"; //$NON-NLS-1$
+ }
+
+ public void open() {
+ try {
+ if( type != null )
+ JavaUI.openInEditor( type, true, true );
+ else {
+ Display.getDefault().asyncExec( new Runnable() {
+ public void run() {
+ MessageDialog.openWarning(
+ new Shell(),
+ Messages.JavaFileHyperlinkDetector_0,
+ Messages.JavaFileHyperlinkDetector_1 );
+ }
+ });
+ }
+
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ };
+
+ return new IHyperlink[] { pomHyperlink };
+
+ } catch( JavaModelException e1 ) {
+ e1.printStackTrace();
+ }
+ }
+
+ return null;
+ }
+
+
+ /**
+ * Returns the XML node corresponding to the offset in the given document.
+ *
+ * @param offset the offset
+ * @return a node or null if no node could be found
+ */
+ @SuppressWarnings("restriction")
+ private Node getNodeByOffset(IDocument document, int offset) {
+
+ try {
+ IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead( document );
+ IndexedRegion indexedRegion = model.getIndexedRegion( offset );
+ if( indexedRegion == null )
+ indexedRegion = model.getIndexedRegion( offset - 1 );
+
+ if( indexedRegion instanceof Node )
+ return (Node) indexedRegion;
+
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+}
Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/messages.properties
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/messages.properties 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/messages.properties 2009-06-12 11:06:37 UTC (rev 3243)
@@ -95,6 +95,11 @@
AttributeEditionDialog_5=Use:
+# package "org.eclipse.stp.sca.xmleditor.hyperlinks"
+JavaFileHyperlinkDetector_0=Class not found
+JavaFileHyperlinkDetector_1=The class could not be found in the project class path.
+
+
# package "org.eclipse.stp.sca.xmleditor.completion"
XmlContextualDom_0=Invalid XML
Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/outline/NodeActions.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/outline/NodeActions.java 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/outline/NodeActions.java 2009-06-12 11:06:37 UTC (rev 3243)
@@ -22,7 +22,7 @@
import org.eclipse.stp.sca.xmleditor.Messages;
import org.eclipse.stp.sca.xmleditor.ScaXmlEditorPlugin;
import org.eclipse.stp.sca.xmleditor.utils.IncludesUtils;
-import org.eclipse.stp.sca.xmleditor.utils.ResourceExplorer;
+import org.eclipse.stp.sca.common.jdt.utils.ResourceExplorer;
import org.eclipse.stp.sca.xmleditor.utils.ScaUtils;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.ISharedImages;
Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/outline/ScaXmlMouseMoveListener.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/outline/ScaXmlMouseMoveListener.java 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/outline/ScaXmlMouseMoveListener.java 2009-06-12 11:06:37 UTC (rev 3243)
@@ -1,5 +1,5 @@
/******************************************************************************
- * Copyright (c) 2008-2009, EBM WebSourcing
+ * Copyright (c) 2009, EBM WebSourcing
* 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
Modified: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/utils/IncludesUtils.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/utils/IncludesUtils.java 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/utils/IncludesUtils.java 2009-06-12 11:06:37 UTC (rev 3243)
@@ -22,8 +22,8 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.stp.sca.xmleditor.utils.ResourceExplorer;
-import org.eclipse.stp.sca.xmleditor.utils.filters.SkippedResources;
+import org.eclipse.stp.sca.common.jdt.utils.ResourceExplorer;
+import org.eclipse.stp.sca.common.jdt.utils.filters.SkippedResources;
import org.jdom.input.SAXBuilder;
import org.jdom.output.DOMOutputter;
import org.w3c.dom.Document;
Deleted: org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/utils/ResourceExplorer.java
===================================================================
--- org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/utils/ResourceExplorer.java 2009-06-09 11:35:55 UTC (rev 3242)
+++ org.eclipse.stp.sca/trunk/org.eclipse.stp.sca.xmleditor/src/org/eclipse/stp/sca/xmleditor/utils/ResourceExplorer.java 2009-06-12 11:06:37 UTC (rev 3243)
@@ -1,130 +0,0 @@
-/******************************************************************************
- * Copyright (c) 2007-2009, EBM WebSourcing
- * 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:
- * EBM WebSourcing - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.stp.sca.xmleditor.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.FileEditorInput;
-
-/**
- * Useful methods to manage and look for resources in the workspace.
- * @author Vincent Zurczak - EBM WebSourcing
- */
-public class ResourceExplorer {
-
- /**
- * Convenience method equivalent to <i>getFiles( project, "*" )</i>.
- * @param project the IProject that interest you.
- * @return all the IFile contained into this project (with no limit in the level).
- */
- public static List<IFile> getFiles( IProject project ) {
- return getFiles( project, "*" ); //$NON-NLS-1$
- }
-
- /**
- * Get all the files whose extension is <b>extension</b> and present in <b>project</b>.
- * @param project the IProject that interest you.
- * @param extension the file extension. Use "*" for any extension.
- * @return all the IFile contained into this project (with no limit in the level).
- */
- public static List<IFile> getFiles( IProject project, String extension ) {
- List<IFile> result = new ArrayList<IFile> ();
- try {
- IResource[] resources = project.members();
- for( IResource resource : resources ) {
- switch( resource.getType()) {
- case IResource.FILE:
- String fileExtension = resource.getFileExtension().toLowerCase();
- if( fileExtension.equals( extension )
- || fileExtension.equals( "*" )) //$NON-NLS-1$
- result.add( (IFile) resource );
- break;
- case IResource.FOLDER:
- IFolder subFolder = (IFolder) resource;
- result.addAll( getFiles( subFolder, extension ));
- break;
- default: break;
- }
- }
- } catch (CoreException e) {
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * Convenience method equivalent to <i>getFiles( folder, "*" )</i>.
- * @param folder the IFolder that interest you.
- * @return all the IFile contained into this folder (with no limit in the level).
- */
- public static List<IFile> getFiles( IFolder folder ) {
- return getFiles( folder, "*" ); //$NON-NLS-1$
- }
-
- /**
- * Get all the files whose extension is <b>extension</b> and present in <b>folder</b>.
- * @param folder the IFolder that interest you.
- * @param extension the file extension. Use "*" for any extension.
- * @return all the IFile contained into this folder (with no limit in the level).
- */
- public static List<IFile> getFiles( IFolder folder, String extension ) {
- List<IFile> result = new ArrayList<IFile> ();
- try {
- IResource[] resources = folder.members();
- for( IResource resource : resources ) {
- switch( resource.getType()) {
- case IResource.FILE:
- String fileExtension = resource.getFileExtension().toLowerCase();
- if( fileExtension.equals( extension )
- || fileExtension.equals( "*" )) //$NON-NLS-1$
- result.add( (IFile) resource );
- break;
- case IResource.FOLDER:
- IFolder subFolder = (IFolder) resource;
- result.addAll( getFiles( subFolder, extension ));
- break;
- default: break;
- }
- }
- } catch (CoreException e) {
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * Get the file edited in the active editor.
- * @return the file edited in the active editor or null if it could not be retrieved.
- */
- public static IFile getIFileFromEditor() {
- try {
- IEditorPart editorPart =
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- IFile editedFile = ((FileEditorInput) editorPart.getEditorInput()).getFile();
-
- return editedFile;
- }
- catch( Exception e ) {
- // TODO: log error
- // ScaXmlEditorPlugin.log( null, e );
- }
- return null;
- }
-}