KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > build > BuildEditor


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 package org.eclipse.pde.internal.ui.editor.build;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.pde.core.build.IBuildModel;
15 import org.eclipse.pde.internal.core.build.IBuildObject;
16 import org.eclipse.pde.internal.ui.IPDEUIConstants;
17 import org.eclipse.pde.internal.ui.PDEPlugin;
18 import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage;
19 import org.eclipse.pde.internal.ui.editor.MultiSourceEditor;
20 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
21 import org.eclipse.pde.internal.ui.editor.PDEFormPage;
22 import org.eclipse.pde.internal.ui.editor.PDESourcePage;
23 import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput;
24 import org.eclipse.pde.internal.ui.editor.context.InputContext;
25 import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
26 import org.eclipse.swt.SWTError;
27 import org.eclipse.swt.dnd.RTFTransfer;
28 import org.eclipse.swt.dnd.TextTransfer;
29 import org.eclipse.swt.dnd.Transfer;
30 import org.eclipse.swt.dnd.TransferData;
31 import org.eclipse.ui.IEditorInput;
32 import org.eclipse.ui.IFileEditorInput;
33 import org.eclipse.ui.IStorageEditorInput;
34 import org.eclipse.ui.PartInitException;
35 import org.eclipse.ui.part.FileEditorInput;
36 import org.eclipse.ui.views.properties.IPropertySheetPage;
37
38 public class BuildEditor extends MultiSourceEditor {
39     
40     public BuildEditor() {
41     }
42     
43     /* (non-Javadoc)
44      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getEditorID()
45      */

46     protected String JavaDoc getEditorID() {
47         return IPDEUIConstants.BUILD_EDITOR_ID;
48     }
49     
50     protected void createResourceContexts(InputContextManager manager,
51             IFileEditorInput input) {
52         IFile file = input.getFile();
53
54         manager.putContext(input, new BuildInputContext(this, input, true));
55         manager.monitorFile(file);
56     }
57     
58     protected InputContextManager createInputContextManager() {
59         BuildInputContextManager manager = new BuildInputContextManager(this);
60         manager.setUndoManager(new BuildUndoManager(this));
61         return manager;
62     }
63     
64     public void monitoredFileAdded(IFile file) {
65         String JavaDoc name = file.getName();
66         if (name.equalsIgnoreCase("build.properties")) { //$NON-NLS-1$
67
if (!fInputContextManager.hasContext(BuildInputContext.CONTEXT_ID)) {
68                 IEditorInput in = new FileEditorInput(file);
69                 fInputContextManager.putContext(in, new BuildInputContext(this, in, false));
70             }
71         }
72     }
73
74     public boolean monitoredFileRemoved(IFile file) {
75         //TODO may need to check with the user if there
76
//are unsaved changes in the model for the
77
//file that just got removed under us.
78
return true;
79     }
80     public void editorContextAdded(InputContext context) {
81         addSourcePage(context.getId());
82     }
83     public void contextRemoved(InputContext context) {
84         close(false);
85     }
86
87     protected void createSystemFileContexts(InputContextManager manager,
88             SystemFileEditorInput input) {
89         manager.putContext(input, new BuildInputContext(this, input, true));
90     }
91
92     protected void createStorageContexts(InputContextManager manager,
93             IStorageEditorInput input) {
94         manager.putContext(input, new BuildInputContext(this, input, true));
95     }
96
97     protected void addEditorPages() {
98         try {
99             if (getEditorInput() instanceof IFileEditorInput)
100                 addPage(new BuildPage(this));
101         } catch (PartInitException e) {
102             PDEPlugin.logException(e);
103         }
104         addSourcePage(BuildInputContext.CONTEXT_ID);
105     }
106
107     /* (non-Javadoc)
108      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#computeInitialPageId()
109      */

110     protected String JavaDoc computeInitialPageId() {
111         // Retrieve the initial page
112
String JavaDoc firstPageId = super.computeInitialPageId();
113         // If none is defined, return the default
114
if (firstPageId == null) {
115             return BuildPage.PAGE_ID;
116         }
117         
118         return firstPageId;
119     }
120     
121     /* (non-Javadoc)
122      * @see org.eclipse.pde.internal.ui.neweditor.MultiSourceEditor#createXMLSourcePage(org.eclipse.pde.internal.ui.neweditor.PDEFormEditor, java.lang.String, java.lang.String)
123      */

124     protected PDESourcePage createSourcePage(PDEFormEditor editor, String JavaDoc title, String JavaDoc name, String JavaDoc contextId) {
125         return new BuildSourcePage(editor, title, name);
126     }
127     
128     protected ISortableContentOutlinePage createContentOutline() {
129         return new BuildOutlinePage(this);
130     }
131     
132     protected IPropertySheetPage getPropertySheet(PDEFormPage page) {
133         return null;
134     }
135
136     public String JavaDoc getTitle() {
137         return super.getTitle();
138     }
139
140     protected boolean isModelCorrect(Object JavaDoc model) {
141         return model != null ? ((IBuildModel) model).isValid() : false;
142     }
143     protected boolean hasKnownTypes() {
144         try {
145             TransferData[] types = getClipboard().getAvailableTypes();
146             Transfer[] transfers =
147                 new Transfer[] { TextTransfer.getInstance(), RTFTransfer.getInstance()};
148             for (int i = 0; i < types.length; i++) {
149                 for (int j = 0; j < transfers.length; j++) {
150                     if (transfers[j].isSupportedType(types[i]))
151                         return true;
152                 }
153             }
154         } catch (SWTError e) {
155         }
156         return false;
157     }
158
159     public Object JavaDoc getAdapter(Class JavaDoc key) {
160         //No property sheet needed - block super
161
if (key.equals(IPropertySheetPage.class)) {
162             return null;
163         }
164         return super.getAdapter(key);
165     }
166     
167     /* (non-Javadoc)
168      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getInputContext(java.lang.Object)
169      */

170     protected InputContext getInputContext(Object JavaDoc object) {
171         InputContext context = null;
172         if (object instanceof IBuildObject) {
173             context = fInputContextManager.findContext(BuildInputContext.CONTEXT_ID);
174         }
175         return context;
176     }
177
178 }
179
Popular Tags