woproject/projects/wolips/plugins/org.objectstyle.wolips.componenteditor/java/org/objectstyle/wolips/componenteditor/editor ComponentEditorMatchingStrategy.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.web.webobjects.woproject.cvs
Message-ID <[email protected]>
Update of /cvsroot/woproject/woproject/projects/wolips/plugins/org.objectstyle.wolips.componenteditor/java/org/objectstyle/wolips/componenteditor/editor
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18038/java/org/objectstyle/wolips/componenteditor/editor

Added Files:
	ComponentEditorMatchingStrategy.java 
Log Message:
ComponentEditorMatchingStrategy

--- NEW FILE: ComponentEditorMatchingStrategy.java ---
package org.objectstyle.wolips.componenteditor.editor;

import org.eclipse.core.resources.IFile;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorMatchingStrategy;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.ResourceUtil;
import org.eclipse.ui.part.FileEditorInput;
import org.objectstyle.wolips.componenteditor.ComponenteditorPlugin;
import org.objectstyle.wolips.components.input.ComponentEditorInput;

public class ComponentEditorMatchingStrategy implements IEditorMatchingStrategy {

	public boolean matches(IEditorReference editorReference,
			IEditorInput editorInput) {
		String editorID = editorReference.getId();
		if(editorID == null) {
			return false;
		}
		if(!editorID.equals(ComponenteditorPlugin.ComponentEditorID)) {
			return false;
		}
		if (!(editorInput instanceof FileEditorInput)) {
			return false;
		}
		IFile inputFile = ResourceUtil.getFile(editorInput);
		if (inputFile == null) {
			return false;
		}
		String extension = inputFile.getFileExtension();
		if (extension == null) {
			return false;
		}
		if (!("java".equalsIgnoreCase(extension)
				|| "wod".equalsIgnoreCase(extension)
				|| "html".equalsIgnoreCase(extension)
				|| "woo".equalsIgnoreCase(extension)
				|| "api".equalsIgnoreCase(extension) || "tiff"
				.equalsIgnoreCase(extension))) {
			return false;
		}
		IEditorInput editorReferenceEditorInput = null;
		try {
			//expensive call it as late as possible
			editorReferenceEditorInput = editorReference.getEditorInput();
		} catch (PartInitException e) {
			ComponenteditorPlugin.getDefault().log(e);
		}
		if(editorReferenceEditorInput == null) {
			return false;
		}
		if(!(editorReferenceEditorInput instanceof ComponentEditorInput)) {
			return false;
		}
		ComponentEditorInput componentEditorInput = (ComponentEditorInput)editorReferenceEditorInput;
		IEditorInput[] editorInputArray = componentEditorInput.getInput();
		for (int i = 0; i < editorInputArray.length; i++) {
			IFile inputFileFromEditor = ResourceUtil.getFile(editorInputArray[i]);
			if(inputFileFromEditor == null) {
				continue;
			}
			if(inputFileFromEditor.equals(inputFile)) {
				return true;
			}
			
		}
		return false;
	}

}



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.