1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2014 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.jfreechart.chart.properties;
\r
14 import org.eclipse.swt.events.ControlEvent;
\r
15 import org.eclipse.swt.events.ControlListener;
\r
16 import org.eclipse.swt.graphics.Point;
\r
17 import org.eclipse.swt.widgets.Composite;
\r
18 import org.eclipse.ui.IWorkbenchSite;
\r
19 import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
\r
20 import org.simantics.db.management.ISessionContext;
\r
21 import org.simantics.selectionview.StandardProperties;
\r
24 * Tab adjusting the layout depending on its dimensions.
\r
25 * @author Tuomas Miettinen
\r
28 public abstract class AdjustableTab extends LabelPropertyTabContributor {
\r
30 private Composite spp;
\r
31 private ControlListener controlListener;
\r
32 private static final int WIDE_SCREEN_WIDTH = 1100;
\r
35 public void createControls(Composite body, IWorkbenchSite site, ISessionContext context, WidgetSupport _support) {
\r
36 // Get size of the available area.
\r
39 spp = spp.getParent();
\r
40 } while (!(spp instanceof StandardProperties));
\r
42 // Add listener to change the layout when the composite resizes.
\r
43 spp.addControlListener(controlListener = new ControlListener(){
\r
46 public void controlMoved(ControlEvent e) {}
\r
49 public void controlResized(ControlEvent e) {
\r
54 // Create the controls and their initial layout.
\r
55 createAndAddControls(body, site, context, _support);
\r
60 * Create controls and add them to the tab.
\r
61 * @param body the composite where the controls are added.
\r
66 protected abstract void createAndAddControls(Composite body, IWorkbenchSite site,
\r
67 ISessionContext context, WidgetSupport _support);
\r
70 * Create layout for controls.
\r
72 protected void createLayout() {
\r
73 Point size = spp.getSize();
\r
74 if (size.x > size.y) {
\r
75 createControlLayoutHorizontal((size.x > WIDE_SCREEN_WIDTH));
\r
77 createControlLayoutVertical();
\r
82 * Determine if the layout uses vertical layout
\r
83 * @return true iff the layout uses vertical layout
\r
85 protected boolean isVertical() {
\r
86 Point size = spp.getSize();
\r
87 return size.x < size.y;
\r
91 * Create vertical layout for controls.
\r
93 protected abstract void createControlLayoutVertical();
\r
96 * Create horizontal layout for controls.
\r
97 * @param wideScreen true iff the control is wider than WIDE_SCREEN_WIDTH
\r
99 protected abstract void createControlLayoutHorizontal(boolean wideScreen);
\r
102 public void dispose() {
\r
103 if(controlListener != null && spp != null)
\r
104 spp.removeControlListener(controlListener);
\r