1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
;
16 import java
.text
.MessageFormat
;
18 import org
.eclipse
.jface
.dialogs
.Dialog
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDAdvancedPagingProvider
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDMessages
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.layout
.FillLayout
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.swt
.widgets
.Control
;
26 import org
.eclipse
.swt
.widgets
.Group
;
27 import org
.eclipse
.swt
.widgets
.Label
;
28 import org
.eclipse
.swt
.widgets
.Text
;
29 import org
.eclipse
.ui
.IViewPart
;
32 * Class implementation of the pages dialog.<br>
34 * It is associated to an SDView and to a ISDAdvancedPagingProvider.<br>
39 public class PagesDialog
extends Dialog
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * viewer and provided are kept here as attributes
48 protected ISDAdvancedPagingProvider fProvider
= null;
51 protected TextArea fCurrentPage
;
54 protected Label fTotalPageComment
;
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
61 * Standard constructor
63 * @param view The sequence diagram view reference
64 * @param provider The paging provider reference
66 public PagesDialog(IViewPart view
, ISDAdvancedPagingProvider provider
) {
67 super(view
.getSite().getShell());
69 setShellStyle(SWT
.DIALOG_TRIM
| SWT
.APPLICATION_MODAL
);
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
78 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
81 public Control
createDialogArea(Composite parent
) {
83 Group ret
= new Group(parent
, SWT
.NONE
);
84 GridData data
= new GridData();
85 data
.grabExcessHorizontalSpace
= true;
86 data
.horizontalAlignment
= GridData
.FILL
;
87 ret
.setLayoutData(data
);
88 ret
.setText(SDMessages
._67
);
90 FillLayout fillLayout
= new FillLayout(SWT
.VERTICAL
);
91 ret
.setLayout(fillLayout
);
93 Label label
= new Label(ret
, SWT
.NONE
);
94 label
.setText(SDMessages
._75
);
96 fCurrentPage
= new TextArea(ret
);
97 fCurrentPage
.setBounds(1, fProvider
.pagesCount());
98 fCurrentPage
.setValue(fProvider
.currentPage() + 1);
100 fTotalPageComment
= new Label(ret
, SWT
.NONE
);
101 fTotalPageComment
.setAlignment(SWT
.RIGHT
);
105 getShell().setText(SDMessages
._68
);
111 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
114 public void okPressed() {
115 int currentPageValue
= fCurrentPage
.getValue() - 1;
117 fProvider
.pageNumberChanged(currentPageValue
);
121 * Updates the comments texts.
123 protected void updateComments() {
124 int pages
= Math
.max(0, fProvider
.pagesCount());
125 StringBuffer totalPageCommentText
= new StringBuffer();
126 totalPageCommentText
.append(SDMessages
._70
);
127 totalPageCommentText
.append(pages
);
128 totalPageCommentText
.append(" "); //$NON-NLS-1$
130 totalPageCommentText
.append(SDMessages
._71
);
131 } else if (pages
== 1) {
132 totalPageCommentText
.append(SDMessages
._72
);
134 totalPageCommentText
.append(SDMessages
._73
);
136 fTotalPageComment
.setText(totalPageCommentText
.toString());
140 // ------------------------------------------------------------------------
142 // ------------------------------------------------------------------------
144 * This is a Text Control that accepts only digits and ensures that bounds are respected
146 protected static class TextArea
{
150 protected Text fText
;
152 * The minimum page value
156 * The maximum page value
163 * @param parent The paren composite
165 public TextArea(Composite parent
) {
166 fText
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
| SWT
.RIGHT
);
167 fText
.setTextLimit(10);
171 * Sets the page value.
173 * @param page The page value
175 public void setValue(int page
) {
176 int value
= Math
.max(fMin
, Math
.min(fMax
, page
));
177 fText
.setText(Integer
.toString(value
));
181 * Returns the page value.
183 * @return the page value
185 public int getValue() {
188 res
= Integer
.parseInt(fText
.getText());
189 } catch (Exception e
) {
193 return Math
.max(fMin
, Math
.min(fMax
, res
));
197 * Sets the minimum and maximum page values.
199 * @param min A minimum page value
200 * @param max A maximum page value
202 public void setBounds(int min
, int max
) {
203 fMin
= Math
.max(0, min
);
204 fMax
= Math
.max(fMin
, max
);
205 Integer tab
[] = new Integer
[2];
206 tab
[0] = Integer
.valueOf(fMin
);
207 tab
[1] = Integer
.valueOf(fMax
);
208 fText
.setToolTipText(MessageFormat
.format(SDMessages
._69
, (Object
[]) tab
));