| /******************************************************************************* |
| * Copyright (c) 2000, 2003 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| /* |
| * Created on Jan 27, 2004 |
| */ |
| package org.eclipse.pde.internal.ui.editor.site; |
| import java.io.*; |
| import org.eclipse.core.resources.*; |
| import org.eclipse.jface.action.*; |
| import org.eclipse.jface.viewers.*; |
| import org.eclipse.pde.internal.ui.*; |
| import org.eclipse.pde.internal.ui.editor.*; |
| import org.eclipse.pde.internal.ui.editor.context.*; |
| import org.eclipse.swt.*; |
| import org.eclipse.swt.dnd.*; |
| import org.eclipse.ui.*; |
| import org.eclipse.ui.forms.editor.*; |
| import org.eclipse.ui.part.*; |
| import org.eclipse.ui.views.contentoutline.*; |
| |
| /** |
| * @author dejan |
| * |
| * To change the template for this generated type comment go to Window - |
| * Preferences - Java - Code Generation - Code and Comments |
| */ |
| public class SiteEditor extends MultiSourceEditor { |
| protected void createResourceContexts(InputContextManager manager, |
| IFileEditorInput input) { |
| IFile file = input.getFile(); |
| IFile siteFile = null; |
| String name = file.getName().toLowerCase(); |
| if (name.equals("site.xml")) { |
| siteFile = file; |
| } |
| if (siteFile.exists()) { |
| IEditorInput in = new FileEditorInput(siteFile); |
| manager.putContext(in, new SiteInputContext(this, in, file==siteFile)); |
| } |
| manager.monitorFile(siteFile); |
| } |
| |
| protected InputContextManager createInputContextManager() { |
| SiteInputContextManager contextManager = new SiteInputContextManager(this); |
| contextManager.setUndoManager(new SiteUndoManager(this)); |
| return contextManager; |
| } |
| |
| public boolean canCopy(ISelection selection) { |
| return true; |
| } |
| |
| protected boolean hasKnownTypes() { |
| try { |
| TransferData[] types = getClipboard().getAvailableTypes(); |
| Transfer[] transfers = |
| new Transfer[] { TextTransfer.getInstance(), RTFTransfer.getInstance()}; |
| for (int i = 0; i < types.length; i++) { |
| for (int j = 0; j < transfers.length; j++) { |
| if (transfers[j].isSupportedType(types[i])) |
| return true; |
| } |
| } |
| } catch (SWTError e) { |
| } |
| return false; |
| } |
| |
| public void monitoredFileAdded(IFile file) { |
| /* |
| String name = file.getName(); |
| if (name.equalsIgnoreCase("site.xml")) { |
| IEditorInput in = new FileEditorInput(file); |
| inputContextManager.putContext(in, new SiteInputContext(this, in, false)); |
| } |
| */ |
| } |
| |
| public boolean monitoredFileRemoved(IFile file) { |
| //TODO may need to check with the user if there |
| //are unsaved changes in the model for the |
| //file that just got removed under us. |
| return true; |
| } |
| public void contextAdded(InputContext context) { |
| addSourcePage(context.getId()); |
| } |
| public void contextRemoved(InputContext context) { |
| if (context.isPrimary()) { |
| close(true); |
| return; |
| } |
| IFormPage page = findPage(context.getId()); |
| if (page!=null) |
| removePage(context.getId()); |
| } |
| |
| protected void createSystemFileContexts(InputContextManager manager, |
| SystemFileEditorInput input) { |
| File file = (File) input.getAdapter(File.class); |
| File siteFile = null; |
| |
| String name = file.getName().toLowerCase(); |
| if (name.equals("site.xml")) { |
| siteFile = file; |
| } |
| if (siteFile.exists()) { |
| IEditorInput in = new SystemFileEditorInput(siteFile); |
| manager.putContext(in, new SiteInputContext(this, in, |
| file == siteFile)); |
| } |
| } |
| |
| protected void createStorageContexts(InputContextManager manager, |
| IStorageEditorInput input) { |
| String name = input.getName().toLowerCase(); |
| if (name.startsWith("site.xml")) { |
| manager.putContext(input, |
| new SiteInputContext(this, input, true)); |
| } |
| } |
| |
| protected void contextMenuAboutToShow(IMenuManager manager) { |
| super.contextMenuAboutToShow(manager); |
| } |
| |
| protected void addPages() { |
| try { |
| addPage(new FeaturesPage(this)); |
| addPage(new ArchivePage(this)); |
| } catch (PartInitException e) { |
| PDEPlugin.logException(e); |
| } |
| addSourcePage(SiteInputContext.CONTEXT_ID); |
| } |
| |
| |
| protected String computeInitialPageId() { |
| String firstPageId = super.computeInitialPageId(); |
| if (firstPageId == null) { |
| InputContext primary = inputContextManager.getPrimaryContext(); |
| if (primary.getId().equals(SiteInputContext.CONTEXT_ID)) |
| firstPageId = FeaturesPage.PAGE_ID; |
| if (firstPageId == null) |
| firstPageId = FeaturesPage.PAGE_ID; |
| } |
| return firstPageId; |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.pde.internal.ui.neweditor.MultiSourceEditor#createXMLSourcePage(org.eclipse.pde.internal.ui.neweditor.PDEFormEditor, java.lang.String, java.lang.String) |
| */ |
| protected PDESourcePage createSourcePage(PDEFormEditor editor, String title, String name, String contextId) { |
| return new SiteSourcePage(editor, title, name); |
| } |
| |
| protected IContentOutlinePage createContentOutline() { |
| return null;//return new SiteOutlinePage(this); |
| } |
| } |