Organized imports
[phpeclipse.git] / net.sourceforge.phpeclipse.xml.ui / src / net / sourceforge / phpeclipse / xml / ui / internal / text / AttValueDoubleClickStrategy.java
1 /*
2  * Copyright (c) 2002-2004 Widespace, OU and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     Igor Malinin - initial contribution
10  *
11  * $Id: AttValueDoubleClickStrategy.java,v 1.2 2005-05-06 00:55:41 stefanbjarni Exp $
12  */
13
14 package net.sourceforge.phpeclipse.xml.ui.internal.text;
15
16 import net.sourceforge.phpeclipse.ui.text.TextDoubleClickStrategy;
17
18 import org.eclipse.jface.text.BadLocationException;
19 import org.eclipse.jface.text.IDocument;
20 import org.eclipse.jface.text.ITextViewer;
21 import org.eclipse.jface.text.ITypedRegion;
22
23
24 /**
25  * 
26  * 
27  * @author Igor Malinin
28  */
29 public class AttValueDoubleClickStrategy extends TextDoubleClickStrategy {
30         /*
31          * @see org.eclipse.jface.text.ITextDoubleClickStrategy#doubleClicked(ITextViewer)
32          */
33         public void doubleClicked(ITextViewer viewer) {
34                 int offset = viewer.getSelectedRange().x;
35                 if (offset < 0) {
36                         return;
37                 }
38
39                 try {
40                         IDocument document = viewer.getDocument();
41
42                         ITypedRegion region = document.getPartition(offset);
43
44                         int start = region.getOffset();
45                         int length = region.getLength();
46                         int end = start + length - 1;
47
48                         if (offset == start) {
49                                 if (document.getChar(start) == document.getChar(end)) {
50                                         viewer.setSelectedRange(start + 1, length - 2);
51                                 } else {
52                                         viewer.setSelectedRange(start + 1, length - 1);
53                                 }
54
55                                 return;
56                         }
57
58                         if (offset == end) {
59                                 if (document.getChar(start) == document.getChar(end)) {
60                                         viewer.setSelectedRange(start + 1, length - 2);
61                                         return;
62                                 }
63                         }
64
65                         super.doubleClicked(viewer);
66                 } catch (BadLocationException e) {}
67         }
68 }