Added plog4u.de plog4u.org
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / actions / RemoveBlockCommentAction.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation 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  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.actions;
12
13 import java.util.LinkedList;
14 import java.util.List;
15 import java.util.ResourceBundle;
16
17 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
18
19 import org.eclipse.jface.text.BadLocationException;
20 import org.eclipse.jface.text.BadPartitioningException;
21 import org.eclipse.jface.text.IDocumentExtension3;
22 import org.eclipse.jface.text.ITextSelection;
23 import org.eclipse.jface.text.ITypedRegion;
24 import org.eclipse.ui.texteditor.ITextEditor;
25
26
27 /**
28  * Action that removes the enclosing comment marks from a Java block comment.
29  * 
30  * @since 3.0
31  */
32 public class RemoveBlockCommentAction extends BlockCommentAction {
33     final static String DEFAULT_PARTITIONING_CONTENT_TYPE = "__dftl_partition_content_type"; //$NON-NLS-1$
34         
35         /**
36          * Creates a new instance.
37          * 
38          * @param bundle the resource bundle
39          * @param prefix a prefix to be prepended to the various resource keys
40          *   (described in <code>ResourceAction</code> constructor), or 
41          *   <code>null</code> if none
42          * @param editor the text editor
43          */
44         public RemoveBlockCommentAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
45                 super(bundle, prefix, editor);
46         }
47         
48         /*
49          * @see org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction#runInternal(org.eclipse.jface.text.ITextSelection, org.eclipse.jface.text.IDocumentExtension3, org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction.Edit.EditFactory)
50          */
51         protected void runInternal(ITextSelection selection, IDocumentExtension3 docExtension, Edit.EditFactory factory) throws BadPartitioningException, BadLocationException {
52                 List edits= new LinkedList();
53                 int tokenLength= getCommentStart().length();
54                 
55                 int offset= selection.getOffset();
56                 int endOffset= offset + selection.getLength();
57
58 //              ITypedRegion partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, offset, false);
59                 ITypedRegion partition= docExtension.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, offset, false);
60                 
61                 int partOffset= partition.getOffset();
62                 int partEndOffset= partOffset + partition.getLength();
63                 
64                 while (partEndOffset < endOffset) {
65                         
66                         if (partition.getType() == IPHPPartitions.PHP_PHPDOC_COMMENT) {
67                                 edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
68                                 edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
69                         }
70                         
71 //                      partition= docExtension.getPartition(IPHPPartitions.PHP_PARTITIONING, partEndOffset, false);
72                         partition= docExtension.getPartition(IDocumentExtension3.DEFAULT_PARTITIONING, partEndOffset, false);
73                         
74                         partOffset= partition.getOffset();
75                         partEndOffset= partOffset + partition.getLength();
76                 }
77
78 //              if (partition.getType() == IPHPPartitions.PHP_PHPDOC_COMMENT) {
79                 if (partition.getType() ==   DEFAULT_PARTITIONING_CONTENT_TYPE) {
80                         edits.add(factory.createEdit(partOffset, tokenLength, "")); //$NON-NLS-1$
81                         edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
82                 }
83
84                 executeEdits(edits);
85         }
86
87         /*
88          * @see org.eclipse.jdt.internal.ui.actions.AddBlockCommentAction#validSelection(org.eclipse.jface.text.ITextSelection)
89          */
90         protected boolean isValidSelection(ITextSelection selection) {
91                 return selection != null && !selection.isEmpty();
92         }
93
94 }