| /******************************************************************************* |
| * Copyright (c) 2001, 2006 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.wst.xsd.ui.internal.adt.editor; |
| |
| import org.eclipse.draw2d.IFigure; |
| import org.eclipse.gef.EditPart; |
| import org.eclipse.gef.EditPartFactory; |
| import org.eclipse.gef.GraphicalEditPart; |
| import org.eclipse.gef.GraphicalViewer; |
| import org.eclipse.gef.editparts.ZoomManager; |
| import org.eclipse.gef.ui.actions.ActionRegistry; |
| import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; |
| import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
| import org.eclipse.wst.xsd.ui.internal.adt.actions.BaseSelectionAction; |
| import org.eclipse.wst.xsd.ui.internal.adt.actions.SetInputToGraphView; |
| import org.eclipse.wst.xsd.ui.internal.adt.design.DesignViewGraphicalViewer; |
| import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.ADTEditPartFactory; |
| import org.eclipse.wst.xsd.ui.internal.adt.facade.IModel; |
| import org.eclipse.wst.xsd.ui.internal.adt.outline.ADTContentOutlinePage; |
| import org.eclipse.wst.xsd.ui.internal.adt.outline.ADTContentOutlineProvider; |
| import org.eclipse.wst.xsd.ui.internal.adt.outline.ADTLabelProvider; |
| import org.eclipse.wst.xsd.ui.internal.editor.XSDEditorPlugin; |
| |
| public abstract class ADTMultiPageEditor extends CommonMultiPageEditor |
| { |
| protected IModel model; |
| private int currentPage = -1; |
| |
| /** |
| * Creates a multi-page editor example. |
| */ |
| public ADTMultiPageEditor() |
| { |
| super(); |
| } |
| |
| public String getContributorId() |
| { |
| return "org.eclipse.wst.xsd.ui.internal.editor"; //$NON-NLS-1$ |
| } |
| |
| public IContentOutlinePage getContentOutlinePage() |
| { |
| if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed()) |
| { |
| ADTContentOutlinePage outlinePage = new ADTContentOutlinePage(this); |
| ADTContentOutlineProvider adtContentProvider = new ADTContentOutlineProvider(); |
| outlinePage.setContentProvider(adtContentProvider); |
| ADTLabelProvider adtLabelProvider = new ADTLabelProvider(); |
| outlinePage.setLabelProvider(adtLabelProvider); |
| outlinePage.setModel(getModel()); |
| |
| fOutlinePage = outlinePage; |
| } |
| return fOutlinePage; |
| } |
| |
| /** |
| * Creates the pages of the multi-page editor. |
| */ |
| protected void createPages() |
| { |
| selectionProvider = getSelectionManager(); |
| |
| createGraphPage(); |
| createSourcePage(); |
| |
| getEditorSite().setSelectionProvider(selectionProvider); |
| |
| model = buildModel(); // (IFileEditorInput)getEditorInput()); |
| |
| initializeGraphicalViewer(); |
| |
| int pageIndexToShow = getDefaultPageTypeIndex(); |
| setActivePage(pageIndexToShow); |
| } |
| |
| protected int getDefaultPageTypeIndex() { |
| int pageIndex = SOURCE_PAGE_INDEX; |
| if (XSDEditorPlugin.getPlugin().getDefaultPage().equals(XSDEditorPlugin.DESIGN_PAGE)) { |
| pageIndex = DESIGN_PAGE_INDEX; |
| } |
| |
| return pageIndex; |
| } |
| |
| protected void pageChange(int newPageIndex) |
| { |
| currentPage = newPageIndex; |
| super.pageChange(newPageIndex); |
| } |
| |
| protected ScrollingGraphicalViewer getGraphicalViewer() |
| { |
| return new DesignViewGraphicalViewer(this, getSelectionManager()); |
| } |
| |
| abstract public IModel buildModel(); // (IFileEditorInput editorInput); |
| |
| protected void createActions() |
| { |
| ActionRegistry registry = getActionRegistry(); |
| |
| BaseSelectionAction action = new SetInputToGraphView(this); |
| action.setSelectionProvider(getSelectionManager()); |
| registry.registerAction(action); |
| } |
| |
| |
| public IModel getModel() |
| { |
| return model; |
| } |
| |
| public Object getAdapter(Class type) |
| { |
| if (type == ZoomManager.class) |
| return graphicalViewer.getProperty(ZoomManager.class.toString()); |
| |
| if (type == GraphicalViewer.class) |
| return graphicalViewer; |
| if (type == EditPart.class && graphicalViewer != null) |
| return graphicalViewer.getRootEditPart(); |
| if (type == IFigure.class && graphicalViewer != null) |
| return ((GraphicalEditPart) graphicalViewer.getRootEditPart()).getFigure(); |
| |
| if (type == IContentOutlinePage.class) |
| { |
| return getContentOutlinePage(); |
| } |
| |
| return super.getAdapter(type); |
| } |
| |
| protected EditPartFactory getEditPartFactory() { |
| return new ADTEditPartFactory(); |
| } |
| |
| protected void initializeGraphicalViewer() |
| { |
| graphicalViewer.setContents(model); |
| } |
| |
| public void dispose() |
| { |
| if (currentPage == SOURCE_PAGE_INDEX) |
| { |
| XSDEditorPlugin.getPlugin().setSourcePageAsDefault(); |
| } |
| else |
| { |
| XSDEditorPlugin.getPlugin().setDesignPageAsDefault(); |
| } |
| |
| super.dispose(); |
| } |
| } |