001: /*******************************************************************************
002: * Copyright (c) 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.toc;
011:
012: import java.io.File;
013: import java.util.ArrayList;
014:
015: import org.eclipse.core.resources.IFile;
016: import org.eclipse.core.runtime.CoreException;
017: import org.eclipse.jface.text.IDocument;
018: import org.eclipse.pde.core.IBaseModel;
019: import org.eclipse.pde.internal.core.text.AbstractEditingModel;
020: import org.eclipse.pde.internal.core.text.toc.TocModel;
021: import org.eclipse.pde.internal.ui.editor.JarEntryEditorInput;
022: import org.eclipse.pde.internal.ui.editor.PDEFormEditor;
023: import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput;
024: import org.eclipse.pde.internal.ui.editor.context.XMLInputContext;
025: import org.eclipse.ui.IEditorInput;
026: import org.eclipse.ui.IFileEditorInput;
027: import org.eclipse.ui.IStorageEditorInput;
028:
029: /**
030: * TocInputContext
031: *
032: */
033: public class TocInputContext extends XMLInputContext {
034:
035: public static final String CONTEXT_ID = "toc-context"; //$NON-NLS-1$
036:
037: /**
038: * @param editor
039: * @param input
040: * @param primary
041: */
042: public TocInputContext(PDEFormEditor editor, IEditorInput input,
043: boolean primary) {
044: super (editor, input, primary);
045: create();
046: }
047:
048: /* (non-Javadoc)
049: * @see org.eclipse.pde.internal.ui.editor.context.InputContext#createModel(org.eclipse.ui.IEditorInput)
050: */
051: protected IBaseModel createModel(IEditorInput input)
052: throws CoreException {
053: if (input instanceof IStorageEditorInput) {
054: boolean isReconciling = input instanceof IFileEditorInput;
055: IDocument document = getDocumentProvider().getDocument(
056: input);
057:
058: TocModel model = new TocModel(document, isReconciling);
059:
060: if (input instanceof IFileEditorInput) {
061: IFile file = ((IFileEditorInput) input).getFile();
062: model.setUnderlyingResource(file);
063: model.setCharset(file.getCharset());
064: } else if (input instanceof SystemFileEditorInput) {
065: File file = (File) ((SystemFileEditorInput) input)
066: .getAdapter(File.class);
067: model.setInstallLocation(file.getParent());
068: model.setCharset(getDefaultCharset());
069: } else if (input instanceof JarEntryEditorInput) {
070: File file = (File) ((JarEntryEditorInput) input)
071: .getAdapter(File.class);
072: model.setInstallLocation(file.toString());
073: model.setCharset(getDefaultCharset());
074: } else {
075: model.setCharset(getDefaultCharset());
076: }
077:
078: model.load();
079:
080: return model;
081: }
082:
083: return null;
084: }
085:
086: /* (non-Javadoc)
087: * @see org.eclipse.pde.internal.ui.editor.context.InputContext#getId()
088: */
089: public String getId() {
090: return CONTEXT_ID;
091: }
092:
093: /* (non-Javadoc)
094: * @see org.eclipse.pde.internal.ui.editor.context.XMLInputContext#reorderInsertEdits(java.util.ArrayList)
095: */
096: protected void reorderInsertEdits(ArrayList ops) {
097: // NO-OP
098: }
099:
100: /* (non-Javadoc)
101: * @see org.eclipse.pde.internal.ui.editor.context.InputContext#doRevert()
102: */
103: public void doRevert() {
104: fEditOperations.clear();
105: fOperationTable.clear();
106: fMoveOperations.clear();
107: AbstractEditingModel model = (AbstractEditingModel) getModel();
108: model.reconciled(model.getDocument());
109: }
110:
111: /* (non-Javadoc)
112: * @see org.eclipse.pde.internal.ui.editor.context.InputContext#getPartitionName()
113: */
114: protected String getPartitionName() {
115: return "___toc_partition"; //$NON-NLS-1$
116: }
117: }
|