1.1 --- a/bpel.search/nbproject/project.properties Mon Jan 15 14:44:19 2007 +0000
1.2 +++ b/bpel.search/nbproject/project.properties Wed Jan 24 10:49:48 2007 +0000
1.3 @@ -17,3 +17,4 @@
1.4 # Microsystems, Inc. All Rights Reserved.
1.5
1.6 javac.source=1.5
1.7 +javac.compilerargs=-Xlint:unchecked
2.1 --- a/bpel.search/nbproject/project.xml Mon Jan 15 14:44:19 2007 +0000
2.2 +++ b/bpel.search/nbproject/project.xml Wed Jan 24 10:49:48 2007 +0000
2.3 @@ -33,6 +33,14 @@
2.4 </run-dependency>
2.5 </dependency>
2.6 <dependency>
2.7 + <code-name-base>org.openide.awt</code-name-base>
2.8 + <build-prerequisite/>
2.9 + <compile-dependency/>
2.10 + <run-dependency>
2.11 + <specification-version>6.2</specification-version>
2.12 + </run-dependency>
2.13 + </dependency>
2.14 + <dependency>
2.15 <code-name-base>org.openide.dialogs</code-name-base>
2.16 <build-prerequisite/>
2.17 <compile-dependency/>
2.18 @@ -107,15 +115,6 @@
2.19 </run-dependency>
2.20 </dependency>
2.21 <dependency>
2.22 - <code-name-base>org.netbeans.modules.bpel.editors</code-name-base>
2.23 - <build-prerequisite/>
2.24 - <compile-dependency/>
2.25 - <run-dependency>
2.26 - <release-version>1</release-version>
2.27 - <specification-version>1.2</specification-version>
2.28 - </run-dependency>
2.29 - </dependency>
2.30 - <dependency>
2.31 <code-name-base>org.netbeans.modules.bpel.search.api</code-name-base>
2.32 <build-prerequisite/>
2.33 <compile-dependency/>
3.1 --- a/bpel.search/src/META-INF/services/org.netbeans.modules.bpel.search.spi.SearchEngine Mon Jan 15 14:44:19 2007 +0000
3.2 +++ b/bpel.search/src/META-INF/services/org.netbeans.modules.bpel.search.spi.SearchEngine Wed Jan 24 10:49:48 2007 +0000
3.3 @@ -1,1 +1,3 @@
3.4 org.netbeans.modules.bpel.search.impl.diagram.Engine
3.5 +org.netbeans.modules.bpel.search.impl.diagram.Construct
3.6 +org.netbeans.modules.bpel.search.impl.model.Engine
4.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/core/Manager.java Mon Jan 15 14:44:19 2007 +0000
4.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/core/Manager.java Wed Jan 24 10:49:48 2007 +0000
4.3 @@ -23,7 +23,7 @@
4.4 import java.util.List;
4.5 import javax.swing.JComponent;
4.6
4.7 -import org.netbeans.modules.print.api.PrintUtil;
4.8 +import static org.netbeans.modules.print.api.PrintUtil.*;
4.9 import org.netbeans.modules.bpel.search.api.SearchManager;
4.10 import org.netbeans.modules.bpel.search.api.SearchMatch;
4.11 import org.netbeans.modules.bpel.search.api.SearchPattern;
4.12 @@ -53,7 +53,7 @@
4.13 return null;
4.14 }
4.15 if (advanced) {
4.16 - return mySearch.getComponent(engines, source);
4.17 + return mySearch.getUIComponent(engines, source);
4.18 }
4.19 else {
4.20 return new Find(engines, source, parent);
4.21 @@ -80,14 +80,6 @@
4.22 return engines;
4.23 }
4.24
4.25 - private void out() {
4.26 - PrintUtil.out();
4.27 - }
4.28 -
4.29 - private void out(Object object) {
4.30 - PrintUtil.out(object);
4.31 - }
4.32 -
4.33 private Search mySearch;
4.34 private List<SearchEngine> myEngines;
4.35 }
5.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/diagram/Construct.java Mon Jan 15 14:44:19 2007 +0000
5.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/diagram/Construct.java Wed Jan 24 10:49:48 2007 +0000
5.3 @@ -18,20 +18,16 @@
5.4 */
5.5 package org.netbeans.modules.bpel.search.impl.diagram;
5.6
5.7 -import java.util.Iterator;
5.8 import java.util.List;
5.9 -
5.10 import org.w3c.dom.NamedNodeMap;
5.11 import org.w3c.dom.Node;
5.12 import org.openide.util.NbBundle;
5.13
5.14 import org.netbeans.modules.bpel.model.api.BpelEntity;
5.15 +import org.netbeans.modules.bpel.editors.api.Diagram;
5.16 +import org.netbeans.modules.bpel.editors.api.DiagramElement;
5.17
5.18 -import org.netbeans.modules.bpel.design.DesignView;
5.19 -import org.netbeans.modules.bpel.design.model.DiagramModel;
5.20 -import org.netbeans.modules.bpel.design.model.elements.VisualElement;
5.21 -import org.netbeans.modules.bpel.design.model.patterns.Pattern;
5.22 -
5.23 +import org.netbeans.modules.bpel.search.api.SearchException;
5.24 import org.netbeans.modules.bpel.search.api.SearchOption;
5.25
5.26 /**
5.27 @@ -41,47 +37,30 @@
5.28 public final class Construct extends Engine {
5.29
5.30 /**{@inheritDoc}*/
5.31 - public void search(SearchOption option) {
5.32 - DesignView view = (DesignView) option.getSource();
5.33 - myModel = view.getModel();
5.34 - Util.getDecorator(view).clearHighlighting();
5.35 + public void search(SearchOption option) throws SearchException {
5.36 + Diagram diagram = (Diagram) option.getSource();
5.37 + diagram.clearHighlighting();
5.38 //out();
5.39 fireSearchStarted(option);
5.40 - search(getRoot(myModel, option.useSelection()).getOMReference(), ""); // NOI18N
5.41 + search(diagram, option.useSelection());
5.42 fireSearchFinished(option);
5.43 }
5.44 +
5.45 + private void search(Diagram diagram, boolean useSelection) {
5.46 + List<DiagramElement> elements = diagram.getElements(useSelection);
5.47
5.48 - private void search(BpelEntity element, String indent) {
5.49 - if (element == null) {
5.50 - return;
5.51 - }
5.52 - process(element, indent);
5.53 - List<BpelEntity> children = element.getChildren();
5.54 -
5.55 - for (BpelEntity entity : children) {
5.56 - search(entity, indent + " "); // NOI18N
5.57 + for (DiagramElement element : elements) {
5.58 + BpelEntity entity = element.getBpelEntity();
5.59 +
5.60 + if (acceptsAttribute(entity) || acceptsComponent(entity)) {
5.61 +//out(indent + " add.");
5.62 + fireSearchFound(new Element(element));
5.63 + }
5.64 }
5.65 }
5.66 -
5.67 - private void process(BpelEntity element, String indent) {
5.68 - Pattern pattern = myModel.getPattern(element);
5.69 -
5.70 - if (pattern == null) {
5.71 - return;
5.72 - }
5.73 - Iterator<VisualElement> iterator = pattern.getElements().iterator();
5.74 -
5.75 - if ( !iterator.hasNext()) {
5.76 - return;
5.77 - }
5.78 - if (acceptsAttribute(element) || acceptsComponent(element)) {
5.79 -//out(indent + " add.");
5.80 - fireSearchFound(new Element(iterator.next()));
5.81 - }
5.82 - }
5.83 -
5.84 - private boolean acceptsAttribute(BpelEntity element) {
5.85 - NamedNodeMap attributes = element.getPeer().getAttributes();
5.86 +
5.87 + private boolean acceptsAttribute(BpelEntity entity) {
5.88 + NamedNodeMap attributes = entity.getPeer().getAttributes();
5.89
5.90 for (int i=0; i < attributes.getLength(); i++) {
5.91 Node attribute = attributes.item(i);
5.92 @@ -96,8 +75,8 @@
5.93 return false;
5.94 }
5.95
5.96 - private boolean acceptsComponent(BpelEntity element) {
5.97 - return accepts(element.getPeer().getTagName());
5.98 + private boolean acceptsComponent(BpelEntity entity) {
5.99 + return accepts(entity.getPeer().getTagName());
5.100 }
5.101
5.102 /**{@inheritDoc}*/
5.103 @@ -110,6 +89,4 @@
5.104 return NbBundle.getMessage(
5.105 Engine.class, "CTL_Construct_Short_Description"); // NOI18N
5.106 }
5.107 -
5.108 - private DiagramModel myModel;
5.109 }
6.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/diagram/Element.java Mon Jan 15 14:44:19 2007 +0000
6.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/diagram/Element.java Wed Jan 24 10:49:48 2007 +0000
6.3 @@ -18,11 +18,7 @@
6.4 */
6.5 package org.netbeans.modules.bpel.search.impl.diagram;
6.6
6.7 -import org.netbeans.modules.bpel.model.api.BpelEntity;
6.8 -import org.netbeans.modules.bpel.design.DesignView;
6.9 -import org.netbeans.modules.bpel.design.model.elements.VisualElement;
6.10 -import org.netbeans.modules.bpel.design.model.patterns.Pattern;
6.11 -
6.12 +import org.netbeans.modules.bpel.editors.api.DiagramElement;
6.13 import org.netbeans.modules.bpel.search.api.SearchElement;
6.14
6.15 /**
6.16 @@ -31,48 +27,32 @@
6.17 */
6.18 final class Element extends SearchElement.Adapter {
6.19
6.20 - Element(VisualElement element) {
6.21 + Element(DiagramElement element) {
6.22 super(element.getText(), element.getText(), null, null);
6.23 myElement = element;
6.24 - highlight(true);
6.25 + highlightOnDiagram(true);
6.26 }
6.27
6.28 + /**{@inheritDoc}*/
6.29 @Override
6.30 public void gotoSource()
6.31 {
6.32 -//out("goto source: " + this); // todo a
6.33 + myElement.gotoSource();
6.34 }
6.35
6.36 + /**{@inheritDoc}*/
6.37 @Override
6.38 - public void select()
6.39 + public void selectOnDiagram()
6.40 {
6.41 -//out("select: " + getText());
6.42 - Pattern pattern = myElement.getPattern();
6.43 - DesignView view = pattern.getModel().getView();
6.44 -
6.45 - // select
6.46 - view.getSelectionModel().setSelectedPattern(pattern);
6.47 -
6.48 - // glow
6.49 - getDecorator().select(getEntity());
6.50 -
6.51 - // scroll
6.52 - myElement.scrollTo();
6.53 + myElement.select();
6.54 }
6.55
6.56 + /**{@inheritDoc}*/
6.57 @Override
6.58 - public void highlight(boolean highlighted)
6.59 + public void highlightOnDiagram(boolean highlighted)
6.60 {
6.61 - getDecorator().highlight(getEntity(), highlighted);
6.62 + myElement.highlight(highlighted);
6.63 }
6.64
6.65 - private BpelEntity getEntity() {
6.66 - return myElement.getPattern().getOMReference();
6.67 - }
6.68 -
6.69 - private Decorator getDecorator() {
6.70 - return Util.getDecorator(myElement.getPattern().getModel().getView());
6.71 - }
6.72 -
6.73 - private VisualElement myElement;
6.74 + private DiagramElement myElement;
6.75 }
7.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/diagram/Engine.java Mon Jan 15 14:44:19 2007 +0000
7.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/diagram/Engine.java Wed Jan 24 10:49:48 2007 +0000
7.3 @@ -18,16 +18,13 @@
7.4 */
7.5 package org.netbeans.modules.bpel.search.impl.diagram;
7.6
7.7 -import java.util.Collection;
7.8 -
7.9 +import java.util.List;
7.10 import org.openide.util.NbBundle;
7.11
7.12 -import org.netbeans.modules.bpel.design.DesignView;
7.13 -import org.netbeans.modules.bpel.design.model.DiagramModel;
7.14 -import org.netbeans.modules.bpel.design.model.elements.VisualElement;
7.15 -import org.netbeans.modules.bpel.design.model.patterns.CompositePattern;
7.16 -import org.netbeans.modules.bpel.design.model.patterns.Pattern;
7.17 +import org.netbeans.modules.bpel.editors.api.Diagram;
7.18 +import org.netbeans.modules.bpel.editors.api.DiagramElement;
7.19
7.20 +import org.netbeans.modules.bpel.search.api.SearchException;
7.21 import org.netbeans.modules.bpel.search.api.SearchOption;
7.22 import org.netbeans.modules.bpel.search.spi.SearchEngine;
7.23
7.24 @@ -38,62 +35,32 @@
7.25 public class Engine extends SearchEngine.Adapter {
7.26
7.27 /**{@inheritDoc}*/
7.28 - public void search(SearchOption option) {
7.29 - DesignView view = (DesignView) option.getSource();
7.30 - DiagramModel model = view.getModel();
7.31 - Util.getDecorator(view).clearHighlighting();
7.32 + public void search(SearchOption option) throws SearchException {
7.33 + Diagram diagram = (Diagram) option.getSource();
7.34 + diagram.clearHighlighting();
7.35 //out();
7.36 fireSearchStarted(option);
7.37 - search(getRoot(model, option.useSelection()), ""); // NOI18N
7.38 + search(diagram, option.useSelection());
7.39 fireSearchFinished(option);
7.40 }
7.41
7.42 - protected Pattern getRoot(DiagramModel model, boolean useSelection) {
7.43 - if (useSelection) {
7.44 - return model.getView().getSelectionModel().getSelectedPattern();
7.45 - }
7.46 - return model.getRootPattern();
7.47 - }
7.48 + private void search(Diagram diagram, boolean useSelection) {
7.49 + List<DiagramElement> elements = diagram.getElements(useSelection);
7.50
7.51 - private void search(Pattern pattern, String indent) {
7.52 - if (pattern == null) {
7.53 - return;
7.54 - }
7.55 - search(pattern.getElements(), indent);
7.56 -
7.57 - if (pattern instanceof CompositePattern) {
7.58 - CompositePattern composite = (CompositePattern) pattern;
7.59 - search(composite.getBorder(), indent);
7.60 - Collection<Pattern> patterns = composite.getNestedPatterns();
7.61 -
7.62 - for (Pattern patern : patterns) {
7.63 - search(patern, indent + " "); // NOI18N
7.64 - }
7.65 - }
7.66 - }
7.67 -
7.68 - private void search(Collection<VisualElement> elements, String indent) {
7.69 - for (VisualElement element : elements) {
7.70 - search(element, indent);
7.71 - }
7.72 - }
7.73 -
7.74 - private void search(VisualElement element, String indent) {
7.75 - if (element == null) {
7.76 - return;
7.77 - }
7.78 - String text = element.getText();
7.79 + for (DiagramElement element : elements) {
7.80 + String text = element.getText();
7.81 //out(indent + " see: " + text);
7.82
7.83 - if (accepts(text)) {
7.84 + if (accepts(text)) {
7.85 //out(indent + " add.");
7.86 - fireSearchFound(new Element(element));
7.87 + fireSearchFound(new Element(element));
7.88 + }
7.89 }
7.90 }
7.91
7.92 /**{@inheritDoc}*/
7.93 public boolean accepts(Object source) {
7.94 - return source instanceof DesignView;
7.95 + return source instanceof Diagram;
7.96 }
7.97
7.98 /**{@inheritDoc}*/
8.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/model/Bundle.properties Mon Jan 15 14:44:19 2007 +0000
8.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/model/Bundle.properties Wed Jan 24 10:49:48 2007 +0000
8.3 @@ -19,3 +19,38 @@
8.4 # Engine
8.5 CTL_Engine_Display_Name=Name of bpel element
8.6 CTL_Engine_Short_Description=Searches bpel elements by given name and type
8.7 +
8.8 +# Target
8.9 +ANY_ELEMENT=Any Element
8.10 +ASSIGN=Assign
8.11 +CATCH=Catch
8.12 +CATCH_ALL=Catch All
8.13 +COMPENSATE=Compensate
8.14 +COPY=Copy
8.15 +CORRELATION=Correlation
8.16 +CORRELATION_SET=Correlation Set
8.17 +ELSE=Else
8.18 +ELSEIF=Else If
8.19 +EMPTY=Empty
8.20 +EXIT=Exit
8.21 +FAULT_HANDLERS=Fault Handlers
8.22 +FLOW=Flow
8.23 +FOREACH=For Each
8.24 +FROM=From
8.25 +IF=If
8.26 +IMPORT=Import
8.27 +INVOKE=Invoke
8.28 +MESSAGE_EXCHANGE=Message Exchange
8.29 +PARTNER_LINK=Partner Link
8.30 +PICK=Pick
8.31 +PROCESS=Process
8.32 +RECEIVE=Receive
8.33 +REPEAT_UNTIL=Repeat Until
8.34 +REPLY=Reply
8.35 +SCOPE=Scope
8.36 +SEQUENCE=Sequence
8.37 +THROW=Throw
8.38 +TO=To
8.39 +VARIABLE=Variable
8.40 +WAIT=Wait
8.41 +WHILE=While
9.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/model/Element.java Mon Jan 15 14:44:19 2007 +0000
9.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/model/Element.java Wed Jan 24 10:49:48 2007 +0000
9.3 @@ -20,7 +20,6 @@
9.4
9.5 import javax.swing.Icon;
9.6
9.7 -import org.netbeans.modules.bpel.editors.api.nodes.NodeType;
9.8 import org.netbeans.modules.bpel.editors.api.utils.Util;
9.9 import org.netbeans.modules.bpel.model.api.BpelEntity;
9.10 import org.netbeans.modules.bpel.model.api.NamedElement;
9.11 @@ -45,23 +44,16 @@
9.12
9.13 /**{@inheritDoc}*/
9.14 @Override
9.15 - public void select()
9.16 + public void gotoSource()
9.17 {
9.18 -//out("select: " + this); // todo a
9.19 + Util.goToSource(myElement);
9.20 }
9.21
9.22 /**{@inheritDoc}*/
9.23 @Override
9.24 - public void highlight(boolean highlighted)
9.25 + public void selectOnDiagram()
9.26 {
9.27 - // todo a
9.28 - }
9.29 -
9.30 - /**{@inheritDoc}*/
9.31 - @Override
9.32 - public void gotoSource()
9.33 - {
9.34 -//out("goto source: " + this); // todo a
9.35 + Util.goToDesign(myElement);
9.36 }
9.37
9.38 /**{@inheritDoc}*/
9.39 @@ -127,8 +119,7 @@
9.40 }
9.41
9.42 private static Icon getIcon(BpelEntity element) {
9.43 - NodeType node = Util.getBasicNodeType(element);
9.44 - return node.getIcon();
9.45 + return Util.getBasicNodeType(element).getIcon();
9.46 }
9.47
9.48 private BpelEntity myElement;
10.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/model/Engine.java Mon Jan 15 14:44:19 2007 +0000
10.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/model/Engine.java Wed Jan 24 10:49:48 2007 +0000
10.3 @@ -25,6 +25,8 @@
10.4 import org.netbeans.modules.bpel.model.api.BpelModel;
10.5 import org.netbeans.modules.bpel.model.api.NamedElement;
10.6
10.7 +import org.netbeans.modules.bpel.search.api.SearchException;
10.8 +import org.netbeans.modules.bpel.search.api.SearchMatch;
10.9 import org.netbeans.modules.bpel.search.api.SearchOption;
10.10 import org.netbeans.modules.bpel.search.spi.SearchEngine;
10.11
10.12 @@ -35,14 +37,21 @@
10.13 public final class Engine extends SearchEngine.Adapter {
10.14
10.15 /**{@inheritDoc}*/
10.16 - public void search(SearchOption option) {
10.17 + public void search(SearchOption option) throws SearchException {
10.18 BpelModel model = (BpelModel) option.getSource();
10.19 + myTarget = ((Target) option.getTarget()).getClazz();
10.20 + myOption = option;
10.21 //out();
10.22 fireSearchStarted(option);
10.23 search(model.getProcess(), ""); // NOI18N
10.24 fireSearchFinished(option);
10.25 }
10.26
10.27 + /**{@inheritDoc}*/
10.28 + public Object[] getTargets() {
10.29 + return Target.values();
10.30 + }
10.31 +
10.32 private void search(BpelEntity element, String indent) {
10.33 if (element == null) {
10.34 return;
10.35 @@ -56,19 +65,47 @@
10.36 }
10.37
10.38 private void process(BpelEntity element, String indent) {
10.39 - if ( !(element instanceof NamedElement)) {
10.40 - return;
10.41 - }
10.42 - NamedElement named = (NamedElement) element;
10.43 - String text = named.getName();
10.44 -//out(indent + " see: " + text);
10.45 -
10.46 - if (accepts(text)) {
10.47 +//out(indent + " see: " + element);
10.48 + if (checkTarget(element) && checkName(element)) {
10.49 //out(indent + " add.");
10.50 fireSearchFound(new Element(element));
10.51 }
10.52 }
10.53
10.54 + private boolean checkTarget(Object object) {
10.55 + if (myTarget == null) {
10.56 + return true;
10.57 + }
10.58 + return myTarget.isAssignableFrom(object.getClass());
10.59 + }
10.60 +
10.61 + private boolean checkName(BpelEntity element) {
10.62 + if (anyName()) {
10.63 + return true;
10.64 + }
10.65 + if ( !(element instanceof NamedElement)) {
10.66 + return false;
10.67 + }
10.68 + NamedElement named = (NamedElement) element;
10.69 + return accepts(named.getName());
10.70 + }
10.71 +
10.72 + private boolean anyName() {
10.73 + String text = myOption.getText();
10.74 + SearchMatch match = myOption.getSearchMatch();
10.75 +
10.76 + if (match == SearchMatch.PATTERN_MATCH && text.equals("*")) { // NOI18N
10.77 + return true;
10.78 + }
10.79 + if (match == SearchMatch.REGULAR_EXPRESSION && text.equals("\\.*")) { // NOI18N
10.80 + return true;
10.81 + }
10.82 + if (match == null && text.equals("")) { // NOI18N
10.83 + return true;
10.84 + }
10.85 + return false;
10.86 + }
10.87 +
10.88 /**{@inheritDoc}*/
10.89 public boolean accepts(Object source) {
10.90 return source instanceof BpelModel;
10.91 @@ -84,4 +121,7 @@
10.92 return NbBundle.getMessage(
10.93 Engine.class, "CTL_Engine_Short_Description"); // NOI18N
10.94 }
10.95 +
10.96 + private SearchOption myOption;
10.97 + private Class<? extends BpelEntity> myTarget;
10.98 }
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/Export.java Wed Jan 24 10:49:48 2007 +0000
11.3 @@ -0,0 +1,328 @@
11.4 +/*
11.5 + * The contents of this file are subject to the terms of the Common Development
11.6 + * and Distribution License (the License). You may not use this file except in
11.7 + * compliance with the License.
11.8 + *
11.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
11.10 + * or http://www.netbeans.org/cddl.txt.
11.11 + *
11.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
11.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
11.14 + * If applicable, add the following below the CDDL Header, with the fields
11.15 + * enclosed by brackets [] replaced by your own identifying information:
11.16 + * "Portions Copyrighted [year] [name of copyright owner]"
11.17 + *
11.18 + * The Original Software is NetBeans. The Initial Developer of the Original
11.19 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11.20 + * Microsystems, Inc. All Rights Reserved.
11.21 + */
11.22 +package org.netbeans.modules.bpel.search.impl.ui;
11.23 +
11.24 +import java.awt.Dimension;
11.25 +import java.awt.GridBagLayout;
11.26 +import java.awt.GridBagConstraints;
11.27 +import java.awt.Insets;
11.28 +import java.awt.event.ActionEvent;
11.29 +import java.io.File;
11.30 +import java.io.FileOutputStream;
11.31 +import java.io.IOException;
11.32 +import java.net.MalformedURLException;
11.33 +import java.util.ArrayList;
11.34 +import java.util.List;
11.35 +import java.util.StringTokenizer;
11.36 +
11.37 +import javax.swing.AbstractAction;
11.38 +import javax.swing.JButton;
11.39 +import javax.swing.JCheckBox;
11.40 +import javax.swing.JFileChooser;
11.41 +import javax.swing.JLabel;
11.42 +import javax.swing.JPanel;
11.43 +import javax.swing.JScrollPane;
11.44 +import javax.swing.JTextArea;
11.45 +import javax.swing.JTextField;
11.46 +import javax.swing.filechooser.FileFilter;
11.47 +
11.48 +import org.openide.DialogDescriptor;
11.49 +import org.openide.ErrorManager;
11.50 +import org.openide.awt.HtmlBrowser;
11.51 +import static org.netbeans.modules.print.api.PrintUtil.*;
11.52 +import org.netbeans.modules.print.api.PrintUtil.Dialog;
11.53 +
11.54 +/**
11.55 + * @author Vladimir Yaroslavskiy
11.56 + * @version 2006.12.21
11.57 + */
11.58 +class Export extends Dialog {
11.59 +
11.60 + void show(List<List<String>> descriptions, String title) {
11.61 + myDescriptions = descriptions;
11.62 + myTitle = title;
11.63 + show();
11.64 + }
11.65 +
11.66 + @Override
11.67 + protected JPanel createMainPanel()
11.68 + {
11.69 + JPanel panel = new JPanel(new GridBagLayout());
11.70 + GridBagConstraints c = new GridBagConstraints();
11.71 + c.anchor = GridBagConstraints.NORTHWEST;
11.72 + c.insets = new Insets(MEDIUM_INSET, TINY_INSET, TINY_INSET, TINY_INSET);
11.73 +
11.74 + // file name
11.75 + panel.add(createLabel("LBL_File_Name"), c); // NOI18N
11.76 +
11.77 + c.gridy++;
11.78 + c.weightx = 1.0;
11.79 + c.insets = new Insets(MEDIUM_INSET, TINY_INSET, TINY_INSET, 0);
11.80 + c.fill = GridBagConstraints.HORIZONTAL;
11.81 + myFileName = new JTextField(TEXT_WIDTH);
11.82 + myFileName.setText(getOutFolder(RESULT)); // NOI18N
11.83 + panel.add(myFileName, c);
11.84 +
11.85 + c.weightx = 0.0;
11.86 + c.insets = new Insets(MEDIUM_INSET, 0, TINY_INSET, TINY_INSET);
11.87 + c.fill = GridBagConstraints.NONE;
11.88 + JButton button = createButton(
11.89 + "TLT_Browse", // NOI18N
11.90 + new AbstractAction(getMessage("LBL_Browse")) { // NOI18N
11.91 + public void actionPerformed(ActionEvent event) {
11.92 + selectFile();
11.93 + }
11.94 + }
11.95 + );
11.96 + Dimension dimension = myFileName.getPreferredSize();
11.97 + dimension.width = dimension.height;
11.98 + button.setPreferredSize(dimension);
11.99 + button.setMinimumSize(dimension);
11.100 + panel.add(button, c);
11.101 +
11.102 + // description
11.103 + c.gridy++;
11.104 + c.insets = new Insets(TINY_INSET, TINY_INSET, TINY_INSET, MEDIUM_INSET);
11.105 + panel.add(createLabel("LBL_Description"), c); // NOI18N
11.106 +
11.107 + c.insets = new Insets(TINY_INSET, TINY_INSET, TINY_INSET, TINY_INSET);
11.108 + c.weightx = 1.0;
11.109 + c.weighty = 1.0;
11.110 + c.gridwidth = 2;
11.111 + c.fill = GridBagConstraints.BOTH;
11.112 + myTextArea = new JTextArea(TEXT_HEIGHT, TEXT_WIDTH);
11.113 + JScrollPane scrollPanel = new JScrollPane(myTextArea);
11.114 + panel.add(scrollPanel, c);
11.115 +
11.116 + // []
11.117 + c.gridy++;
11.118 + c.weightx = 0.0;
11.119 + c.weighty = 0.0;
11.120 + c.gridwidth = 1;
11.121 + panel.add(new JLabel(), c);
11.122 +
11.123 + // open in browser
11.124 + c.gridwidth = 2;
11.125 + c.insets = new Insets(TINY_INSET, 0, TINY_INSET, TINY_INSET);
11.126 + c.fill = GridBagConstraints.NONE;
11.127 + myRunBrowser = createCheckBox(
11.128 + "LBL_Open_in_Browser", // NOI18N
11.129 + new AbstractAction(getMessage("LBL_Open_in_Browser")) { // NOI18N
11.130 + public void actionPerformed(ActionEvent event) {}
11.131 + }
11.132 + );
11.133 + myRunBrowser.setSelected(true);
11.134 + panel.add(myRunBrowser, c);
11.135 +
11.136 + return panel;
11.137 + }
11.138 +
11.139 + private void checkFolder(File folder) {
11.140 + if (folder == null || folder.exists()) {
11.141 + return;
11.142 + }
11.143 + checkFolder(folder.getParentFile());
11.144 + folder.mkdir();
11.145 + }
11.146 +
11.147 + private void createFile(String name) {
11.148 + File file = new File(name);
11.149 +
11.150 + if (file.exists()) {
11.151 + if (showWarning("LBL_File_Exists", name)) { // NOI18N
11.152 + exportFile(file);
11.153 + }
11.154 + else {
11.155 + show();
11.156 + }
11.157 + }
11.158 + else {
11.159 + exportFile(file);
11.160 + }
11.161 + }
11.162 +
11.163 + private void selectFile() {
11.164 + JFileChooser chooser = new JFileChooser();
11.165 + chooser.setFileFilter(new FileFilter() {
11.166 + public boolean accept(File file) {
11.167 + return
11.168 + file.isFile() && file.getName().endsWith(HTML_EXT) ||
11.169 + file.isDirectory();
11.170 + }
11.171 + public String getDescription() {
11.172 + return getMessage("LBL_HTML_File_Type"); // NOI18N
11.173 + }
11.174 + });
11.175 + chooser.setSelectedFile(new File(myFileName.getText()));
11.176 +
11.177 + if (chooser.showOpenDialog(getUIComponent()) == JFileChooser.APPROVE_OPTION) {
11.178 + myFileName.setText(chooser.getSelectedFile().getAbsolutePath());
11.179 + }
11.180 + }
11.181 +
11.182 + private void exportFile(File file) {
11.183 + List<String> text = getText();
11.184 +
11.185 + // create html
11.186 + StringBuffer html = new StringBuffer();
11.187 + html.append("<html><body>" + LS); // NOI18N
11.188 + html.append("<h3>" + getMessage("LBL_Search_Results") + // NOI18N
11.189 + "</h3>" + LS + LS); // NOI18N
11.190 +
11.191 + if (myTitle != null) {
11.192 + html.append(processBrackets(myTitle) + LS + LS);
11.193 + }
11.194 + if (text.size() > 0) {
11.195 + html.append("<p><b>" + // NOI18N
11.196 + getMessage("LBL_Description") + "</b>"); // NOI18N
11.197 +
11.198 + for (String item : text) {
11.199 + html.append(item + LS);
11.200 + }
11.201 + }
11.202 + int count = 1;
11.203 + html.append(LS + "<p><table border=1>" + LS); // NOI18N
11.204 +
11.205 + for (List<String> description : myDescriptions) {
11.206 + if (description == null) {
11.207 + html.append("</table>" + LS); // NOI18N
11.208 + html.append(LS + "<p><table border=1>" + LS); // NOI18N
11.209 + count = 1;
11.210 + continue;
11.211 + }
11.212 + html.append("<tr><td>" + (count++) + "</td>"); // NOI18N
11.213 +
11.214 + for (String item : description) {
11.215 + html.append(" <td>"); // NOI18N
11.216 + html.append(processBrackets(item));
11.217 + html.append("</td>"); // NOI18N
11.218 + }
11.219 + html.append("</tr>" + LS); // NOI18N
11.220 + }
11.221 + html.append("</table>" + LS + LS); // NOI18N
11.222 + html.append("</body></html>" + LS); // NOI18N
11.223 +
11.224 + // export to file
11.225 + try {
11.226 + FileOutputStream outputStream = new FileOutputStream(file);
11.227 + outputStream.write(html.toString().getBytes());
11.228 + outputStream.close();
11.229 + }
11.230 + catch (IOException e) {
11.231 + printError("LBL_Cannot_Write_to_File", file.getAbsolutePath()); // NOI18N
11.232 + show();
11.233 + return;
11.234 + }
11.235 + if (myRunBrowser.isSelected()) {
11.236 + try {
11.237 + HtmlBrowser.URLDisplayer.getDefault().showURL(file.toURI().toURL());
11.238 + }
11.239 + catch (MalformedURLException e) {
11.240 + ErrorManager.getDefault().notify(e);
11.241 + }
11.242 + }
11.243 + }
11.244 +
11.245 + private List<String> getText() {
11.246 + List<String> text = new ArrayList<String>();
11.247 + StringTokenizer stk = new StringTokenizer(myTextArea.getText(), LS);
11.248 +
11.249 + while (stk.hasMoreTokens()) {
11.250 + text.add(stk.nextToken());
11.251 + }
11.252 + return text;
11.253 + }
11.254 +
11.255 + @Override
11.256 + protected DialogDescriptor createDescriptor()
11.257 + {
11.258 + myDescriptor = new DialogDescriptor(
11.259 + getPanel(),
11.260 + getMessage("LBL_Export_Title") // NOI18N
11.261 + );
11.262 + return myDescriptor;
11.263 + }
11.264 +
11.265 + private String getOutFolder(String file) {
11.266 + return UH + FS + OF + FS + file;
11.267 + }
11.268 +
11.269 + @Override
11.270 + protected void opened()
11.271 + {
11.272 + myFileName.requestFocus();
11.273 + }
11.274 +
11.275 + @Override
11.276 + protected void closed()
11.277 + {
11.278 + if (myDescriptor.getValue() != DialogDescriptor.OK_OPTION) {
11.279 + return;
11.280 + }
11.281 + String name = myFileName.getText().toLowerCase();
11.282 +
11.283 + if ( !(name.endsWith(HTM_EXT) || name.endsWith(HTML_EXT))) {
11.284 + name += HTML_EXT;
11.285 + }
11.286 + checkFolder(new File(name).getParentFile());
11.287 + createFile(name);
11.288 + }
11.289 +
11.290 + private String processBrackets(String value) {
11.291 + return processLBrackets(processRBrackets(value));
11.292 + }
11.293 +
11.294 + private String processBrackets(String value, String text, String replace) {
11.295 + if (value == null) {
11.296 + return null;
11.297 + }
11.298 + int index = value.indexOf(text);
11.299 +
11.300 + if (index == -1) {
11.301 + return value;
11.302 + }
11.303 + return
11.304 + value.substring(0, index) +
11.305 + replace +
11.306 + processBrackets(value.substring(index + 1), text, replace);
11.307 + }
11.308 +
11.309 + private String processLBrackets(String value) {
11.310 + return processBrackets(value, "<", "<"); // NOI18N
11.311 + }
11.312 +
11.313 + private String processRBrackets(String value) {
11.314 + return processBrackets(value, ">", ">"); // NOI18N
11.315 + }
11.316 +
11.317 + private String myTitle;
11.318 + private JTextArea myTextArea;
11.319 + private JTextField myFileName;
11.320 + private JCheckBox myRunBrowser;
11.321 + private DialogDescriptor myDescriptor;
11.322 + private List<List<String>> myDescriptions;
11.323 +
11.324 + private static final String OF = "out"; // NOI18N
11.325 + private static final String HTM_EXT = ".htm"; // NOI18N
11.326 + private static final String HTML_EXT = ".html"; // NOI18N
11.327 + private static final String RESULT = "result.html"; // NOI18N
11.328 +
11.329 + private static final int TEXT_HEIGHT = 5;
11.330 + private static final int TEXT_WIDTH = 30;
11.331 +}
12.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/Find.java Mon Jan 15 14:44:19 2007 +0000
12.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/Find.java Wed Jan 24 10:49:48 2007 +0000
12.3 @@ -37,9 +37,10 @@
12.4 import org.netbeans.modules.xml.xam.ui.search.SearchProvider;
12.5 import org.netbeans.modules.xml.xam.ui.search.Query;
12.6
12.7 -import org.netbeans.modules.print.api.PrintUtil;
12.8 +import static org.netbeans.modules.print.api.PrintUtil.*;
12.9 import org.netbeans.modules.bpel.search.api.SearchElement;
12.10 import org.netbeans.modules.bpel.search.api.SearchEvent;
12.11 +import org.netbeans.modules.bpel.search.api.SearchException;
12.12 import org.netbeans.modules.bpel.search.api.SearchOption;
12.13 import org.netbeans.modules.bpel.search.api.SearchMatch;
12.14 import org.netbeans.modules.bpel.search.spi.SearchEngine;
12.15 @@ -71,7 +72,7 @@
12.16 return;
12.17 }
12.18 for (Object element : myElements) {
12.19 - ((SearchElement) element).highlight(false);
12.20 + ((SearchElement) element).highlightOnDiagram(false);
12.21 }
12.22 myElements = null;
12.23 }
12.24 @@ -83,8 +84,7 @@
12.25 if ( !(object instanceof SearchElement)) {
12.26 return;
12.27 }
12.28 - SearchElement element = (SearchElement) object;
12.29 - element.select();
12.30 + ((SearchElement) object).selectOnDiagram();
12.31 }
12.32
12.33 private void bindAction(JComponent parent) {
12.34 @@ -92,7 +92,7 @@
12.35 Object mapKey = findAction.getActionMapKey();
12.36 parent.getActionMap().put(mapKey, new AbstractAction () {
12.37 public void actionPerformed(ActionEvent event) {
12.38 - setVisible( !isVisible());
12.39 + setVisible(true);
12.40 }
12.41 });
12.42 InputMap keys =
12.43 @@ -105,14 +105,6 @@
12.44 keys.put(key, mapKey);
12.45 }
12.46
12.47 - private void out() {
12.48 - PrintUtil.out();
12.49 - }
12.50 -
12.51 - private void out(Object object) {
12.52 - PrintUtil.out(object);
12.53 - }
12.54 -
12.55 // ---------------------------------------------------------------------
12.56 private final class Provider implements SearchProvider, SearchListener {
12.57
12.58 @@ -134,27 +126,44 @@
12.59 return NbBundle.getMessage(Provider.class, "CTL_Input_Description"); // NOI18N
12.60 }
12.61
12.62 - public List<Object> search(Query query) {
12.63 - String text = query.getQuery();
12.64 + public List<Object> search(Query query)
12.65 + throws org.netbeans.modules.xml.xam.ui.search.SearchException
12.66 + {
12.67 + SearchMatch match = getMatch(query);
12.68 + String text = getText(query, match);
12.69
12.70 SearchOption option = new SearchOption.Adapter(
12.71 text,
12.72 mySource,
12.73 - query.isRegularExpression() ?
12.74 - SearchMatch.REGULAR_EXPRESSION : getMatch(text),
12.75 + null, // target
12.76 + match,
12.77 false, // case sensitive
12.78 query.useSelected());
12.79
12.80 - mySearchEngine.search(option);
12.81 -
12.82 + try {
12.83 + mySearchEngine.search(option);
12.84 + }
12.85 + catch (SearchException e) {
12.86 + throw new org.netbeans.modules.xml.xam.ui.search.SearchException(
12.87 + e.getMessage(), e);
12.88 + }
12.89 return myElements;
12.90 }
12.91
12.92 - private SearchMatch getMatch(String text) {
12.93 - if (text.contains("*") || text.contains("?")) { // NOI18N
12.94 - return SearchMatch.PATTERN_MATCH;
12.95 + private SearchMatch getMatch(Query query) {
12.96 + if (query.isRegularExpression()) {
12.97 + return SearchMatch.REGULAR_EXPRESSION;
12.98 }
12.99 - return null;
12.100 + return SearchMatch.PATTERN_MATCH;
12.101 + }
12.102 +
12.103 + private String getText(Query query, SearchMatch match) {
12.104 + String text = query.getQuery();
12.105 +
12.106 + if (match == SearchMatch.PATTERN_MATCH) {
12.107 + return "*" + text + "*"; // NOI18N
12.108 + }
12.109 + return text;
12.110 }
12.111
12.112 public void searchStarted(SearchEvent event) {
13.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/Search.java Mon Jan 15 14:44:19 2007 +0000
13.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/Search.java Wed Jan 24 10:49:48 2007 +0000
13.3 @@ -18,40 +18,26 @@
13.4 */
13.5 package org.netbeans.modules.bpel.search.impl.ui;
13.6
13.7 -import java.awt.Color;
13.8 import java.awt.Component;
13.9 -import java.awt.Dimension;
13.10 import java.awt.GridBagConstraints;
13.11 import java.awt.GridBagLayout;
13.12 import java.awt.Insets;
13.13 -import java.awt.Point;
13.14 -import java.awt.Toolkit;
13.15 import java.awt.event.ActionEvent;
13.16 import java.awt.event.ActionListener;
13.17 -import java.awt.event.KeyAdapter;
13.18 -import java.awt.event.KeyEvent;
13.19 -import java.awt.event.MouseAdapter;
13.20 -import java.awt.event.MouseEvent;
13.21 -import java.awt.event.MouseWheelEvent;
13.22 -import java.awt.event.MouseWheelListener;
13.23 -import java.util.ArrayList;
13.24 -import java.util.Date;
13.25 import java.util.List;
13.26
13.27 import javax.swing.AbstractAction;
13.28 import javax.swing.JButton;
13.29 +import javax.swing.JCheckBox;
13.30 +import javax.swing.JComboBox;
13.31 import javax.swing.JComponent;
13.32 +import javax.swing.JLabel;
13.33 import javax.swing.JPanel;
13.34 -import javax.swing.JTextField;
13.35 -import javax.swing.JToggleButton;
13.36 -import javax.swing.JScrollPane;
13.37 -import javax.swing.JViewport;
13.38 -import javax.swing.ScrollPaneConstants;
13.39 -import javax.swing.SwingUtilities;
13.40
13.41 import org.openide.DialogDescriptor;
13.42 +import org.netbeans.modules.print.api.PrintUtil.Dialog;
13.43
13.44 -import org.netbeans.modules.print.api.PrintUtil.Dialog;
13.45 +import org.netbeans.modules.bpel.search.api.SearchException;
13.46 import org.netbeans.modules.bpel.search.api.SearchOption;
13.47 import org.netbeans.modules.bpel.search.api.SearchMatch;
13.48 import org.netbeans.modules.bpel.search.spi.SearchEngine;
13.49 @@ -64,155 +50,185 @@
13.50 public final class Search extends Dialog {
13.51
13.52 /**{@inheritDoc}*/
13.53 - public Component getComponent(List<SearchEngine> engines, Object source) {
13.54 + public Component getUIComponent(List<SearchEngine> engines, Object source) {
13.55 mySource = source;
13.56 myTree = new Tree();
13.57 mySearchEngine = engines.get(0);
13.58 mySearchEngine.addSearchListener(myTree);
13.59 + // todo a? progress
13.60 show();
13.61 - return getComponent();
13.62 + return getUIComponent();
13.63 }
13.64
13.65 - private JPanel createMainPanel() {
13.66 -//out("Create Main panel");
13.67 + @Override
13.68 + protected JPanel createMainPanel()
13.69 + {
13.70 JPanel panel = new JPanel(new GridBagLayout());
13.71 GridBagConstraints c = new GridBagConstraints();
13.72 - c.gridy = 1;
13.73 + c.anchor = GridBagConstraints.NORTHWEST;
13.74 + c.fill = GridBagConstraints.HORIZONTAL;
13.75 + c.weightx = 1.0;
13.76 + c.gridx = 0;
13.77
13.78 - // text field
13.79 - myText = new JTextField("*"); // todo r
13.80 - // todo m
13.81 - int width = TEXT_WIDTH;
13.82 - int height = myText.getPreferredSize().height;
13.83 - myText.setPreferredSize(new Dimension(width, height));
13.84 - myText.setMinimumSize(new Dimension(width, height));
13.85 - panel.add(myText, c);
13.86 + // text
13.87 + panel.add(createTextPanel(), c);
13.88
13.89 -// c.gridy++;
13.90 + // option
13.91 + panel.add(getSeparator("LBL_Options"), c); // NOI18N
13.92 + panel.add(createOptionPanel(), c);
13.93
13.94 return panel;
13.95 }
13.96
13.97 - private JComponent createNavigatePanel() {
13.98 + private JComponent createTextPanel() {
13.99 JPanel panel = new JPanel(new GridBagLayout());
13.100 GridBagConstraints c = new GridBagConstraints();
13.101 + c.anchor = GridBagConstraints.WEST;
13.102
13.103 - // first
13.104 - panel = new JPanel(new GridBagLayout());
13.105 - c.insets = new Insets(TINY_INSET, TINY_INSET, TINY_INSET, TINY_INSET);
13.106 -/*
13.107 - myFirst = (JButton) createButton(new JButton(),
13.108 - "TLT_First", // NOI18N
13.109 - new AbstractAction(null, Util.getIcon("first")) { // NOI18N
13.110 - public void actionPerformed(ActionEvent event) {
13.111 - first();
13.112 - }
13.113 + // text
13.114 + c.gridy++;
13.115 + c.insets = new Insets(TINY_INSET, 0, TINY_INSET, 0);
13.116 + JLabel label = createLabel("LBL_Name"); // NOI18N
13.117 + panel.add(label, c);
13.118 +
13.119 + c.insets = new Insets(TINY_INSET, SMALL_INSET, TINY_INSET, 0);
13.120 + c.fill = GridBagConstraints.HORIZONTAL;
13.121 + c.weightx = 1.0;
13.122 + myName = new TextField(ASTERISK);
13.123 + myName.addActionListener(new ActionListener() {
13.124 + public void actionPerformed(ActionEvent event) {
13.125 + updateButton();
13.126 }
13.127 - );
13.128 -*/
13.129 - panel.add(myFirst, c);
13.130 + });
13.131 + setWidth(myName.getUIComponent(), TEXT_WIDTH);
13.132 + label.setLabelFor(myName.getUIComponent());
13.133 + panel.add(myName.getUIComponent(), c);
13.134
13.135 - // previous
13.136 - panel.add(myPrevious, c);
13.137 + // type
13.138 + c.gridy++;
13.139 + c.fill = GridBagConstraints.NONE;
13.140 + c.weightx = 0.0;
13.141 + c.insets = new Insets(TINY_INSET, 0, TINY_INSET, 0);
13.142 + label = createLabel("LBL_Type"); // NOI18N
13.143 + panel.add(label, c);
13.144
13.145 -// int width = (int)Math.round(myPrevious.getPreferredSize().width/PREVIEW_FACTOR);
13.146 -// int height = myPrevious.getPreferredSize().height;
13.147 -// myGoto.setPreferredSize(new Dimension(width, height));
13.148 -// myGoto.setMinimumSize(new Dimension(width, height));
13.149 -
13.150 -// myGoto.setHorizontalAlignment(JTextField.CENTER);
13.151 -// myGoto.setToolTipText(getMessage("TLT_Goto")); // NOI18N
13.152 -// myGoto.addActionListener(new ActionListener() {
13.153 -// public void actionPerformed(ActionEvent event) {
13.154 -// goTo();
13.155 -// }
13.156 -// });
13.157 -// panel.add(myGoto, c);
13.158 -
13.159 - // next
13.160 - panel.add(myNext, c);
13.161 -
13.162 - // last
13.163 - panel.add(myLast, c);
13.164 + c.fill = GridBagConstraints.HORIZONTAL;
13.165 + c.insets = new Insets(TINY_INSET, SMALL_INSET, TINY_INSET, 0);
13.166 + c.weightx = 1.0;
13.167 + myTarget = new JComboBox(mySearchEngine.getTargets());
13.168 + label.setLabelFor(myTarget);
13.169 + panel.add(myTarget, c);
13.170
13.171 return panel;
13.172 }
13.173
13.174 - private JComponent createScalePanel() {
13.175 -//out("Create scale panel");
13.176 + private JComponent createOptionPanel() {
13.177 JPanel panel = new JPanel(new GridBagLayout());
13.178 GridBagConstraints c = new GridBagConstraints();
13.179 + c.anchor = GridBagConstraints.NORTHWEST;
13.180 + c.insets = new Insets(0, SMALL_INSET, 0, 0);
13.181 + c.weightx = 1.0;
13.182
13.183 - // fit to window
13.184 - c.insets = new Insets(TINY_INSET, MEDIUM_INSET, TINY_INSET, TINY_INSET);
13.185 - panel.add(myFit, c);
13.186 + c.gridy++;
13.187 + myMatchCase = createCheckBox(
13.188 + "LBL_Match_Case", // NOI18N
13.189 + new AbstractAction(getMessage("LBL_Match_Case")) { // NOI18N
13.190 + public void actionPerformed(ActionEvent event) {}
13.191 + }
13.192 + );
13.193 + panel.add(myMatchCase, c);
13.194
13.195 - // decrease
13.196 - panel.add(myDecrease, c);
13.197 + c.gridy++;
13.198 + myPatternMatch = createCheckBox(
13.199 + "LBL_Pattern_Match", // NOI18N
13.200 + new AbstractAction(getMessage("LBL_Pattern_Match")) { // NOI18N
13.201 + public void actionPerformed(ActionEvent event) {
13.202 + exclusion(myPatternMatch, myRegularExpression);
13.203 + }
13.204 + }
13.205 + );
13.206 + myPatternMatch.setSelected(true);
13.207 + myPatternMatch.setEnabled(true);
13.208 + panel.add(myPatternMatch, c);
13.209
13.210 - // increase
13.211 - panel.add(myIncrease, c);
13.212 + c.gridy++;
13.213 + myRegularExpression = createCheckBox(
13.214 + "LBL_Regular_Expression", // NOI18N
13.215 + new AbstractAction(getMessage("LBL_Regular_Expression")) { // NOI18N
13.216 + public void actionPerformed(ActionEvent event) {
13.217 + exclusion(myRegularExpression, myPatternMatch);
13.218 + }
13.219 + }
13.220 + );
13.221 + myRegularExpression.setSelected(false);
13.222 + myRegularExpression.setEnabled(false);
13.223 + panel.add(myRegularExpression, c);
13.224
13.225 return panel;
13.226 }
13.227
13.228 - private JComponent createScrollPanel() {
13.229 -//out("Create scroll panel");
13.230 - GridBagConstraints c = new GridBagConstraints();
13.231 + private void exclusion(JCheckBox checkBox1, JCheckBox checkBox2) {
13.232 + checkBox1.setEnabled( !checkBox2.isSelected());
13.233
13.234 - // papers
13.235 -// myPaperPanel = new JPanel(new GridBagLayout());
13.236 -// myPaperPanel.setBackground(Color.lightGray);
13.237 - JPanel panel = new JPanel(new GridBagLayout());
13.238 + if (checkBox2.isSelected()) {
13.239 + checkBox1.setSelected(false);
13.240 + }
13.241 + checkBox2.setEnabled( !checkBox1.isSelected());
13.242
13.243 - c.gridy = 1;
13.244 - c.anchor = GridBagConstraints.NORTHWEST;
13.245 - c.weightx = 1.0;
13.246 - c.weighty = 1.0;
13.247 - c.insets = new Insets(0, 0, 0, 0);
13.248 - panel.setBackground(Color.lightGray);
13.249 -// panel.add(myPaperPanel, c);
13.250 - //panel.setBorder(new javax.swing.border.LineBorder(java.awt.Color.yellow));
13.251 - //optionPanel.setBorder(new javax.swing.border.LineBorder(java.awt.Color.green));
13.252 - //myPaperPanel.setBorder(new javax.swing.border.LineBorder(java.awt.Color.green));
13.253 + if (checkBox1.isSelected()) {
13.254 + checkBox2.setSelected(false);
13.255 + }
13.256 + }
13.257
13.258 - // scroll
13.259 - c.fill = GridBagConstraints.BOTH;
13.260 -
13.261 + private SearchMatch getMatch() {
13.262 + if (myPatternMatch.isSelected()) {
13.263 + return SearchMatch.PATTERN_MATCH;
13.264 + }
13.265 + if (myRegularExpression.isSelected()) {
13.266 + return SearchMatch.REGULAR_EXPRESSION;
13.267 + }
13.268 return null;
13.269 }
13.270
13.271 + private void updateButton() {
13.272 +// String text = myName.getText();
13.273 +// boolean enabled = text != null && text.length() > 0;
13.274 +// mySearchButton.setEnabled(enabled);
13.275 +// todo r
13.276 + }
13.277 +
13.278 private void search() {
13.279 -//out("text: '" + myText.getText() + "'");
13.280 + myDescriptor.setClosingOptions(
13.281 + new Object[] {
13.282 + mySearchButton,
13.283 + DialogDescriptor.CANCEL_OPTION
13.284 + }
13.285 + );
13.286 SearchOption option = new SearchOption.Adapter(
13.287 - myText.getText(),
13.288 + myName.getText(),
13.289 mySource,
13.290 - SearchMatch.PATTERN_MATCH, // todo m
13.291 - false, // case sensitive
13.292 + myTarget.getSelectedItem(),
13.293 + getMatch(),
13.294 + myMatchCase.isSelected(),
13.295 false); // use selection
13.296
13.297 - mySearchEngine.search(option);
13.298 - }
13.299 -
13.300 - private void updateButtons() {
13.301 -/*
13.302 - myGoto.setText (getPaper(myPaperNumber));
13.303 - myFirst.setEnabled (myPaperNumber > 1);
13.304 - myPrevious.setEnabled (myPaperNumber > 1);
13.305 - myGoto.setEnabled (enabled);
13.306 - myToggle.setEnabled (enabled);
13.307 - myFit.setEnabled (enabled);
13.308 - myIncrease.setEnabled (enabled);
13.309 - myDecrease.setEnabled (enabled);
13.310 - myPrnBtn.setEnabled (enabled);
13.311 - myOptBtn.setEnabled (enabled);
13.312 -*/
13.313 -// disable Search button if name is empty
13.314 + try {
13.315 + mySearchEngine.search(option);
13.316 + }
13.317 + catch (SearchException e) {
13.318 + myDescriptor.setClosingOptions(
13.319 + new Object[] {
13.320 + DialogDescriptor.CANCEL_OPTION
13.321 + }
13.322 + );
13.323 + printError("ERR_Pattern_Error", e.getMessage()); // NOI18N
13.324 + }
13.325 }
13.326
13.327 @Override
13.328 protected void closed()
13.329 {
13.330 + myName.save();
13.331 mySearchEngine.removeSearchListener(myTree);
13.332 mySearchEngine = null;
13.333 mySource = null;
13.334 @@ -220,38 +236,35 @@
13.335 }
13.336
13.337 @Override
13.338 - protected void opened()
13.339 - {
13.340 -// myScrollPanel.requestFocus();
13.341 - }
13.342 -
13.343 - @Override
13.344 - protected DialogDescriptor getDescriptor()
13.345 + protected DialogDescriptor createDescriptor()
13.346 {
13.347 Object[] buttons = getButtons();
13.348 - DialogDescriptor descriptor = new DialogDescriptor(
13.349 - createMainPanel(),
13.350 + myDescriptor = new DialogDescriptor(
13.351 + getPanel(),
13.352 getMessage("LBL_Advanced_Search"), // NOI18N
13.353 - true,
13.354 + true, // modal
13.355 buttons,
13.356 mySearchButton,
13.357 DialogDescriptor.DEFAULT_ALIGN,
13.358 null,
13.359 - null
13.360 + new ActionListener() {
13.361 + public void actionPerformed(ActionEvent event) {
13.362 + if (mySearchButton == event.getSource()) {
13.363 + search();
13.364 + }
13.365 + }
13.366 + }
13.367 );
13.368 -// descriptor.setClosingOptions(
13.369 -// new Object[] { myPrnBtn, DialogDescriptor.CANCEL_OPTION });
13.370 + updateButton();
13.371
13.372 - return descriptor;
13.373 + return myDescriptor;
13.374 }
13.375
13.376 private Object[] getButtons() {
13.377 - mySearchButton = (JButton) createButton(new JButton(),
13.378 + mySearchButton = createButton(
13.379 "TLT_Search", // NOI18N
13.380 new AbstractAction(getMessage("LBL_Search")) { // NOI18N
13.381 - public void actionPerformed(ActionEvent event) {
13.382 - search();
13.383 - }
13.384 + public void actionPerformed(ActionEvent event) {}
13.385 }
13.386 );
13.387 return new Object[] {
13.388 @@ -260,21 +273,17 @@
13.389 };
13.390 }
13.391
13.392 - private JButton myFirst;
13.393 - private JButton myPrevious;
13.394 - private JButton myNext;
13.395 - private JButton myLast;
13.396 -
13.397 - private JButton myFit;
13.398 - private JButton myIncrease;
13.399 - private JButton myDecrease;
13.400 -
13.401 -
13.402 private Object mySource;
13.403 - private JTextField myText;
13.404 + private TextField myName;
13.405 + private JComboBox myTarget;
13.406 private SearchListener myTree;
13.407 private JButton mySearchButton;
13.408 + private JCheckBox myMatchCase;
13.409 + private JCheckBox myPatternMatch;
13.410 + private JCheckBox myRegularExpression;
13.411 private SearchEngine mySearchEngine;
13.412 + private DialogDescriptor myDescriptor;
13.413
13.414 - private static final int TEXT_WIDTH = 100;
13.415 + private static final int TEXT_WIDTH = 200;
13.416 + private static final String ASTERISK = "*"; // NOI18N
13.417 }
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/TextField.java Wed Jan 24 10:49:48 2007 +0000
14.3 @@ -0,0 +1,171 @@
14.4 +/*
14.5 + * The contents of this file are subject to the terms of the Common Development
14.6 + * and Distribution License (the License). You may not use this file except in
14.7 + * compliance with the License.
14.8 + *
14.9 + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
14.10 + * or http://www.netbeans.org/cddl.txt.
14.11 + *
14.12 + * When distributing Covered Code, include this CDDL Header Notice in each file
14.13 + * and include the License file at http://www.netbeans.org/cddl.txt.
14.14 + * If applicable, add the following below the CDDL Header, with the fields
14.15 + * enclosed by brackets [] replaced by your own identifying information:
14.16 + * "Portions Copyrighted [year] [name of copyright owner]"
14.17 + *
14.18 + * The Original Software is NetBeans. The Initial Developer of the Original
14.19 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
14.20 + * Microsystems, Inc. All Rights Reserved.
14.21 + */
14.22 +package org.netbeans.modules.bpel.search.impl.ui;
14.23 +
14.24 +import java.awt.event.KeyEvent;
14.25 +import java.awt.event.KeyAdapter;
14.26 +import java.awt.event.ActionEvent;
14.27 +import java.awt.event.ActionListener;
14.28 +
14.29 +import java.util.ArrayList;
14.30 +import java.util.List;
14.31 +import java.util.StringTokenizer;
14.32 +import javax.swing.JComboBox;
14.33 +import javax.swing.JComponent;
14.34 +import javax.swing.JRootPane;
14.35 +import javax.swing.SwingUtilities;
14.36 +
14.37 +/**
14.38 + * @author Vladimir Yaroslavskiy
14.39 + * @version 2006.12.22
14.40 + */
14.41 +public final class TextField {
14.42 +
14.43 + /**{@inheritDoc}*/
14.44 + public TextField(String items) {
14.45 + myItems = new ArrayList<String>();
14.46 + createUIComponent();
14.47 + setItems(items);
14.48 + }
14.49 +
14.50 + /**{@inheritDoc}*/
14.51 + public String getText() {
14.52 + return (String) myComboBox.getEditor().getItem();
14.53 + }
14.54 +
14.55 + /**{@inheritDoc}*/
14.56 + public void requestFocus() {
14.57 + myComboBox.getEditor().getEditorComponent().requestFocus();
14.58 + }
14.59 +
14.60 + /**{@inheritDoc}*/
14.61 + public String save() {
14.62 + addItem((String) myComboBox.getEditor().getItem()); // save last input item
14.63 + StringBuffer items = new StringBuffer();
14.64 +
14.65 + for (int i=0; i < myItems.size(); i++) {
14.66 + items.append((i==0 ? "" : DELIM) + myItems.get(i)); // NOI18N
14.67 +
14.68 + if (i == MAX_SIZE) {
14.69 + break;
14.70 + }
14.71 + }
14.72 + return items.toString();
14.73 + }
14.74 +
14.75 + /**{@inheritDoc}*/
14.76 + public void addActionListener(ActionListener listener) {
14.77 + myActionListener = listener;
14.78 + }
14.79 +
14.80 + /**{@inheritDoc}*/
14.81 + public JComponent getUIComponent() {
14.82 + return myComboBox;
14.83 + }
14.84 +
14.85 + private void addItem(String item) {
14.86 + if (item == null) {
14.87 + select();
14.88 + return;
14.89 + }
14.90 + myComboBox.removeAllItems();
14.91 +
14.92 + if (myItems.contains(item)) {
14.93 + myItems.remove(item);
14.94 + }
14.95 + myItems.add(0, item);
14.96 +
14.97 + for (int i=0; i < myItems.size(); i++) {
14.98 + if (i == MAX_SIZE) {
14.99 + break;
14.100 + }
14.101 + myComboBox.addItem(myItems.get(i));
14.102 + }
14.103 + myComboBox.setSelectedItem(item);
14.104 + select();
14.105 + }
14.106 +
14.107 + private void setItems(String items) {
14.108 + if (items == null) {
14.109 + return;
14.110 + }
14.111 + if (items.startsWith(DELIM)) {
14.112 + if ( !myItems.contains("")) { // NOI18N
14.113 + myItems.add(""); // NOI18N
14.114 + }
14.115 + }
14.116 + StringTokenizer stk = new StringTokenizer(items, DELIM);
14.117 +
14.118 + while (stk.hasMoreTokens()) {
14.119 + String item = stk.nextToken();
14.120 +
14.121 + if ( !myItems.contains(item)) {
14.122 + myItems.add(item);
14.123 + }
14.124 + }
14.125 + myComboBox.removeAllItems();
14.126 +
14.127 + for (int i=0; i < myItems.size(); i++) {
14.128 + myComboBox.addItem(myItems.get(i));
14.129 +
14.130 + if (i == MAX_SIZE) {
14.131 + break;
14.132 + }
14.133 + }
14.134 + if (myItems.size() > 0) {
14.135 + myComboBox.setSelectedItem(myItems.get(0));
14.136 + }
14.137 + select();
14.138 + }
14.139 +
14.140 + private void createUIComponent() {
14.141 + myComboBox = new JComboBox();
14.142 + myComboBox.setEditable(true);
14.143 + myComboBox.getEditor().getEditorComponent().addKeyListener(
14.144 + new KeyAdapter() {
14.145 + public void keyReleased(KeyEvent event) {
14.146 + if (myActionListener != null) {
14.147 + myActionListener.actionPerformed(
14.148 + new ActionEvent(myComboBox.getEditor().getItem(), 0, null));
14.149 + }
14.150 + }
14.151 + public void keyPressed(KeyEvent key) {
14.152 + if (key.getKeyCode() == key.VK_ENTER && !myComboBox.isPopupVisible()) {
14.153 + JRootPane rootPane = SwingUtilities.getRootPane(myComboBox);
14.154 +
14.155 + if (rootPane != null) {
14.156 + rootPane.dispatchEvent(key);
14.157 + }
14.158 + }
14.159 + }
14.160 + }
14.161 + );
14.162 + }
14.163 +
14.164 + private void select() {
14.165 + myComboBox.getEditor().selectAll();
14.166 + }
14.167 +
14.168 + private JComboBox myComboBox;
14.169 + private List<String> myItems;
14.170 + private ActionListener myActionListener;
14.171 +
14.172 + private static final int MAX_SIZE = 15;
14.173 + private static final String DELIM = "\u007f"; // NOI18N
14.174 +}
15.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/Tree.java Mon Jan 15 14:44:19 2007 +0000
15.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/Tree.java Wed Jan 24 10:49:48 2007 +0000
15.3 @@ -25,8 +25,11 @@
15.4
15.5 import java.awt.Component;
15.6 import java.awt.Dimension;
15.7 +import java.awt.Toolkit;
15.8 +import java.awt.datatransfer.StringSelection;
15.9 import java.awt.event.ActionEvent;
15.10 import java.awt.event.ActionListener;
15.11 +import java.awt.event.ComponentEvent;
15.12 import java.awt.event.KeyEvent;
15.13 import java.awt.event.KeyAdapter;
15.14 import java.awt.event.MouseAdapter;
15.15 @@ -35,6 +38,7 @@
15.16 import javax.swing.JMenuItem;
15.17 import javax.swing.JPopupMenu;
15.18 import javax.swing.JTree;
15.19 +import javax.swing.KeyStroke;
15.20 import javax.swing.SwingUtilities;
15.21 import javax.swing.ToolTipManager;
15.22 import javax.swing.event.TreeExpansionEvent;
15.23 @@ -51,7 +55,7 @@
15.24 import org.openide.util.NbBundle;
15.25 import org.openide.windows.WindowManager;
15.26
15.27 -import org.netbeans.modules.print.api.PrintUtil;
15.28 +import static org.netbeans.modules.print.api.PrintUtil.*;
15.29 import org.netbeans.modules.bpel.search.api.SearchEvent;
15.30 import org.netbeans.modules.bpel.search.api.SearchElement;
15.31 import org.netbeans.modules.bpel.search.spi.SearchListener;
15.32 @@ -62,13 +66,7 @@
15.33 * @version 2006.11.24
15.34 */
15.35 final class Tree implements SearchListener {
15.36 -/*
15.37 - Tree() {
15.38 - myConfig = new Config (key);
15.39 - mySeparator = I18n.get (myConfig.get ("separator", "$separator." + myKey));
15.40 - }
15.41 -// todo r
15.42 -*/
15.43 +
15.44 public void searchStarted(SearchEvent event) {
15.45 //out();
15.46 myRoot = new DefaultMutableTreeNode();
15.47 @@ -90,8 +88,7 @@
15.48 Tree.class, "LBL_Found_Occurrences", text, myFoundCount); // NOI18N
15.49 myRoot.setUserObject(
15.50 new SearchElement.Adapter(title, title, Util.getIcon("find"), null)); // NOI18N
15.51 -// todo r
15.52 -// factorizeRoot(myRoot);
15.53 +
15.54 View view = (View) WindowManager.getDefault().findTopComponent(View.NAME);
15.55 view.show(createTree());
15.56 }
15.57 @@ -99,11 +96,12 @@
15.58 private JTree createTree() {
15.59 myTree = new JTree(new DefaultTreeModel(myRoot));
15.60 myTree.getSelectionModel().setSelectionMode(
15.61 - TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
15.62 + TreeSelectionModel.SINGLE_TREE_SELECTION);
15.63 ToolTipManager.sharedInstance().registerComponent(myTree);
15.64 myTree.setCellRenderer(new TreeRenderer());
15.65 myTree.setShowsRootHandles(false);
15.66 myTree.setRootVisible(true);
15.67 + myTree.setSelectionPath(new TreePath(myRoot.getPath()));
15.68
15.69 myTree.addTreeWillExpandListener(new TreeWillExpandListener() {
15.70 public void treeWillExpand(TreeExpansionEvent event) {
15.71 @@ -126,22 +124,23 @@
15.72 myTree.addMouseListener(new MouseAdapter() {
15.73 public void mousePressed(MouseEvent event) {
15.74 if (SwingUtilities.isRightMouseButton(event)) {
15.75 - showPopupMenu(event);
15.76 + showPopupMenu(event, event.getX(), event.getY());
15.77 }
15.78 }
15.79 public void mouseClicked(MouseEvent event) {
15.80 - // simple click
15.81 - if (event.getClickCount() == 1) {
15.82 - select(getNode(event));
15.83 + // double click
15.84 + if (event.getClickCount() == 2) {
15.85 + DefaultMutableTreeNode node = getSelectedNode();
15.86 +
15.87 + if (node.isLeaf()) {
15.88 + selectOnDiagram(node);
15.89 + }
15.90 }
15.91 }
15.92 });
15.93 myTree.addKeyListener(new KeyAdapter() {
15.94 public void keyReleased(KeyEvent event) {
15.95 - if (event.getKeyCode() == event.VK_ENTER) {
15.96 - reform(getSelectedNodes());
15.97 -//todo a goto(getSelectedNodes());
15.98 - }
15.99 + handleEvent(event);
15.100 }
15.101 });
15.102 updateSize();
15.103 @@ -149,63 +148,269 @@
15.104 return myTree;
15.105 }
15.106
15.107 + private void handleEvent(KeyEvent event) {
15.108 + DefaultMutableTreeNode node = getSelectedNode();
15.109 + int code = event.getKeyCode();
15.110 + int modifiers = event.getModifiers();
15.111 +
15.112 + if (code == KeyEvent.VK_F10 && isShift(modifiers)) {
15.113 + showPopupMenu(event, 0, 0);
15.114 + }
15.115 + else {
15.116 + handleAction(code, modifiers, node);
15.117 + }
15.118 + }
15.119 +
15.120 + private void handleAction(int code, int modifiers, DefaultMutableTreeNode node) {
15.121 + if (code == KeyEvent.VK_O && isAlt(modifiers)) {
15.122 + gotoSource(node);
15.123 + }
15.124 + else if (code == KeyEvent.VK_D && isAlt(modifiers)) {
15.125 + selectOnDiagram(node);
15.126 + }
15.127 + else if (code == KeyEvent.VK_C && isCtrl(modifiers)) {
15.128 + copy(node);
15.129 + }
15.130 + else if (code == KeyEvent.VK_H && isCtrl(modifiers)) {
15.131 + export(node);
15.132 + }
15.133 + else {
15.134 + handleResult(code, modifiers, node);
15.135 + }
15.136 + }
15.137 +
15.138 + private void handleResult(int code, int modifiers, DefaultMutableTreeNode node) {
15.139 + if (code == KeyEvent.VK_F12 && isShift(modifiers)) {
15.140 + previousOccurence(node);
15.141 + }
15.142 + else if (code == KeyEvent.VK_F12) {
15.143 + nextOccurence(node);
15.144 + }
15.145 + else if (code == KeyEvent.VK_E && isCtrl(modifiers)) {
15.146 + collapseExpand(getSelectedNode());
15.147 + }
15.148 + else if (code == KeyEvent.VK_DELETE) {
15.149 + remove(node);
15.150 + }
15.151 + }
15.152 +
15.153 + private void showPopupMenu(ComponentEvent event, int x, int y) {
15.154 + final DefaultMutableTreeNode node = getSelectedNode();
15.155 + JPopupMenu popup = new JPopupMenu();
15.156 + JMenuItem item;
15.157 +
15.158 + createAction(popup, node);
15.159 +
15.160 + popup.addSeparator(); // -----------------------------------------------------
15.161 +
15.162 + // previous occurence
15.163 + item = createItem("LBL_Previous_Occurence"); // NOI18N
15.164 + item.setEnabled(true);
15.165 + item.addActionListener(new ActionListener() {
15.166 + public void actionPerformed(ActionEvent event) {
15.167 + previousOccurence(node);
15.168 + }
15.169 + });
15.170 + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12,KeyEvent.SHIFT_MASK));
15.171 + popup.add(item);
15.172 +
15.173 + // next occurence
15.174 + item = createItem("LBL_Next_Occurence"); // NOI18N
15.175 + item.setEnabled(true);
15.176 + item.addActionListener(new ActionListener() {
15.177 + public void actionPerformed(ActionEvent event) {
15.178 + nextOccurence(node);
15.179 + }
15.180 + });
15.181 + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0));
15.182 + popup.add(item);
15.183 +
15.184 + popup.addSeparator(); // -----------------------------------------------------
15.185 +
15.186 + // collapse / expand
15.187 + item = createItem("LBL_Collapse_Expand"); // NOI18N
15.188 + item.setEnabled( !node.isLeaf());
15.189 + item.addActionListener(new ActionListener() {
15.190 + public void actionPerformed(ActionEvent event) {
15.191 + collapseExpand(node);
15.192 + }
15.193 + });
15.194 + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_MASK));
15.195 + popup.add(item);
15.196 +
15.197 + // remove
15.198 + item = createItem("LBL_Remove"); // NOI18N
15.199 + item.setEnabled( !node.isRoot());
15.200 + item.addActionListener(new ActionListener() {
15.201 + public void actionPerformed(ActionEvent event) {
15.202 + remove(node);
15.203 + }
15.204 + });
15.205 + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
15.206 + popup.add(item);
15.207 +
15.208 + // show
15.209 + popup.show(event.getComponent(), x, y);
15.210 + }
15.211 +
15.212 + private void createAction(JPopupMenu popup, final DefaultMutableTreeNode node) {
15.213 + JMenuItem item;
15.214 +
15.215 + // go to source
15.216 + item = createItem("LBL_Go_to_Source"); // NOI18N
15.217 + item.setEnabled( !node.isRoot());
15.218 + item.addActionListener(new ActionListener() {
15.219 + public void actionPerformed(ActionEvent event) {
15.220 + gotoSource(node);
15.221 + }
15.222 + });
15.223 + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.ALT_MASK));
15.224 + popup.add(item);
15.225 +
15.226 + // select on diagram
15.227 + item = createItem("LBL_Select_on_Diagram"); // NOI18N
15.228 + item.setEnabled( !node.isRoot());
15.229 + item.addActionListener(new ActionListener() {
15.230 + public void actionPerformed(ActionEvent event) {
15.231 + selectOnDiagram(node);
15.232 + }
15.233 + });
15.234 + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.ALT_MASK));
15.235 + popup.add(item);
15.236 +
15.237 + // copy
15.238 + item = createItem("LBL_Copy"); // NOI18N
15.239 + item.addActionListener(new ActionListener() {
15.240 + public void actionPerformed(ActionEvent event) {
15.241 + copy(node);
15.242 + }
15.243 + });
15.244 + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK));
15.245 + popup.add(item);
15.246 +
15.247 + // export
15.248 + item = createItem("LBL_Export"); // NOI18N
15.249 + item.addActionListener(new ActionListener() {
15.250 + public void actionPerformed(ActionEvent event) {
15.251 + export(node);
15.252 + }
15.253 + });
15.254 + item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK));
15.255 + popup.add(item);
15.256 + }
15.257 +
15.258 + private boolean isAlt(int modifiers) {
15.259 + return isModifier(modifiers, KeyEvent.ALT_MASK);
15.260 + }
15.261 +
15.262 + private boolean isShift(int modifiers) {
15.263 + return isModifier(modifiers, KeyEvent.SHIFT_MASK);
15.264 + }
15.265 +
15.266 + private boolean isCtrl(int modifiers) {
15.267 + return isModifier(modifiers, KeyEvent.CTRL_MASK);
15.268 + }
15.269 +
15.270 + private boolean isModifier(int modifiers, int mask) {
15.271 + return (modifiers & mask) != 0;
15.272 + }
15.273 +
15.274 private void updateSize() {
15.275 myTree.putClientProperty(Dimension.class.getName(), myTree.getMaximumSize());
15.276 }
15.277
15.278 - private void showPopupMenu(MouseEvent event) {
15.279 - DefaultMutableTreeNode node = getNode(event);
15.280 - JPopupMenu popup = new JPopupMenu();
15.281 - JMenuItem item;
15.282 + private void gotoSource(DefaultMutableTreeNode node) {
15.283 + ((SearchElement) node.getUserObject()).gotoSource();
15.284 + }
15.285
15.286 - // select
15.287 - item = createItem("LBL_Select_Action"); // NOI18N
15.288 - item.addActionListener(new ActionListener() {
15.289 - public void actionPerformed(ActionEvent event) {
15.290 - select(getSelectedNodes());
15.291 - }
15.292 - });
15.293 - if ( !node.isRoot()) {
15.294 - popup.add(item);
15.295 - }
15.296 - popup.addSeparator();
15.297 - // todo start here
15.298 + private void selectOnDiagram(DefaultMutableTreeNode node) {
15.299 + ((SearchElement) node.getUserObject()).selectOnDiagram();
15.300 + }
15.301
15.302 - if (popup.getSubElements().length != 0) {
15.303 - popup.show(event.getComponent(), event.getX(), event.getY());
15.304 + private void previousOccurence(TreeNode node) {
15.305 +// todo a
15.306 + }
15.307 +
15.308 + private void nextOccurence(TreeNode node) {
15.309 +// todo a
15.310 + }
15.311 +
15.312 + private void copy(TreeNode node) {
15.313 + StringBuffer buffer = new StringBuffer();
15.314 +
15.315 + copy(node, buffer, ""); // NOI18N
15.316 + buffer.append(LS);
15.317 +
15.318 + StringSelection selection = new StringSelection(buffer.toString());
15.319 + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
15.320 + selection, selection);
15.321 + }
15.322 +
15.323 + private void copy(TreeNode node, StringBuffer buffer, String indent) {
15.324 + buffer.append(indent + node + LS);
15.325 + Enumeration children = node.children();
15.326 +
15.327 + while (children.hasMoreElements()) {
15.328 + TreeNode child = (TreeNode) children.nextElement();
15.329 + copy(child, buffer, indent + " "); // NOI18N
15.330 }
15.331 }
15.332
15.333 - private JMenuItem createItem(String name) {
15.334 - return new JMenuItem(NbBundle.getMessage(Tree.class, name));
15.335 + private void export(DefaultMutableTreeNode node) {
15.336 + List<List<String>> descriptions = new ArrayList<List<String>>();
15.337 + export(node, descriptions);
15.338 + descriptions.add (null);
15.339 +
15.340 + if (myExport == null) {
15.341 + myExport = new Export();
15.342 + }
15.343 + myExport.show(descriptions, myRoot.toString());
15.344 }
15.345
15.346 - private void select(DefaultMutableTreeNode [] nodes) {
15.347 - if (nodes == null) {
15.348 - return;
15.349 + private void export(DefaultMutableTreeNode node, List<List<String>> descriptions) {
15.350 + if (node.isLeaf()) {
15.351 + List<String> description = new ArrayList<String>();
15.352 + description.add(getDescription(node));
15.353 + description.add(node.toString());
15.354 + descriptions.add(description);
15.355 }
15.356 - for (DefaultMutableTreeNode node : nodes) {
15.357 - select(node);
15.358 + Enumeration children = node.children();
15.359 +
15.360 + while (children.hasMoreElements()) {
15.361 + DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
15.362 + export(child, descriptions);
15.363 }
15.364 }
15.365
15.366 - private void select(DefaultMutableTreeNode node) {
15.367 - if (node == null || node.isRoot()) {
15.368 - return;
15.369 + private String getDescription(DefaultMutableTreeNode node) {
15.370 + if (isRoot(node)) {
15.371 + return ""; // NOI18N
15.372 }
15.373 - ((SearchElement) node.getUserObject()).select();
15.374 + String description = getDescription((DefaultMutableTreeNode) node.getParent());
15.375 +
15.376 + if ( !node.isLeaf()) {
15.377 + if ( !isRoot((DefaultMutableTreeNode) node.getParent())) {
15.378 + description += LS;
15.379 + }
15.380 + description += node;
15.381 + }
15.382 + return description;
15.383 }
15.384
15.385 - private void reform(DefaultMutableTreeNode [] nodes) {
15.386 - if (nodes == null) {
15.387 - return;
15.388 + private boolean isRoot(DefaultMutableTreeNode node) {
15.389 + if (node == null) {
15.390 + return true;
15.391 }
15.392 - for (DefaultMutableTreeNode node : nodes) {
15.393 - reform(node);
15.394 + if (node.getParent() == null) {
15.395 + return true;
15.396 }
15.397 + if (node.getParent().getParent() == null) {
15.398 + return true;
15.399 + }
15.400 + return false;
15.401 }
15.402
15.403 - private void reform(DefaultMutableTreeNode node) {
15.404 + private void collapseExpand(DefaultMutableTreeNode node) {
15.405 if (node == null || node.isLeaf()) {
15.406 return;
15.407 }
15.408 @@ -294,209 +499,37 @@
15.409 }
15.410 }
15.411
15.412 - private DefaultMutableTreeNode getNode(MouseEvent event) {
15.413 - return getNode(myTree.getPathForLocation(event.getX(), event.getY()));
15.414 + private void remove(DefaultMutableTreeNode node) {
15.415 + DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
15.416 +
15.417 + if (parent != null) {
15.418 + parent.remove(node);
15.419 + myTree.updateUI();
15.420 + }
15.421 }
15.422
15.423 private DefaultMutableTreeNode getNode(TreePath path) {
15.424 - if (path == null) {
15.425 - return null;
15.426 - }
15.427 return (DefaultMutableTreeNode) path.getLastPathComponent();
15.428 }
15.429
15.430 - private DefaultMutableTreeNode [] getSelectedNodes() {
15.431 - TreePath [] treePaths = myTree.getSelectionPaths();
15.432 + private DefaultMutableTreeNode getSelectedNode() {
15.433 + TreePath[] paths = myTree.getSelectionPaths();
15.434
15.435 - if (treePaths == null) {
15.436 - return null;
15.437 + if (paths == null || paths.length == 0) {
15.438 + return myRoot;
15.439 }
15.440 - DefaultMutableTreeNode [] nodes = new DefaultMutableTreeNode[treePaths.length];
15.441 + TreePath path = paths [0];
15.442
15.443 - for (int i=0; i < treePaths.length; i++) {
15.444 - nodes [i] = getNode(treePaths[i]);
15.445 + if (path == null) {
15.446 + return myRoot;
15.447 }
15.448 - return nodes;
15.449 + return getNode(path);
15.450 }
15.451
15.452 -/*todo r
15.453 - private void factorizeRoot(DefaultMutableTreeNode root) {
15.454 - int count = root.getChildCount ();
15.455 -
15.456 - for (int i=0; i < count; i++) {
15.457 - factorize ((DefaultMutableTreeNode) root.getChildAt (i));
15.458 - }
15.459 + private JMenuItem createItem(String name) {
15.460 + return new JMenuItem(NbBundle.getMessage(Tree.class, name));
15.461 }
15.462
15.463 - private void factorize (DefaultMutableTreeNode node) {
15.464 -//System.out.println ();
15.465 -//System.out.println ("SEE: " + node);
15.466 - if (node.getChildCount () != 1) {
15.467 -//System.out.println (" return: has more children: " + node.getChildCount ());
15.468 - return;
15.469 - }
15.470 - DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt (0);
15.471 -
15.472 - if (child.isLeaf ()) {
15.473 -//System.out.println (" return: child is leaf: " + child);
15.474 - return;
15.475 - }
15.476 - DefaultMutableTreeNode grandChild = (DefaultMutableTreeNode) child.getChildAt (0);
15.477 -
15.478 - if (grandChild.isLeaf ()) {
15.479 -//System.out.println (" return: grandchild is leaf: " + grandchild);
15.480 - return;
15.481 - }
15.482 - // union node with child
15.483 -//System.out.println ("==== see node: " + node + " " + ((SearchElement) node.getUserObject ()));
15.484 -//System.out.println ("==== see child: " + child + " " + ((SearchElement) child.getUserObject ()));
15.485 - SearchElement searchElement = (SearchElement) child.getUserObject ();
15.486 - String text = "" + node + mySeparator + child;
15.487 - node.setUserObject (searchElement.clone (text));
15.488 -//System.out.println ("==== set text: " + text);
15.489 -
15.490 - node.remove (child);
15.491 -//System.out.println (" remove child: " + child);
15.492 -
15.493 - Vector grandchildren = new Vector ();
15.494 - Enumeration children = child.children ();
15.495 -
15.496 - while (children.hasMoreElements ()) {
15.497 - DefaultMutableTreeNode next = (DefaultMutableTreeNode) children.nextElement ();
15.498 - grandchildren.add (next);
15.499 -//System.out.println (" grandchild: " + next);
15.500 - }
15.501 -//System.out.println (" --------------------");
15.502 -
15.503 - for (int i=0; i < grandchildren.size (); i++) {
15.504 - DefaultMutableTreeNode next = (DefaultMutableTreeNode) grandchildren.get (i);
15.505 - node.add (next);
15.506 -//System.out.println (" add grandchild: " + next);
15.507 - }
15.508 -//System.out.println (" updated: " + node);
15.509 - factorize (node);
15.510 - }
15.511 -
15.512 - public void copy () {
15.513 - DefaultMutableTreeNode [] nodes = getSelectedNodes();
15.514 -
15.515 - if (nodes == null) {
15.516 - return;
15.517 - }
15.518 - StringBuffer buffer = new StringBuffer ();
15.519 -
15.520 - for (int i=0; i < nodes.length; i++) {
15.521 - copy (nodes [i], buffer, "");
15.522 - buffer.append ("\n");
15.523 - }
15.524 - StringSelection stringSelection = new StringSelection (buffer.toString ());
15.525 - Toolkit.getDefaultToolkit ().getSystemClipboard ().setContents (stringSelection, stringSelection);
15.526 - }
15.527 -
15.528 - private void copy (DefaultMutableTreeNode node, StringBuffer buffer, String indent) {
15.529 - buffer.append (indent + node + "\n");
15.530 - Enumeration children = node.children ();
15.531 -
15.532 - while (children.hasMoreElements ()) {
15.533 - DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement ();
15.534 - copy (child, buffer, indent + " ");
15.535 - }
15.536 - }
15.537 -
15.538 - public void remove () {
15.539 - DefaultMutableTreeNode [] nodes = getSelectedNodes();
15.540 -
15.541 - if (nodes == null) {
15.542 - return;
15.543 - }
15.544 - for (int i=0; i < nodes.length; i++) {
15.545 - DefaultMutableTreeNode parent = (DefaultMutableTreeNode) nodes [i].getParent ();
15.546 -
15.547 - if (parent == null) {
15.548 - continue;
15.549 - }
15.550 - parent.remove (nodes [i]);
15.551 - }
15.552 -//todo r myTree.updateUI ();
15.553 -myTree.revalidate();
15.554 -myTree.repaint();
15.555 - }
15.556 -
15.557 - public void removeAll () {
15.558 - DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel ().getRoot ();
15.559 - root.removeAllChildren ();
15.560 -//todo r myTree.updateUI ();
15.561 -myTree.revalidate();
15.562 -myTree.repaint();
15.563 - }
15.564 -
15.565 - public void export () { // todo rename save
15.566 - DefaultMutableTreeNode [] nodes = getSelectedNodes();
15.567 -
15.568 - if (nodes == null) {
15.569 - return;
15.570 - }
15.571 - Vector descriptions = new Vector ();
15.572 -
15.573 - for (int i=0; i < nodes.length; i++) {
15.574 - export (nodes [i], descriptions);
15.575 - descriptions.add (null);
15.576 - }
15.577 - if (myExport == null) {
15.578 - myExport = new Export ();
15.579 - }
15.580 - myExport.show (descriptions, myTitle);
15.581 - }
15.582 -
15.583 - private void export (DefaultMutableTreeNode node, Vector descriptions) {
15.584 - if (node.isLeaf ()) {
15.585 - Vector description = new Vector ();
15.586 - description.add (getDescription (node));
15.587 - description.add ("" + node);
15.588 - descriptions.add (description);
15.589 - }
15.590 - Enumeration children = node.children ();
15.591 -
15.592 - while (children.hasMoreElements ()) {
15.593 - DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement ();
15.594 - export (child, descriptions);
15.595 - }
15.596 - }
15.597 -
15.598 - private String getDescription (DefaultMutableTreeNode node) {
15.599 - if (isRoot (node)) {
15.600 - return "";
15.601 - }
15.602 - String description = getDescription ((DefaultMutableTreeNode) node.getParent ());
15.603 -
15.604 - if ( !node.isLeaf () ) {
15.605 - if ( !isRoot ((DefaultMutableTreeNode) node.getParent ())) {
15.606 - description += mySeparator;
15.607 - }
15.608 - description += node;
15.609 - }
15.610 - return description;
15.611 - }
15.612 -
15.613 - private boolean isRoot (DefaultMutableTreeNode node) {
15.614 - if (node == null) {
15.615 - return true;
15.616 - }
15.617 - if (node.getParent () == null) {
15.618 - return true;
15.619 - }
15.620 - if (node.getParent ().getParent () == null) {
15.621 - return true;
15.622 - }
15.623 - return false;
15.624 - }
15.625 -
15.626 - private String myId;
15.627 - private String myTitle;
15.628 - private String mySeparator;
15.629 - private Export myExport = null;
15.630 -//todo r private JPanel myPanel = new JPanel (new GridBagLayout ());
15.631 -*/
15.632 private void addElement(
15.633 MutableTreeNode root,
15.634 SearchElement element,
15.635 @@ -526,12 +559,6 @@
15.636 //out("skip leaf: " + child);
15.637 continue;
15.638 }
15.639 -//todo r String text = ((SearchElement) child.getUserObject()).getText();
15.640 -//out("see child: " + text);
15.641 -//out("see next: " + next.toString());
15.642 -
15.643 -//todo r? if (next.getText().equals(text)) {
15.644 -// if (next.toString().equals(child.toString())) {
15.645 if (child.getUserObject().equals(next)) {
15.646 // go to the next level
15.647 //out("next level");
15.648 @@ -557,14 +584,6 @@
15.649 return elements.iterator();
15.650 }
15.651
15.652 - private void out() {
15.653 - PrintUtil.out();
15.654 - }
15.655 -
15.656 - private void out(Object object) {
15.657 - PrintUtil.out(object);
15.658 - }
15.659 -
15.660 // ----------------------------------------------------------------
15.661 private static class TreeRenderer extends DefaultTreeCellRenderer {
15.662
15.663 @@ -583,12 +602,9 @@
15.664 }
15.665 }
15.666
15.667 -// todo r
15.668 -// private String myKey;
15.669 -// private Config myConfig;
15.670 -// private String mySeparator;
15.671 private JTree myTree;
15.672 + private Export myExport;
15.673 private int myFoundCount;
15.674 private boolean myIsReformAll;
15.675 - private MutableTreeNode myRoot;
15.676 + private DefaultMutableTreeNode myRoot;
15.677 }
16.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/View.java Mon Jan 15 14:44:19 2007 +0000
16.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/ui/View.java Wed Jan 24 10:49:48 2007 +0000
16.3 @@ -18,7 +18,6 @@
16.4 */
16.5 package org.netbeans.modules.bpel.search.impl.ui;
16.6
16.7 -import java.awt.Dimension;
16.8 import java.awt.GridBagConstraints;
16.9 import java.awt.GridBagLayout;
16.10 import java.awt.event.FocusEvent;
16.11 @@ -44,6 +43,7 @@
16.12 public View() {
16.13 setIcon(Util.getIcon("find").getImage()); // NOI18N
16.14 setLayout(new GridBagLayout());
16.15 + setFocusable(true);
16.16 }
16.17
16.18 void show(JTree tree) {
16.19 @@ -82,6 +82,7 @@
16.20 c.weightx = 1.0;
16.21 c.weighty = 1.0;
16.22 add(scrollPanel, c);
16.23 +//todo a add buttons on toolbar
16.24
16.25 revalidate();
16.26 repaint();
17.1 --- a/bpel.search/src/org/netbeans/modules/bpel/search/impl/util/Util.java Mon Jan 15 14:44:19 2007 +0000
17.2 +++ b/bpel.search/src/org/netbeans/modules/bpel/search/impl/util/Util.java Wed Jan 24 10:49:48 2007 +0000
17.3 @@ -36,15 +36,13 @@
17.4 private Util() {}
17.5
17.6 /**{@inheritDoc}*/
17.7 - @SuppressWarnings("unchecked") // NOI18N
17.8 - public static <T> List<T> getInstances(Class<T> clazz)
17.9 - {
17.10 + public static <T> List<T> getInstances(Class<T> clazz) {
17.11 Lookup.Result result = Lookup.getDefault().lookup(new Lookup.Template(clazz));
17.12 - Collection<Object> collection = result.allInstances();
17.13 + Collection collection = result.allInstances();
17.14 List<T> list = new ArrayList<T>();
17.15
17.16 for (Object object : collection) {
17.17 - list.add((T) object);
17.18 + list.add(clazz.cast(object));
17.19 }
17.20 return list;
17.21 }