1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*******************************************************************************
* Copyright (c) 2006 Sybase, Inc. and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Sybase, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.jst.pagedesigner.actions.range;
import org.eclipse.gef.commands.Command;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jst.pagedesigner.commands.range.Paragraph;
import org.eclipse.jst.pagedesigner.commands.range.ParagraphFinder;
import org.eclipse.jst.pagedesigner.commands.range.ParagraphUnapplyStyleCommand;
import org.eclipse.jst.pagedesigner.dom.DOMRange;
import org.eclipse.jst.pagedesigner.dom.EditModelQuery;
import org.eclipse.jst.pagedesigner.dom.IDOMPosition;
import org.w3c.dom.Node;
/**
* @author mengbo
*/
public class NoneParagraphStyleAction extends ParagraphStyleAction {
public static final String[] HH = { "h1", "h2", "h3", "h4", "h5", "h6" };
private String[] _applyingTags;
/**
* @param text
* @param name
* @param image
* @param style
*/
public NoneParagraphStyleAction(String text, String[] tags,
ImageDescriptor image, int style) {
super(text, "", image, style);
_applyingTags = tags;
}
/**
* @param text
* @param node
* @param image
* @param style
*/
public NoneParagraphStyleAction(String text, Node node,
ImageDescriptor image, int style) {
super(text, node, image, style);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.editors.actions.DesignerToolBarAction#isApplied(org.eclipse.jst.pagedesigner.dom.DOMRange)
*/
protected boolean isApplied(DOMRange range) {
if (range != null) {
boolean ordered = range.isOrdered();
IDOMPosition start = ordered ? range.getStartPosition() : range
.getEndPosition();
IDOMPosition end = ordered ? range.getEndPosition() : range
.getStartPosition();
Node common = null;
if (EditModelQuery.isSame(range)) {
ParagraphFinder finder = new ParagraphFinder(start);
Paragraph p = finder.getParagraph(start);
common = p.getLowestContainer();
} else {
common = EditModelQuery.getInstance().getCommonAncestor(start,
end);
}
// the lowest common block parent is the container to apply style.
if (EditModelQuery.hasAncestor(common, _applyingTags, true)) {
return false;
} else {
return true;
}
} else {
return false;
}
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jst.pagedesigner.commands.range.DesignerToolBarAction#getCommand()
*/
protected Command getCommand() {
ParagraphUnapplyStyleCommand command = new ParagraphUnapplyStyleCommand(
getViewer(), _applyingTags, null, null);
return command;
}
}
|