KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > plugin > ManifestEditorMatchingStrategy


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.editor.plugin;
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.ui.IEditorInput;
16 import org.eclipse.ui.IEditorMatchingStrategy;
17 import org.eclipse.ui.IEditorReference;
18 import org.eclipse.ui.IFileEditorInput;
19 import org.eclipse.ui.IStorageEditorInput;
20 import org.eclipse.ui.PartInitException;
21 import org.eclipse.ui.ide.ResourceUtil;
22
23
24 public class ManifestEditorMatchingStrategy implements IEditorMatchingStrategy {
25
26     public boolean matches(IEditorReference editorRef, IEditorInput input) {
27         IFile inputFile = ResourceUtil.getFile(input);
28         if (input instanceof IFileEditorInput) {
29             try {
30                 if (input.equals(editorRef.getEditorInput()))
31                     return true;
32                 String JavaDoc path = inputFile.getProjectRelativePath().toString();
33                 if (path.equals("build.properties")) { //$NON-NLS-1$
34
IFile editorFile = ResourceUtil.getFile(editorRef.getEditorInput());
35                     return editorFile != null && inputFile.getProject().equals(editorFile.getProject());
36                 }
37             } catch (PartInitException e) {
38                 return false;
39             }
40         } else if (input instanceof IStorageEditorInput) {
41             try {
42                 IEditorInput existing = editorRef.getEditorInput();
43                 return input.equals(existing);
44             } catch (PartInitException e1) {
45             }
46         }
47         return false;
48     }
49
50
51 }
52
53
Popular Tags