001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.build;
011:
012: import org.eclipse.core.resources.IFile;
013: import org.eclipse.jface.action.IToolBarManager;
014: import org.eclipse.pde.core.build.IBuildModel;
015: import org.eclipse.pde.internal.core.build.IBuildObject;
016: import org.eclipse.pde.internal.ui.IPDEUIConstants;
017: import org.eclipse.pde.internal.ui.PDEPlugin;
018: import org.eclipse.pde.internal.ui.PDEPluginImages;
019: import org.eclipse.pde.internal.ui.PDEUIMessages;
020: import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage;
021: import org.eclipse.pde.internal.ui.editor.MultiSourceEditor;
022: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
023: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
024: import org.eclipse.pde.internal.ui.editor.PDESourcePage;
025: import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput;
026: import org.eclipse.pde.internal.ui.editor.context.InputContext;
027: import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
028: import org.eclipse.pde.internal.ui.editor.plugin.PluginExportAction;
029: import org.eclipse.swt.SWTError;
030: import org.eclipse.swt.dnd.RTFTransfer;
031: import org.eclipse.swt.dnd.TextTransfer;
032: import org.eclipse.swt.dnd.Transfer;
033: import org.eclipse.swt.dnd.TransferData;
034: import org.eclipse.ui.IEditorInput;
035: import org.eclipse.ui.IFileEditorInput;
036: import org.eclipse.ui.IStorageEditorInput;
037: import org.eclipse.ui.PartInitException;
038: import org.eclipse.ui.part.FileEditorInput;
039: import org.eclipse.ui.views.properties.IPropertySheetPage;
040:
041: public class BuildEditor extends MultiSourceEditor {
042:
043: private PluginExportAction fExportAction;
044:
045: public BuildEditor() {
046: }
047:
048: /* (non-Javadoc)
049: * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getEditorID()
050: */
051: protected String getEditorID() {
052: return IPDEUIConstants.BUILD_EDITOR_ID;
053: }
054:
055: protected void createResourceContexts(InputContextManager manager,
056: IFileEditorInput input) {
057: IFile file = input.getFile();
058:
059: manager.putContext(input, new BuildInputContext(this , input,
060: true));
061: manager.monitorFile(file);
062: }
063:
064: protected InputContextManager createInputContextManager() {
065: BuildInputContextManager manager = new BuildInputContextManager(
066: this );
067: manager.setUndoManager(new BuildUndoManager(this ));
068: return manager;
069: }
070:
071: public void monitoredFileAdded(IFile file) {
072: String name = file.getName();
073: if (name.equalsIgnoreCase("build.properties")) { //$NON-NLS-1$
074: if (!fInputContextManager
075: .hasContext(BuildInputContext.CONTEXT_ID)) {
076: IEditorInput in = new FileEditorInput(file);
077: fInputContextManager.putContext(in,
078: new BuildInputContext(this , in, false));
079: }
080: }
081: }
082:
083: public boolean monitoredFileRemoved(IFile file) {
084: //TODO may need to check with the user if there
085: //are unsaved changes in the model for the
086: //file that just got removed under us.
087: return true;
088: }
089:
090: public void editorContextAdded(InputContext context) {
091: addSourcePage(context.getId());
092: }
093:
094: public void contextRemoved(InputContext context) {
095: close(false);
096: }
097:
098: protected void createSystemFileContexts(
099: InputContextManager manager, SystemFileEditorInput input) {
100: manager.putContext(input, new BuildInputContext(this , input,
101: true));
102: }
103:
104: protected void createStorageContexts(InputContextManager manager,
105: IStorageEditorInput input) {
106: manager.putContext(input, new BuildInputContext(this , input,
107: true));
108: }
109:
110: protected void addEditorPages() {
111: try {
112: if (getEditorInput() instanceof IFileEditorInput)
113: addPage(new BuildPage(this ));
114: } catch (PartInitException e) {
115: PDEPlugin.logException(e);
116: }
117: addSourcePage(BuildInputContext.CONTEXT_ID);
118: }
119:
120: /* (non-Javadoc)
121: * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#computeInitialPageId()
122: */
123: protected String computeInitialPageId() {
124: // Retrieve the initial page
125: String firstPageId = super .computeInitialPageId();
126: // If none is defined, return the default
127: if (firstPageId == null) {
128: return BuildPage.PAGE_ID;
129: }
130:
131: return firstPageId;
132: }
133:
134: /* (non-Javadoc)
135: * @see org.eclipse.pde.internal.ui.neweditor.MultiSourceEditor#createXMLSourcePage(org.eclipse.pde.internal.ui.neweditor.PDEFormEditor, java.lang.String, java.lang.String)
136: */
137: protected PDESourcePage createSourcePage(PDEFormEditor editor,
138: String title, String name, String contextId) {
139: return new BuildSourcePage(editor, title, name);
140: }
141:
142: protected ISortableContentOutlinePage createContentOutline() {
143: return new BuildOutlinePage(this );
144: }
145:
146: protected IPropertySheetPage getPropertySheet(PDEFormPage page) {
147: return null;
148: }
149:
150: public String getTitle() {
151: return super .getTitle();
152: }
153:
154: protected boolean isModelCorrect(Object model) {
155: return model != null ? ((IBuildModel) model).isValid() : false;
156: }
157:
158: protected boolean hasKnownTypes() {
159: try {
160: TransferData[] types = getClipboard().getAvailableTypes();
161: Transfer[] transfers = new Transfer[] {
162: TextTransfer.getInstance(),
163: RTFTransfer.getInstance() };
164: for (int i = 0; i < types.length; i++) {
165: for (int j = 0; j < transfers.length; j++) {
166: if (transfers[j].isSupportedType(types[i]))
167: return true;
168: }
169: }
170: } catch (SWTError e) {
171: }
172: return false;
173: }
174:
175: public Object getAdapter(Class key) {
176: //No property sheet needed - block super
177: if (key.equals(IPropertySheetPage.class)) {
178: return null;
179: }
180: return super .getAdapter(key);
181: }
182:
183: /* (non-Javadoc)
184: * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getInputContext(java.lang.Object)
185: */
186: protected InputContext getInputContext(Object object) {
187: InputContext context = null;
188: if (object instanceof IBuildObject) {
189: context = fInputContextManager
190: .findContext(BuildInputContext.CONTEXT_ID);
191: }
192: return context;
193: }
194:
195: public void contributeToToolbar(IToolBarManager manager) {
196: manager.add(getExportAction());
197: }
198:
199: private PluginExportAction getExportAction() {
200: if (fExportAction == null) {
201: fExportAction = new PluginExportAction(this);
202: fExportAction
203: .setToolTipText(PDEUIMessages.PluginEditor_exportTooltip);
204: fExportAction
205: .setImageDescriptor(PDEPluginImages.DESC_EXPORT_PLUGIN_TOOL);
206: }
207: return fExportAction;
208: }
209: }
|