X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsymbollibrary%2Fui%2FSymbolPageView.java;h=5724cbcfeffa3a5df14047bd7f9a226bd81a74b9;hb=5e8ced2e11529386fb9807975312714903d81f91;hp=d6ec79b8bcd2e17b20b6f95294e09ece11ebf2ce;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/ui/SymbolPageView.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/ui/SymbolPageView.java index d6ec79b8b..5724cbcfe 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/ui/SymbolPageView.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/symbollibrary/ui/SymbolPageView.java @@ -1,237 +1,237 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.symbollibrary.ui; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.contexts.IContextService; -import org.eclipse.ui.part.IContributedContentsView; -import org.eclipse.ui.part.IPage; -import org.eclipse.ui.part.Page; -import org.eclipse.ui.part.PageBook; -import org.eclipse.ui.part.PageBookView; -import org.simantics.db.management.ISessionContextProvider; -import org.simantics.diagram.symbolcontribution.EmptySymbolProviderFactory; -import org.simantics.diagram.symbolcontribution.SymbolProviderFactory; -import org.simantics.ui.SimanticsUI; -import org.simantics.utils.datastructures.BijectionMap; - -/** - * This paged view shows {@link SymbolLibraryPage}s for editors based on the - * {@link ISymbolProviderFactory} the editors adapt to. ISymbolProvider equality is - * used for deciding what pages to create/assign for activated workbench parts. - * Only editors are considered in page creation. - * - *
- * To get a symbol palette for your editor, add the following to your - * {@link IEditorPart#getAdapter(Class)} implementation: - * - *
- * if (c == ISymbolProviderFactory.class) { - * try { - * return DiagramTypeUtils.readSymbolProviderFactory(RequestProcessor, Resource diagram); - * } catch (DatabaseException e) { - * // TODO: Log error - * return null; - * } - * } - *- * - * @author Tuukka Lehtonen - */ -public class SymbolPageView extends PageBookView { - - private static final String SYMBOL_VIEW_CONTEXT = "org.simantics.diagram.symbolLibrary"; - - private ISessionContextProvider contextProvider; - - private IMemento memento; - - BijectionMap
null
if no editor contributed the current page
- */
- private IWorkbenchPart getContributingEditor() {
- return getCurrentContributingPart();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
- */
- @Override
- public void init(IViewSite site, IMemento memento) throws PartInitException {
- this.memento = memento;
- init(site);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.part.PageBookView#init(org.eclipse.ui.IViewSite)
- */
- @Override
- public void init(IViewSite site) throws PartInitException {
- super.init(site);
-
- // This prevents the view from providing a selection to other
- // workbench parts, thus making them lose their selections which is not
- // desirable.
- site.setSelectionProvider(null);
-
- contextProvider = SimanticsUI.getSessionContextProvider();
- }
-
- @Override
- public void saveState(IMemento memento) {
- if (this.memento != null) {
- memento.putMemento(this.memento);
- }
- }
-
- /* (non-Javadoc)
- * Method declared on IWorkbenchPart.
- */
- @Override
- public void dispose() {
-// System.out.println("dispose: " + this);
- // Dispose of this before nullifying contextProvider because this
- // dispose may just need the context provider - at least PropertyPage
- // disposal will.
- super.dispose();
-
- contextProvider = null;
- }
-
- @Override
- protected IPage createDefaultPage(PageBook book) {
- Page page = new SymbolLibraryPage(EmptySymbolProviderFactory.INSTANCE);
- initPage(page);
- page.createControl(getPageBook());
- return page;
-// MessagePage page = new MessagePage();
-// initPage(page);
-// page.createControl(book);
-// page.setMessage(Messages.SymbolPageView_noSymbolsAvailable);
-// return page;
- }
-
- @Override
- protected PageRec doCreatePage(IWorkbenchPart part) {
- SymbolProviderFactory providerFactory = (SymbolProviderFactory) part.getAdapter(SymbolProviderFactory.class);
- if (providerFactory == null)
- return null;
-
- IPage page = providerPageMap.getRight(providerFactory);
- if (page == null) {
- //System.out.println("create new symbol library page for part " + part + " and symbol provider factory " + providerFactory);
- Page newPage = new SymbolLibraryPage(providerFactory);
- initPage(newPage);
- newPage.createControl(getPageBook());
-
- providerPageMap.map(providerFactory, newPage);
- page = newPage;
- }
- return new PageRec(part, page);
- }
-
- @Override
- protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
- IPage page = pageRecord.page;
- @SuppressWarnings("unused")
- SymbolProviderFactory provider = providerPageMap.removeWithRight(page);
- //System.out.println("destroy page " + page + " for symbol provider " + provider + " by closing part " + part);
- page.dispose();
- pageRecord.dispose();
- }
-
- @Override
- protected IWorkbenchPart getBootstrapPart() {
- IWorkbenchPage page = getSite().getPage();
- if (page != null) {
- IEditorPart editor = page.getActiveEditor();
- if (editor != null)
- return editor;
- return page.getActivePart();
- }
- return null;
- }
-
- @Override
- protected boolean isImportant(IWorkbenchPart part) {
- // Ignore all but editors.
- return part instanceof IEditorPart;
- }
-
- /* (non-Javadoc)
- * Method declared on IViewPart.
- * Treat this the same as part activation.
- */
- @Override
- public void partBroughtToTop(IWorkbenchPart part) {
- partActivated(part);
- }
-
-// @Override
-// public void partActivated(IWorkbenchPart part) {
-// IWorkbenchPart source = getSourcePart(part);
-// //System.out.println("part activated: " + part + ", " + source);
-// super.partActivated(source);
-// }
-//
-// private IWorkbenchPart getSourcePart(IWorkbenchPart part) {
-// IContributedContentsView view = (IContributedContentsView) part.getAdapter(IContributedContentsView.class);
-// if (view != null) {
-// IWorkbenchPart source = view.getContributingPart();
-// if (source != null)
-// return source;
-// }
-// return part;
-// }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * 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:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.diagram.symbollibrary.ui;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IViewSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.part.IContributedContentsView;
+import org.eclipse.ui.part.IPage;
+import org.eclipse.ui.part.Page;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.part.PageBookView;
+import org.simantics.db.management.ISessionContextProvider;
+import org.simantics.diagram.symbolcontribution.EmptySymbolProviderFactory;
+import org.simantics.diagram.symbolcontribution.SymbolProviderFactory;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.utils.datastructures.BijectionMap;
+
+/**
+ * This paged view shows {@link SymbolLibraryPage}s for editors based on the
+ * {@link ISymbolProviderFactory} the editors adapt to. ISymbolProvider equality is
+ * used for deciding what pages to create/assign for activated workbench parts.
+ * Only editors are considered in page creation.
+ *
+ * + * To get a symbol palette for your editor, add the following to your + * {@link IEditorPart#getAdapter(Class)} implementation: + * + *
+ * if (c == ISymbolProviderFactory.class) { + * try { + * return DiagramTypeUtils.readSymbolProviderFactory(RequestProcessor, Resource diagram); + * } catch (DatabaseException e) { + * // TODO: Log error + * return null; + * } + * } + *+ * + * @author Tuukka Lehtonen + */ +public class SymbolPageView extends PageBookView { + + private static final String SYMBOL_VIEW_CONTEXT = "org.simantics.diagram.symbolLibrary"; + + private ISessionContextProvider contextProvider; + + private IMemento memento; + + BijectionMap
null
if no editor contributed the current page
+ */
+ private IWorkbenchPart getContributingEditor() {
+ return getCurrentContributingPart();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
+ */
+ @Override
+ public void init(IViewSite site, IMemento memento) throws PartInitException {
+ this.memento = memento;
+ init(site);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.part.PageBookView#init(org.eclipse.ui.IViewSite)
+ */
+ @Override
+ public void init(IViewSite site) throws PartInitException {
+ super.init(site);
+
+ // This prevents the view from providing a selection to other
+ // workbench parts, thus making them lose their selections which is not
+ // desirable.
+ site.setSelectionProvider(null);
+
+ contextProvider = SimanticsUI.getSessionContextProvider();
+ }
+
+ @Override
+ public void saveState(IMemento memento) {
+ if (this.memento != null) {
+ memento.putMemento(this.memento);
+ }
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IWorkbenchPart.
+ */
+ @Override
+ public void dispose() {
+// System.out.println("dispose: " + this);
+ // Dispose of this before nullifying contextProvider because this
+ // dispose may just need the context provider - at least PropertyPage
+ // disposal will.
+ super.dispose();
+
+ contextProvider = null;
+ }
+
+ @Override
+ protected IPage createDefaultPage(PageBook book) {
+ Page page = new SymbolLibraryPage(EmptySymbolProviderFactory.INSTANCE);
+ initPage(page);
+ page.createControl(getPageBook());
+ return page;
+// MessagePage page = new MessagePage();
+// initPage(page);
+// page.createControl(book);
+// page.setMessage(Messages.SymbolPageView_noSymbolsAvailable);
+// return page;
+ }
+
+ @Override
+ protected PageRec doCreatePage(IWorkbenchPart part) {
+ SymbolProviderFactory providerFactory = (SymbolProviderFactory) part.getAdapter(SymbolProviderFactory.class);
+ if (providerFactory == null)
+ return null;
+
+ IPage page = providerPageMap.getRight(providerFactory);
+ if (page == null) {
+ //System.out.println("create new symbol library page for part " + part + " and symbol provider factory " + providerFactory);
+ Page newPage = new SymbolLibraryPage(providerFactory);
+ initPage(newPage);
+ newPage.createControl(getPageBook());
+
+ providerPageMap.map(providerFactory, newPage);
+ page = newPage;
+ }
+ return new PageRec(part, page);
+ }
+
+ @Override
+ protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) {
+ IPage page = pageRecord.page;
+ @SuppressWarnings("unused")
+ SymbolProviderFactory provider = providerPageMap.removeWithRight(page);
+ //System.out.println("destroy page " + page + " for symbol provider " + provider + " by closing part " + part);
+ page.dispose();
+ pageRecord.dispose();
+ }
+
+ @Override
+ protected IWorkbenchPart getBootstrapPart() {
+ IWorkbenchPage page = getSite().getPage();
+ if (page != null) {
+ IEditorPart editor = page.getActiveEditor();
+ if (editor != null)
+ return editor;
+ return page.getActivePart();
+ }
+ return null;
+ }
+
+ @Override
+ protected boolean isImportant(IWorkbenchPart part) {
+ // Ignore all but editors.
+ return part instanceof IEditorPart;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IViewPart.
+ * Treat this the same as part activation.
+ */
+ @Override
+ public void partBroughtToTop(IWorkbenchPart part) {
+ partActivated(part);
+ }
+
+// @Override
+// public void partActivated(IWorkbenchPart part) {
+// IWorkbenchPart source = getSourcePart(part);
+// //System.out.println("part activated: " + part + ", " + source);
+// super.partActivated(source);
+// }
+//
+// private IWorkbenchPart getSourcePart(IWorkbenchPart part) {
+// IContributedContentsView view = (IContributedContentsView) part.getAdapter(IContributedContentsView.class);
+// if (view != null) {
+// IWorkbenchPart source = view.getContributingPart();
+// if (source != null)
+// return source;
+// }
+// return part;
+// }
+
+}