KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > FeatureEditorMatchingStrategy


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.feature;
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.PartInitException;
20 import org.eclipse.ui.ide.ResourceUtil;
21
22
23 public class FeatureEditorMatchingStrategy implements IEditorMatchingStrategy {
24
25     private static final String JavaDoc BP = "build.properties"; //$NON-NLS-1$
26
private static final String JavaDoc FX = "feature.xml"; //$NON-NLS-1$
27

28     public boolean matches(IEditorReference editorRef, IEditorInput input) {
29         if (!(input instanceof IFileEditorInput))
30             return false;
31         IFile inputFile = ResourceUtil.getFile(input);
32         if (inputFile == null)
33             return false;
34         try {
35             IFile currInputFile = ResourceUtil.getFile(editorRef.getEditorInput());
36             if (currInputFile == null)
37                 return false;
38             if (!inputFile.getProject().equals(currInputFile.getProject()))
39                 return false;
40             // build.properties matches with editors that have a feature.xml file
41
// as their input and that feature.xml is at the root
42
if (inputFile.getName().equals(FX)) {
43                 if (currInputFile.getName().equals(BP))
44                     return inputFile.getProjectRelativePath().toString().equals(FX);
45                 return inputFile.equals(currInputFile);
46             } else if (inputFile.getName().equals(BP)) {
47                 if (currInputFile.getName().equals(FX))
48                     return currInputFile.getProjectRelativePath().toString().equals(FX);
49                 return inputFile.equals(currInputFile);
50             }
51             return false;
52         } catch (PartInitException e) {
53             return false;
54         }
55     }
56
57 }
58
59
Popular Tags