1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
;
15 import java
.text
.MessageFormat
;
17 import org
.eclipse
.jface
.dialogs
.Dialog
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDAdvancedPagingProvider
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.Messages
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.layout
.FillLayout
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Control
;
25 import org
.eclipse
.swt
.widgets
.Group
;
26 import org
.eclipse
.swt
.widgets
.Label
;
27 import org
.eclipse
.swt
.widgets
.Text
;
28 import org
.eclipse
.ui
.IViewPart
;
31 * Class implementation of the pages dialog.<br>
33 * It is associated to an SDView and to a ISDAdvancedPagingProvider.<br>
38 public class PagesDialog
extends Dialog
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 * viewer and provided are kept here as attributes
47 private ISDAdvancedPagingProvider fProvider
= null;
50 private TextArea fCurrentPage
;
53 private Label fTotalPageComment
;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
60 * Standard constructor
62 * @param view The sequence diagram view reference
63 * @param provider The paging provider reference
65 public PagesDialog(IViewPart view
, ISDAdvancedPagingProvider provider
) {
66 super(view
.getSite().getShell());
68 setShellStyle(SWT
.DIALOG_TRIM
| SWT
.APPLICATION_MODAL
);
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 public Control
createDialogArea(Composite parent
) {
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
);
83 ret
.setText(Messages
.SequenceDiagram_PageNavigation
);
85 FillLayout fillLayout
= new FillLayout(SWT
.VERTICAL
);
86 ret
.setLayout(fillLayout
);
88 Label label
= new Label(ret
, SWT
.NONE
);
89 label
.setText(Messages
.SequenceDiagram_CurrentPage
);
91 fCurrentPage
= new TextArea(ret
);
92 fCurrentPage
.setBounds(1, fProvider
.pagesCount());
93 fCurrentPage
.setValue(fProvider
.currentPage() + 1);
95 fTotalPageComment
= new Label(ret
, SWT
.NONE
);
96 fTotalPageComment
.setAlignment(SWT
.RIGHT
);
100 getShell().setText(Messages
.SequenceDiagram_SequenceDiagramPages
);
105 public void okPressed() {
106 int currentPageValue
= fCurrentPage
.getValue() - 1;
108 fProvider
.pageNumberChanged(currentPageValue
);
112 * Updates the comments texts.
114 private void updateComments() {
115 int pages
= Math
.max(0, fProvider
.pagesCount());
116 StringBuffer totalPageCommentText
= new StringBuffer();
117 totalPageCommentText
.append(Messages
.SequenceDiagram_Total
);
118 totalPageCommentText
.append(pages
);
119 totalPageCommentText
.append(" "); //$NON-NLS-1$
121 totalPageCommentText
.append(Messages
.SequenceDiagram_pages
);
122 } else if (pages
== 1) {
123 totalPageCommentText
.append(Messages
.SequenceDiagram_page
);
125 totalPageCommentText
.append(Messages
.SequenceDiagram_pages
);
127 fTotalPageComment
.setText(totalPageCommentText
.toString());
131 // ------------------------------------------------------------------------
133 // ------------------------------------------------------------------------
136 * This is a Text Control that accepts only digits and ensures that bounds are respected
138 protected static class TextArea
{
144 * The minimum page value
148 * The maximum page value
155 * @param parent The paren composite
157 public TextArea(Composite parent
) {
158 fText
= new Text(parent
, SWT
.SINGLE
| SWT
.BORDER
| SWT
.RIGHT
);
159 fText
.setTextLimit(10);
163 * Sets the page value.
165 * @param page The page value
167 public void setValue(int page
) {
168 int value
= Math
.max(fMin
, Math
.min(fMax
, page
));
169 fText
.setText(Integer
.toString(value
));
173 * Returns the page value.
175 * @return the page value
177 public int getValue() {
180 res
= Integer
.parseInt(fText
.getText());
181 } catch (Exception e
) {
185 return Math
.max(fMin
, Math
.min(fMax
, res
));
189 * Sets the minimum and maximum page values.
191 * @param min A minimum page value
192 * @param max A maximum page value
194 public void setBounds(int min
, int max
) {
195 fMin
= Math
.max(0, min
);
196 fMax
= Math
.max(fMin
, max
);
197 Integer tab
[] = new Integer
[2];
198 tab
[0] = Integer
.valueOf(fMin
);
199 tab
[1] = Integer
.valueOf(fMax
);
200 fText
.setToolTipText(MessageFormat
.format(Messages
.SequenceDiagram_IsInBetween
, (Object
[]) tab
));