Change tabs to spaces; elim trailing whitespace.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / dialogs / PagesDialog.java
CommitLineData
73005152 1/**********************************************************************
c8422608 2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
73005152
BH
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
a0a88f65
AM
7 *
8 * Contributors:
c8422608
AM
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
73005152 11 **********************************************************************/
c8422608 12
df0b8ff4 13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs;
73005152
BH
14
15import java.text.MessageFormat;
16
17import org.eclipse.jface.dialogs.Dialog;
18import org.eclipse.linuxtools.tmf.ui.views.uml2sd.handlers.provider.ISDAdvancedPagingProvider;
92330441 19import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.Messages;
73005152
BH
20import org.eclipse.swt.SWT;
21import org.eclipse.swt.layout.FillLayout;
22import org.eclipse.swt.layout.GridData;
23import org.eclipse.swt.widgets.Composite;
24import org.eclipse.swt.widgets.Control;
25import org.eclipse.swt.widgets.Group;
26import org.eclipse.swt.widgets.Label;
27import org.eclipse.swt.widgets.Text;
28import org.eclipse.ui.IViewPart;
29
30/**
df0b8ff4 31 * Class implementation of the pages dialog.<br>
a0a88f65 32 *
df0b8ff4 33 * It is associated to an SDView and to a ISDAdvancedPagingProvider.<br>
a0a88f65 34 *
df0b8ff4
BH
35 * @version 1.0
36 * @author sveyrier
73005152
BH
37 */
38public class PagesDialog extends Dialog {
39
df0b8ff4
BH
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43
73005152
BH
44 /**
45 * viewer and provided are kept here as attributes
46 */
cab6c8ff 47 private ISDAdvancedPagingProvider fProvider = null;
a0a88f65
AM
48
49 /** Current page */
cab6c8ff 50 private TextArea fCurrentPage;
a0a88f65
AM
51
52 /** Comment label */
cab6c8ff 53 private Label fTotalPageComment;
73005152 54
df0b8ff4
BH
55 // ------------------------------------------------------------------------
56 // Constructors
57 // ------------------------------------------------------------------------
a0a88f65 58
73005152 59 /**
df0b8ff4 60 * Standard constructor
a0a88f65 61 *
eb63f5ff
BH
62 * @param view The sequence diagram view reference
63 * @param provider The paging provider reference
73005152 64 */
eb63f5ff
BH
65 public PagesDialog(IViewPart view, ISDAdvancedPagingProvider provider) {
66 super(view.getSite().getShell());
67 fProvider = provider;
df0b8ff4 68 setShellStyle(SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
73005152
BH
69 }
70
df0b8ff4
BH
71 // ------------------------------------------------------------------------
72 // Methods
73 // ------------------------------------------------------------------------
73005152 74
73005152
BH
75 @Override
76 public Control createDialogArea(Composite parent) {
77
78 Group ret = new Group(parent, SWT.NONE);
79 GridData data = new GridData();
80 data.grabExcessHorizontalSpace = true;
81 data.horizontalAlignment = GridData.FILL;
82 ret.setLayoutData(data);
92330441 83 ret.setText(Messages.SequenceDiagram_PageNavigation);
73005152
BH
84
85 FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
86 ret.setLayout(fillLayout);
87
88 Label label = new Label(ret, SWT.NONE);
92330441 89 label.setText(Messages.SequenceDiagram_CurrentPage);
73005152 90
eb63f5ff
BH
91 fCurrentPage = new TextArea(ret);
92 fCurrentPage.setBounds(1, fProvider.pagesCount());
93 fCurrentPage.setValue(fProvider.currentPage() + 1);
73005152 94
eb63f5ff
BH
95 fTotalPageComment = new Label(ret, SWT.NONE);
96 fTotalPageComment.setAlignment(SWT.RIGHT);
73005152
BH
97
98 updateComments();
99
92330441 100 getShell().setText(Messages.SequenceDiagram_SequenceDiagramPages);
73005152
BH
101 return ret;
102 }
103
73005152
BH
104 @Override
105 public void okPressed() {
eb63f5ff 106 int currentPageValue = fCurrentPage.getValue() - 1;
73005152 107 super.close();
eb63f5ff 108 fProvider.pageNumberChanged(currentPageValue);
73005152
BH
109 }
110
df0b8ff4 111 /**
a0a88f65 112 * Updates the comments texts.
df0b8ff4 113 */
cab6c8ff 114 private void updateComments() {
eb63f5ff
BH
115 int pages = Math.max(0, fProvider.pagesCount());
116 StringBuffer totalPageCommentText = new StringBuffer();
92330441 117 totalPageCommentText.append(Messages.SequenceDiagram_Total);
eb63f5ff
BH
118 totalPageCommentText.append(pages);
119 totalPageCommentText.append(" "); //$NON-NLS-1$
df0b8ff4 120 if (pages == 0) {
92330441 121 totalPageCommentText.append(Messages.SequenceDiagram_pages);
df0b8ff4 122 } else if (pages == 1) {
92330441 123 totalPageCommentText.append(Messages.SequenceDiagram_page);
df0b8ff4 124 } else {
92330441 125 totalPageCommentText.append(Messages.SequenceDiagram_pages);
df0b8ff4 126 }
eb63f5ff 127 fTotalPageComment.setText(totalPageCommentText.toString());
df0b8ff4
BH
128 }
129
a0a88f65 130
df0b8ff4
BH
131 // ------------------------------------------------------------------------
132 // Helper classes
133 // ------------------------------------------------------------------------
11252342 134
df0b8ff4
BH
135 /**
136 * This is a Text Control that accepts only digits and ensures that bounds are respected
137 */
138 protected static class TextArea {
139 /**
140 * The text field.
141 */
f26e290b 142 private Text fText;
df0b8ff4
BH
143 /**
144 * The minimum page value
145 */
f26e290b 146 private int fMin;
df0b8ff4
BH
147 /**
148 * The maximum page value
149 */
f26e290b 150 private int fMax;
df0b8ff4
BH
151
152 /**
153 * Constructor
a0a88f65 154 *
df0b8ff4
BH
155 * @param parent The paren composite
156 */
157 public TextArea(Composite parent) {
eb63f5ff
BH
158 fText = new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.RIGHT);
159 fText.setTextLimit(10);
df0b8ff4
BH
160 }
161
162 /**
163 * Sets the page value.
a0a88f65 164 *
df0b8ff4
BH
165 * @param page The page value
166 */
167 public void setValue(int page) {
eb63f5ff
BH
168 int value = Math.max(fMin, Math.min(fMax, page));
169 fText.setText(Integer.toString(value));
df0b8ff4
BH
170 }
171
172 /**
173 * Returns the page value.
a0a88f65 174 *
df0b8ff4
BH
175 * @return the page value
176 */
177 public int getValue() {
178 int res;
179 try {
eb63f5ff 180 res = Integer.parseInt(fText.getText());
df0b8ff4
BH
181 } catch (Exception e) {
182 // ignored
183 res = 0;
184 }
eb63f5ff 185 return Math.max(fMin, Math.min(fMax, res));
df0b8ff4
BH
186 }
187
188 /**
189 * Sets the minimum and maximum page values.
a0a88f65 190 *
eb63f5ff
BH
191 * @param min A minimum page value
192 * @param max A maximum page value
df0b8ff4 193 */
eb63f5ff
BH
194 public void setBounds(int min, int max) {
195 fMin = Math.max(0, min);
196 fMax = Math.max(fMin, max);
df0b8ff4 197 Integer tab[] = new Integer[2];
eb63f5ff
BH
198 tab[0] = Integer.valueOf(fMin);
199 tab[1] = Integer.valueOf(fMax);
92330441 200 fText.setToolTipText(MessageFormat.format(Messages.SequenceDiagram_IsInBetween, (Object[]) tab));
df0b8ff4
BH
201 }
202 }
203
73005152 204}
This page took 0.057784 seconds and 5 git commands to generate.