KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > site > SiteEditor


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 /*
12  * Created on Jan 27, 2004
13  */

14 package org.eclipse.pde.internal.ui.editor.site;
15 import java.io.File JavaDoc;
16 import java.util.Locale JavaDoc;
17
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.jface.action.IMenuManager;
20 import org.eclipse.pde.internal.core.isite.ISiteObject;
21 import org.eclipse.pde.internal.ui.IPDEUIConstants;
22 import org.eclipse.pde.internal.ui.PDEPlugin;
23 import org.eclipse.pde.internal.ui.editor.ISortableContentOutlinePage;
24 import org.eclipse.pde.internal.ui.editor.MultiSourceEditor;
25 import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
26 import org.eclipse.pde.internal.ui.editor.PDESourcePage;
27 import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput;
28 import org.eclipse.pde.internal.ui.editor.context.InputContext;
29 import org.eclipse.pde.internal.ui.editor.context.InputContextManager;
30 import org.eclipse.ui.IEditorInput;
31 import org.eclipse.ui.IFileEditorInput;
32 import org.eclipse.ui.IStorageEditorInput;
33 import org.eclipse.ui.PartInitException;
34 import org.eclipse.ui.part.FileEditorInput;
35
36 public class SiteEditor extends MultiSourceEditor {
37     
38     /* (non-Javadoc)
39      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getEditorID()
40      */

41     protected String JavaDoc getEditorID() {
42         return IPDEUIConstants.SITE_EDITOR_ID;
43     }
44     
45     protected void createResourceContexts(InputContextManager manager,
46             IFileEditorInput input) {
47         IFile file = input.getFile();
48         IFile siteFile = null;
49         String JavaDoc name = file.getName().toLowerCase(Locale.ENGLISH);
50         if (name.equals("site.xml")) { //$NON-NLS-1$
51
siteFile = file;
52             if (siteFile.exists()) {
53                 IEditorInput in = new FileEditorInput(siteFile);
54                 manager.putContext(in, new SiteInputContext(this, in, file==siteFile));
55             }
56             manager.monitorFile(siteFile);
57         }
58     }
59     
60     protected InputContextManager createInputContextManager() {
61         SiteInputContextManager contextManager = new SiteInputContextManager(this);
62         contextManager.setUndoManager(new SiteUndoManager(this));
63         return contextManager;
64     }
65     
66     
67     public void monitoredFileAdded(IFile file) {
68     }
69
70     public boolean monitoredFileRemoved(IFile file) {
71         //TODO may need to check with the user if there
72
//are unsaved changes in the model for the
73
//file that just got removed under us.
74
return true;
75     }
76     public void editorContextAdded(InputContext context) {
77         addSourcePage(context.getId());
78     }
79     public void contextRemoved(InputContext context) {
80         close(false);
81     }
82
83     protected void createSystemFileContexts(InputContextManager manager,
84             SystemFileEditorInput input) {
85         File JavaDoc file = (File JavaDoc) input.getAdapter(File JavaDoc.class);
86         File JavaDoc siteFile = null;
87
88         String JavaDoc name = file.getName().toLowerCase(Locale.ENGLISH);
89         if (name.equals("site.xml")) { //$NON-NLS-1$
90
siteFile = file;
91             if (siteFile.exists()) {
92                 IEditorInput in = new SystemFileEditorInput(siteFile);
93                 manager.putContext(in, new SiteInputContext(this, in,
94                         file == siteFile));
95             }
96         }
97     }
98
99     protected void createStorageContexts(InputContextManager manager,
100             IStorageEditorInput input) {
101         String JavaDoc name = input.getName().toLowerCase(Locale.ENGLISH);
102         if (name.startsWith("site.xml")) { //$NON-NLS-1$
103
manager.putContext(input, new SiteInputContext(this, input, true));
104         }
105     }
106     
107     protected void contextMenuAboutToShow(IMenuManager manager) {
108         super.contextMenuAboutToShow(manager);
109     }
110
111     protected void addEditorPages() {
112         try {
113             addPage(new FeaturesPage(this));
114             addPage(new ArchivePage(this));
115         } catch (PartInitException e) {
116             PDEPlugin.logException(e);
117         }
118         addSourcePage(SiteInputContext.CONTEXT_ID);
119     }
120
121
122     protected String JavaDoc computeInitialPageId() {
123         return FeaturesPage.PAGE_ID;
124     }
125     
126     /* (non-Javadoc)
127      * @see org.eclipse.pde.internal.ui.neweditor.MultiSourceEditor#createXMLSourcePage(org.eclipse.pde.internal.ui.neweditor.PDEFormEditor, java.lang.String, java.lang.String)
128      */

129     protected PDESourcePage createSourcePage(PDEFormEditor editor, String JavaDoc title, String JavaDoc name, String JavaDoc contextId) {
130         return new SiteSourcePage(editor, title, name);
131     }
132     
133     protected ISortableContentOutlinePage createContentOutline() {
134         return new SiteOutlinePage(this);
135     }
136         
137     /*
138      * (non-Javadoc)
139      * @see org.eclipse.pde.internal.ui.editor.PDEFormEditor#getInputContext(java.lang.Object)
140      */

141     protected InputContext getInputContext(Object JavaDoc object) {
142         InputContext context = null;
143         if (object instanceof ISiteObject) {
144             context = fInputContextManager
145                     .findContext(SiteInputContext.CONTEXT_ID);
146         }
147         return context;
148     }
149
150 }
Popular Tags