Initialize
[sdk/ide/product.git] / org.eclipse.jst.pagedesigner / src / org / eclipse / jst / pagedesigner / viewer / DesignRange.java
1 /*******************************************************************************\r
2  * Copyright (c) 2006 Sybase, Inc. and others.\r
3  *\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
8  *\r
9  * Contributors:\r
10  *     Sybase, Inc. - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.eclipse.jst.pagedesigner.viewer;\r
13 \r
14 import org.eclipse.jface.viewers.ISelection;\r
15 \r
16 /**\r
17  * @author mengbo\r
18  */\r
19 public class DesignRange implements ISelection \r
20 {\r
21     private final DesignPosition _start;\r
22     private final DesignPosition _end;\r
23 \r
24         /**\r
25          * @param start\r
26          * @param end\r
27          */\r
28         public DesignRange(DesignPosition start, DesignPosition end) {\r
29                 _start = start;\r
30                 _end = end;\r
31         }\r
32 \r
33         /**\r
34          * @return the start position in the range\r
35          */\r
36         public DesignPosition getStartPosition() {\r
37                 return _start;\r
38         }\r
39 \r
40         /**\r
41          * @return the end position in the range\r
42          */\r
43         public DesignPosition getEndPosition() {\r
44                 return _end;\r
45         }\r
46 \r
47         /**\r
48          * @return true if the range is valid\r
49          */\r
50         public boolean isValid() {\r
51                 return _start != null && _start.isValid() && _end != null\r
52                                 && _end.isValid();\r
53         }\r
54 \r
55         /*\r
56          * (non-Javadoc)\r
57          * \r
58          * @see org.eclipse.jface.viewers.ISelection#isEmpty()\r
59          */\r
60         public boolean isEmpty() {\r
61                 // FIXME: temp implementation, need revisit.\r
62                 return !isValid() || _start.equals(_end);\r
63         }\r
64 \r
65         /**\r
66          * @param buffer\r
67          * @return a buffer with the debug dum\r
68          */\r
69         public StringBuffer debugDump(StringBuffer buffer) {\r
70                 if (_start != null) {\r
71                         buffer.append("Start: ").append(_start); //$NON-NLS-1$\r
72                 } else {\r
73                         buffer.append("Start: null"); //$NON-NLS-1$\r
74                 }\r
75                 if (_end != null) {\r
76                         buffer.append("End: ").append(_end); //$NON-NLS-1$\r
77                 } else {\r
78                         buffer.append("End: null"); //$NON-NLS-1$\r
79                 }\r
80                 return buffer;\r
81         }\r
82 \r
83         public String toString() {\r
84                 StringBuffer buffer = new StringBuffer();\r
85                 return debugDump(buffer).toString();\r
86         }\r
87 }\r