Source Code Cross Referenced for FindController.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » ui » support » finddialog » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » uml » org.netbeans.modules.uml.ui.support.finddialog 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.uml.ui.support.finddialog;
0043:
0044:        import java.awt.Component;
0045:        import java.awt.Frame;
0046:        import java.util.ArrayList;
0047:        import java.util.regex.Matcher;
0048:        import java.util.regex.Pattern;
0049:
0050:        import javax.swing.JDialog;
0051:        import javax.swing.JOptionPane;
0052:
0053:        import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeControl;
0054:        import org.netbeans.modules.uml.ui.swing.finddialog.FindDialogUI;
0055:        import org.netbeans.modules.uml.ui.swing.finddialog.ReplaceDialogUI;
0056:
0057:        import org.netbeans.modules.uml.ui.support.DiagramAndPresentationNavigator;
0058:        import org.netbeans.modules.uml.ui.support.IDiagramAndPresentationNavigator;
0059:        import org.netbeans.modules.uml.ui.support.ProductHelper;
0060:        import org.netbeans.modules.uml.ui.support.SimpleQuestionDialogKind;
0061:        import org.netbeans.modules.uml.ui.support.SimpleQuestionDialogResultKind;
0062:        import org.netbeans.modules.uml.ui.support.SwingPreferenceQuestionDialog;
0063:        import org.netbeans.modules.uml.ui.support.applicationmanager.IProduct;
0064:        import org.netbeans.modules.uml.ui.support.applicationmanager.IProductDiagramManager;
0065:        import org.netbeans.modules.uml.ui.support.commondialogs.IPreferenceQuestionDialog;
0066:        import org.netbeans.modules.uml.ui.support.commondialogs.MessageIconKindEnum;
0067:        import org.netbeans.modules.uml.ui.support.diagramsupport.IPresentationTarget;
0068:        import org.netbeans.modules.uml.ui.support.diagramsupport.IProxyDiagramManager;
0069:        import org.netbeans.modules.uml.ui.support.diagramsupport.PresentationFinder;
0070:        import org.netbeans.modules.uml.ui.support.diagramsupport.ProxyDiagramManager;
0071:        import org.netbeans.modules.uml.core.IApplication;
0072:        import org.netbeans.modules.uml.core.metamodel.core.constructs.IActor;
0073:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
0074:        import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
0075:        import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
0076:        import org.netbeans.modules.uml.core.metamodel.core.foundation.ITaggedValue;
0077:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
0078:        import org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram;
0079:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
0080:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IFeature;
0081:        import org.netbeans.modules.uml.core.metamodel.structure.IProject;
0082:        import org.netbeans.modules.uml.core.support.umlsupport.StringUtilities;
0083:        import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
0084:        import org.netbeans.modules.uml.core.support.umlutils.ETList;
0085:        import org.netbeans.modules.uml.core.support.umlutils.ElementLocator;
0086:        import org.netbeans.modules.uml.core.support.umlutils.IElementLocator;
0087:        import org.netbeans.modules.uml.core.typemanagement.ITypeManager;
0088:        import org.netbeans.modules.uml.core.workspacemanagement.IWSProject;
0089:        import org.netbeans.modules.uml.core.workspacemanagement.IWorkspace;
0090:
0091:        /**
0092:         * @author sumitabhk
0093:         *
0094:         * 
0095:         */
0096:        public class FindController implements  IFindController {
0097:            private int m_Scope = 0;
0098:            private int m_ResultType = 0;
0099:            private String m_SearchString = "";
0100:            private int m_Kind = 0;
0101:            private String m_ReplaceString = "";
0102:            private boolean m_DiagramNavigate = true;
0103:            private boolean m_WholeWordSearch = false;
0104:            private boolean m_SearchAlias = false;
0105:            private boolean m_CaseSensitive = true;
0106:            private boolean m_IsReplace = false;
0107:            private ArrayList m_Projects = new ArrayList();
0108:            private boolean m_Cancelled = false;
0109:            private boolean m_ExternalLoad = false;
0110:            private long m_ActiveWindow = 0;
0111:            private IProject m_Project = null;
0112:            private JDialog m_Dialog = null;
0113:
0114:            /**
0115:             * 
0116:             */
0117:            public FindController() {
0118:                super ();
0119:            }
0120:
0121:            public void showFindDialog() {
0122:                setIsReplace(false);
0123:                Frame parent = ProductHelper.getProxyUserInterface()
0124:                        .getWindowHandle();
0125:                FindDialogUI ui = new FindDialogUI(parent, true);
0126:                ui.doLayout();
0127:                //ui.setVisible(true);
0128:                ui.setModal(true);
0129:                ui.setController(this );
0130:                ui.setVisible(true);
0131:            }
0132:
0133:            /* (non-Javadoc)
0134:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getScope()
0135:             */
0136:            public int getScope() {
0137:                return m_Scope;
0138:            }
0139:
0140:            /* (non-Javadoc)
0141:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setScope(int)
0142:             */
0143:            public void setScope(int value) {
0144:                m_Scope = value;
0145:            }
0146:
0147:            /* (non-Javadoc)
0148:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getSearchString()
0149:             */
0150:            public String getSearchString() {
0151:                return m_SearchString;
0152:            }
0153:
0154:            /* (non-Javadoc)
0155:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setSearchString(java.lang.String)
0156:             */
0157:            public void setSearchString(String value) {
0158:                m_SearchString = value;
0159:            }
0160:
0161:            /* (non-Javadoc)
0162:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getKind()
0163:             */
0164:            public int getKind() {
0165:                return m_Kind;
0166:            }
0167:
0168:            /* (non-Javadoc)
0169:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setKind(int)
0170:             */
0171:            public void setKind(int value) {
0172:                m_Kind = value;
0173:            }
0174:
0175:            /* (non-Javadoc)
0176:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getCaseSensitive()
0177:             */
0178:            public boolean getCaseSensitive() {
0179:                return m_CaseSensitive;
0180:            }
0181:
0182:            /* (non-Javadoc)
0183:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setCaseSensitive(int)
0184:             */
0185:            public void setCaseSensitive(boolean value) {
0186:                m_CaseSensitive = value;
0187:            }
0188:
0189:            /* (non-Javadoc)
0190:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getReplaceString()
0191:             */
0192:            public String getReplaceString() {
0193:                return m_ReplaceString;
0194:            }
0195:
0196:            /* (non-Javadoc)
0197:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setReplaceString(java.lang.String)
0198:             */
0199:            public void setReplaceString(String value) {
0200:                m_ReplaceString = value;
0201:            }
0202:
0203:            /* (non-Javadoc)
0204:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getIsReplace()
0205:             */
0206:            public boolean getIsReplace() {
0207:                return m_IsReplace;
0208:            }
0209:
0210:            /* (non-Javadoc)
0211:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setIsReplace(int)
0212:             */
0213:            public void setIsReplace(boolean value) {
0214:                m_IsReplace = value;
0215:            }
0216:
0217:            public void setDialog(JDialog diag) {
0218:                m_Dialog = diag;
0219:            }
0220:
0221:            /* (non-Javadoc)
0222:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#search(org.netbeans.modules.uml.ui.support.finddialog.IFindResults)
0223:             */
0224:            public void search(IFindResults pResults) {
0225:                // get the type of search the user selected
0226:                if (m_Kind == 1) //FIND_KIND_ADVANCED
0227:                {
0228:                    // If the user has chosen to do an advanced search
0229:                    // we take exactly what they typed in and search for it
0230:                    // this is for those users that know xpath queries
0231:                    searchUsingElementLocator(m_SearchString, pResults);
0232:                } else {
0233:                    // search by what they typed in (name or description will be searched)
0234:                    if ((m_SearchString.indexOf('*') >= 0)
0235:                            && (!m_WholeWordSearch)) {
0236:                        // found a wildcard
0237:                        searchWithWildcard(pResults);
0238:                    } else {
0239:                        // no wildcard found, so if they want to do a case sensitive search,
0240:                        // we can use the element locator
0241:                        if (m_CaseSensitive) {
0242:                            String tempStr;
0243:                            // case sensitive
0244:                            // now need to check if we are doing a find or a replace
0245:                            if (!m_IsReplace) {
0246:                                if (m_ResultType == 0)//FIND_TYPE_ELEMENT)
0247:                                {
0248:                                    // just a find, so we can group the name and alias strings together
0249:                                    tempStr = "//*[contains(@name, \"";
0250:                                    tempStr += m_SearchString;
0251:                                    tempStr += "\")";
0252:                                    if (m_SearchAlias) {
0253:                                        tempStr += " or contains(@alias, \"";
0254:                                        tempStr += m_SearchString;
0255:                                        tempStr += "\")";
0256:                                    }
0257:                                    tempStr += "]";
0258:                                    // if this search has returned S_FALSE then the user was asked about something
0259:                                    // and they said not to continue
0260:                                    if (searchUsingElementLocator(tempStr,
0261:                                            pResults)) {
0262:                                        searchForDiagrams(tempStr, pResults);
0263:                                        process(m_SearchString, -1, /*WILDCARD_LOC_UNKNOWN,*/
0264:                                                pResults);
0265:                                    }
0266:                                } else {
0267:                                    tempStr = "//*";
0268:                                    // if this search has returned S_FALSE then the user was asked about something
0269:                                    // and they said not to continue
0270:                                    if (searchUsingElementLocator(tempStr,
0271:                                            pResults)) {
0272:                                        searchForDiagrams(tempStr, pResults);
0273:                                        process(m_SearchString, -1, /*WILDCARD_LOC_UNKNOWN,*/
0274:                                                pResults);
0275:                                    }
0276:                                }
0277:                            } else {
0278:                                // this is a replace, so we will be looking for name, description or alias
0279:                                if (m_SearchAlias) {
0280:                                    tempStr = "//*[contains(@alias, \"";
0281:                                    tempStr += m_SearchString;
0282:                                    tempStr += "\")";
0283:                                    // since there are cases where the name and the alias are the same, there
0284:                                    // may not be an @alias attribute so we need to check the @name too
0285:                                    tempStr += " or (not(@alias) and contains(@name, \"";
0286:                                    tempStr += m_SearchString;
0287:                                    tempStr += "\"))]";
0288:                                    // if this search has returned S_FALSE then the user was asked about something
0289:                                    // and they said not to continue
0290:                                    if (searchUsingElementLocator(tempStr,
0291:                                            pResults)) {
0292:                                        searchForDiagrams(tempStr, pResults);
0293:                                        process(m_SearchString, -1, /*WILDCARD_LOC_UNKNOWN,*/
0294:                                                pResults);
0295:                                    }
0296:                                } else if (m_ResultType == 0)//FIND_TYPE_ELEMENT)
0297:                                {
0298:                                    tempStr = "//*[contains(@name, \"";
0299:                                    tempStr += m_SearchString;
0300:                                    tempStr += "\")]";
0301:                                    // if this search has returned S_FALSE then the user was asked about something
0302:                                    // and they said not to continue
0303:                                    if (searchUsingElementLocator(tempStr,
0304:                                            pResults)) {
0305:                                        searchForDiagrams(tempStr, pResults);
0306:                                        process(m_SearchString, -1, /*WILDCARD_LOC_UNKNOWN,*/
0307:                                                pResults);
0308:                                    }
0309:                                } else {
0310:                                    tempStr = "//*";
0311:                                    // if this search has returned S_FALSE then the user was asked about something
0312:                                    // and they said not to continue
0313:                                    if (searchUsingElementLocator(tempStr,
0314:                                            pResults)) {
0315:                                        searchForDiagrams(tempStr, pResults);
0316:                                        process(m_SearchString, -1, /*WILDCARD_LOC_UNKNOWN,*/
0317:                                                pResults);
0318:                                    }
0319:                                }
0320:                            }
0321:                        } else {
0322:                            // no wildcard found, but since they don't care about case, we can't use
0323:                            // the element locator directly
0324:                            String tempStr = "//*";
0325:                            // if this search has returned S_FALSE then the user was asked about something
0326:                            // and they said not to continue
0327:                            if (searchUsingElementLocator(tempStr, pResults)) {
0328:                                searchForDiagrams(tempStr, pResults);
0329:                                process(m_SearchString, -1, /*WILDCARD_LOC_UNKNOWN,*/
0330:                                        pResults);
0331:                            }
0332:                        }
0333:                    }
0334:                }
0335:            }
0336:
0337:            /**
0338:             * Show the replace dialog.
0339:             */
0340:            public void showReplaceDialog() {
0341:                setIsReplace(true);
0342:                // the dialog needs to know about the find controller
0343:
0344:                Frame parent = ProductHelper.getProxyUserInterface()
0345:                        .getWindowHandle();
0346:                ReplaceDialogUI ui = new ReplaceDialogUI(parent, true);
0347:                ui.doLayout();
0348:                //ui.setVisible(true);
0349:                ui.setModal(true);
0350:                ui.setController(this );
0351:                ui.setVisible(true);
0352:            }
0353:
0354:            public boolean navigateToElement(IElement pElement) {
0355:                boolean result = true;
0356:                if (pElement != null) {
0357:                    FindUtilities.startWaitCursor(m_Dialog);
0358:                    // get the core product
0359:                    IProduct pProduct = ProductHelper.getProduct();
0360:                    if (pProduct != null) {
0361:                        // find in tree
0362:                        IProjectTreeControl pTree = pProduct.getProjectTree();
0363:                        if (pTree != null) {
0364:                            pTree.findAndSelectInTree(pElement);
0365:                        }
0366:                        if (m_DiagramNavigate) {
0367:                            result = findInDiagrams(pElement);
0368:                        }
0369:                    }
0370:                    FindUtilities.endWaitCursor(m_Dialog);
0371:                }
0372:                return result;
0373:            }
0374:
0375:            /* (non-Javadoc)
0376:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getResultType()
0377:             */
0378:            public int getResultType() {
0379:                return m_ResultType;
0380:            }
0381:
0382:            /* (non-Javadoc)
0383:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setResultType(int)
0384:             */
0385:            public void setResultType(int value) {
0386:                m_ResultType = value;
0387:            }
0388:
0389:            /* (non-Javadoc)
0390:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#addToProjectList(java.lang.String)
0391:             */
0392:            public void addToProjectList(String newVal) {
0393:                m_Projects.add(newVal);
0394:            }
0395:
0396:            /* (non-Javadoc)
0397:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#clearProjectList()
0398:             */
0399:            public void clearProjectList() {
0400:                m_Projects.clear();
0401:            }
0402:
0403:            /* (non-Javadoc)
0404:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#replace(org.netbeans.modules.uml.ui.support.finddialog.IFindResults)
0405:             */
0406:            public void replace(IFindResults pResults) {
0407:                //go thru each elements in find results
0408:                try {
0409:                    replaceInElements(pResults);
0410:                } catch (Exception ex) {
0411:                    Frame parent = ProductHelper.getProxyUserInterface()
0412:                            .getWindowHandle();
0413:                    JOptionPane.showMessageDialog(parent,
0414:                            DefaultFindDialogResource
0415:                                    .getString("IDS_NOREPLACESTR"),
0416:                            DefaultFindDialogResource
0417:                                    .getString("IDS_REPLACETITLE"),
0418:                            JOptionPane.INFORMATION_MESSAGE);
0419:                    return;
0420:                }
0421:
0422:                //go thru each diagrams in find results
0423:                try {
0424:                    replaceInDiagrams(pResults);
0425:                } catch (Exception ex) {
0426:                    Frame parent = ProductHelper.getProxyUserInterface()
0427:                            .getWindowHandle();
0428:                    JOptionPane.showMessageDialog(parent,
0429:                            DefaultFindDialogResource
0430:                                    .getString("IDS_NOREPLACESTR"),
0431:                            DefaultFindDialogResource
0432:                                    .getString("IDS_REPLACETITLE"),
0433:                            JOptionPane.INFORMATION_MESSAGE);
0434:                    return;
0435:                }
0436:
0437:            }
0438:
0439:            private void replaceInElements(IFindResults pResults)
0440:                    throws Exception {
0441:                // get the elements from the results object
0442:                ETList<IElement> pElements = pResults.getElements();
0443:                if (pElements != null) {
0444:                    // loop through the elements
0445:                    int eleCount = pElements.size();
0446:                    for (int y = 0; y < eleCount; y++) {
0447:                        IElement pElement = pElements.get(y);
0448:                        if (pElement != null) {
0449:                            // "replace" its information
0450:                            if (m_ResultType == 0)//FIND_TYPE_ELEMENT)
0451:                            {
0452:                                // if it is a named element
0453:                                if (pElement instanceof  INamedElement) {
0454:                                    INamedElement pNamedElement = (INamedElement) pElement;
0455:                                    if (pNamedElement != null) {
0456:                                        String name = pNamedElement.getName();
0457:                                        String str = replaceValue(name);
0458:                                        pNamedElement.setName(str);
0459:                                    }
0460:                                }
0461:                            } else if (m_SearchAlias) {
0462:                                // if it is a named element
0463:                                if (pElement instanceof  INamedElement) {
0464:                                    INamedElement pNamedElement = (INamedElement) pElement;
0465:                                    if (pNamedElement != null) {
0466:                                        String name = pNamedElement.getAlias();
0467:                                        String str = replaceValue(name);
0468:                                        pNamedElement.setAlias(str);
0469:                                    }
0470:                                }
0471:                            } else {
0472:                                String doc = pElement.getDocumentation();
0473:                                String str = replaceValue(doc);
0474:                                pElement.setDocumentation(str);
0475:                            }
0476:                        }
0477:                    }
0478:                }
0479:            }
0480:
0481:            private void replaceInDiagrams(IFindResults pResults)
0482:                    throws Exception {
0483:                // now loop through the diagrams in the result object
0484:                ETList<IProxyDiagram> pDiagrams = pResults.getDiagrams();
0485:                if (pDiagrams != null) {
0486:                    // loop through the elements
0487:                    int count = pDiagrams.size();
0488:                    for (int y = 0; y < count; y++) {
0489:                        IProxyDiagram pDiagram = pDiagrams.get(y);
0490:                        if (pDiagram != null) {
0491:                            // "replace" its information
0492:                            if (m_ResultType == 0)//FIND_TYPE_ELEMENT)
0493:                            {
0494:                                String name = pDiagram.getName();
0495:                                String str = replaceValue(name);
0496:                                pDiagram.setName(str);
0497:                            } else if (m_SearchAlias) {
0498:                                String name = pDiagram.getAlias();
0499:                                String str = replaceValue(name);
0500:                                pDiagram.setAlias(str);
0501:                            } else {
0502:                                String doc = pDiagram.getDocumentation();
0503:                                String str = replaceValue(doc);
0504:                                pDiagram.setDocumentation(str);
0505:                            }
0506:                        }
0507:                    }
0508:                }
0509:
0510:            }
0511:
0512:            /* (non-Javadoc)
0513:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getSearchAlias()
0514:             */
0515:            public boolean getSearchAlias() {
0516:                return m_SearchAlias;
0517:            }
0518:
0519:            /* (non-Javadoc)
0520:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setSearchAlias(int)
0521:             */
0522:            public void setSearchAlias(boolean value) {
0523:                m_SearchAlias = value;
0524:            }
0525:
0526:            /* (non-Javadoc)
0527:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#search2(com.embarcadero.describe.structure.IProject, org.netbeans.modules.uml.ui.support.finddialog.IFindResults)
0528:             */
0529:            public void search2(IProject pProject, IFindResults pResults) {
0530:                m_Project = pProject;
0531:                search(pResults);
0532:            }
0533:
0534:            /* (non-Javadoc)
0535:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#navigateToDiagram(org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram)
0536:             */
0537:            public boolean navigateToDiagram(IProxyDiagram pDiagram) {
0538:                boolean result = true;
0539:                // get the core product
0540:                if (m_DiagramNavigate) {
0541:                    FindUtilities.startWaitCursor(m_Dialog);
0542:                    if (pDiagram != null) {
0543:                        IProduct pProduct = ProductHelper.getProduct();
0544:                        if (pProduct != null) {
0545:                            IProductDiagramManager pManager = pProduct
0546:                                    .getDiagramManager();
0547:                            if (pManager != null) {
0548:                                pManager.openDiagram2(pDiagram, true, null);
0549:                            }
0550:                        }
0551:                    }
0552:                    FindUtilities.endWaitCursor(m_Dialog);
0553:                }
0554:                return result;
0555:            }
0556:
0557:            /* (non-Javadoc)
0558:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getExternalLoad()
0559:             */
0560:            public boolean getExternalLoad() {
0561:                return m_ExternalLoad;
0562:            }
0563:
0564:            /* (non-Javadoc)
0565:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setExternalLoad(int)
0566:             */
0567:            public void setExternalLoad(boolean value) {
0568:                m_ExternalLoad = value;
0569:            }
0570:
0571:            /* (non-Javadoc)
0572:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getCancelled()
0573:             */
0574:            public boolean getCancelled() {
0575:                return m_Cancelled;
0576:            }
0577:
0578:            /* (non-Javadoc)
0579:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setCancelled(int)
0580:             */
0581:            public void setCancelled(boolean value) {
0582:                m_Cancelled = value;
0583:            }
0584:
0585:            /* (non-Javadoc)
0586:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getActiveWindow()
0587:             */
0588:            public long getActiveWindow() {
0589:                return m_ActiveWindow;
0590:            }
0591:
0592:            /* (non-Javadoc)
0593:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setActiveWindow(int)
0594:             */
0595:            public void setActiveWindow(long value) {
0596:                m_ActiveWindow = value;
0597:            }
0598:
0599:            /* (non-Javadoc)
0600:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getWholeWordSearch()
0601:             */
0602:            public boolean getWholeWordSearch() {
0603:                return m_WholeWordSearch;
0604:            }
0605:
0606:            /* (non-Javadoc)
0607:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setWholeWordSearch(int)
0608:             */
0609:            public void setWholeWordSearch(boolean value) {
0610:                m_WholeWordSearch = value;
0611:            }
0612:
0613:            /* (non-Javadoc)
0614:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#getDiagramNavigate()
0615:             */
0616:            public boolean getDiagramNavigate() {
0617:                return m_DiagramNavigate;
0618:            }
0619:
0620:            /* (non-Javadoc)
0621:             * @see org.netbeans.modules.uml.ui.support.finddialog.IFindController#setDiagramNavigate(int)
0622:             */
0623:            public void setDiagramNavigate(boolean value) {
0624:                m_DiagramNavigate = value;
0625:            }
0626:
0627:            public boolean searchUsingElementLocator(String searchString,
0628:                    IFindResults pResults) {
0629:                boolean flag = true;
0630:                if (searchString != null && searchString.length() > 0) {
0631:                    // if the user has unchecked the case sensitive flag, the search may take awhile
0632:                    // due to using //* in the ElementLocator
0633:                    // warn the user
0634:                    boolean bContinue = warnUserAboutTime();
0635:                    if (bContinue) {
0636:                        if (!m_CaseSensitive) {
0637:                            // TODO
0638:                            //HANDLE event = CreateEvent(NULL, TRUE, FALSE, _T("FINDDLG"));
0639:                            //MyWaitDlgThread *thread = (MyWaitDlgThread *)AfxBeginThread(RUNTIME_CLASS(MyWaitDlgThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
0640:                            //thread->m_Eventname = "FINDDLG";
0641:                            //thread->m_FindController = this;
0642:                            //if (::AfxGetMainWnd())
0643:                            //{
0644:                            //   thread->m_AlternateHWNDOwner = ::AfxGetMainWnd()->m_hWnd;
0645:                            //}
0646:                            //thread->ResumeThread();
0647:                            m_Cancelled = false;
0648:                            //while ((WaitForSingleObject(event, 0)==WAIT_TIMEOUT) && (m_Cancelled == false))
0649:                            while (!m_Cancelled) {
0650:                                if (!searchUsingElementLocator2(searchString,
0651:                                        pResults)) {
0652:                                    m_Cancelled = true;
0653:                                }
0654:                                break;
0655:                            }
0656:                            //if (thread)
0657:                            //{
0658:                            //thread->m_bCloseDialog = TRUE;
0659:                            //}
0660:                            //if (m_Cancelled)
0661:                            //{
0662:                            // pResults->put_Elements(0);
0663:                            //}                    					
0664:                        } else {
0665:                            searchUsingElementLocator2(searchString, pResults);
0666:                        }
0667:                    } else {
0668:                        // return S_FALSE then the user was asked about something
0669:                        // and they said not to continue
0670:                        flag = false;
0671:                    }
0672:                }
0673:                return flag;
0674:            }
0675:
0676:            public boolean searchUsingElementLocator2(String searchString,
0677:                    IFindResults pResults) {
0678:                boolean flag = true;
0679:                if (searchString != null && searchString.length() > 0) {
0680:                    if (m_Project != null) {
0681:                        flag = searchUsingElementLocatorForProject(
0682:                                searchString, m_Project, pResults);
0683:                    } else {
0684:                        // get the right projects - this will either be all of the projects in the workspace if the user chose
0685:                        // workspace, or the projects that they told us to look through
0686:                        ETList<IWSProject> pProjects = getProjects(true);
0687:                        if (pProjects != null) {
0688:                            // loop through the projects that we determined were the correct ones
0689:                            int count = pProjects.size();
0690:                            for (int x = 0; x < count; x++) {
0691:                                if (m_Cancelled) {
0692:                                    break;
0693:                                }
0694:                                IWSProject wsProject = pProjects.get(x);
0695:                                if (wsProject != null) {
0696:                                    // need to get the IProject, not the WSProject in order to use the element locator
0697:                                    String name = wsProject.getName();
0698:                                    IApplication pApp = ProductHelper
0699:                                            .getApplication();
0700:                                    if (pApp != null) {
0701:                                        IProject pProject = pApp
0702:                                                .getProjectByName(name);
0703:                                        if (pProject != null) {
0704:                                            flag = searchUsingElementLocatorForProject(
0705:                                                    searchString, pProject,
0706:                                                    pResults);
0707:                                        }
0708:                                    }
0709:                                }
0710:                            }
0711:                        }
0712:                    }
0713:                }
0714:                return flag;
0715:            }
0716:
0717:            public boolean searchUsingElementLocatorForProject(
0718:                    String searchString, IProject pProject,
0719:                    IFindResults pResults) {
0720:                boolean flag = true;
0721:                if (searchString != null && searchString.length() > 0) {
0722:                    if (m_Cancelled) {
0723:                        flag = false;
0724:                        return flag;
0725:                    }
0726:                    if (m_ExternalLoad) {
0727:                        ITypeManager typeMan = pProject.getTypeManager();
0728:                        if (typeMan != null) {
0729:                            typeMan.loadExternalElements();
0730:                        }
0731:                    }
0732:                    //
0733:                    // Get the elements from the results object.  This will be what we add to
0734:                    //
0735:                    ETList<IElement> pTempElements = pResults.getElements();
0736:                    if (pTempElements != null) {
0737:                        // find the elements matching the string
0738:                        IElementLocator pLocator = new ElementLocator();
0739:                        if (pLocator != null) {
0740:                            if (pProject instanceof  INamespace) {
0741:                                INamespace pNamespace = (INamespace) pProject;
0742:                                ETList<IElement> pElements = pLocator
0743:                                        .findElementsByDeepQuery(pNamespace,
0744:                                                searchString);
0745:                                if (pElements != null) {
0746:                                    // loop through the found elements
0747:                                    int eleCount = pElements.size();
0748:                                    for (int y = 0; y < eleCount; y++) {
0749:                                        if (m_Cancelled) {
0750:                                            flag = false;
0751:                                            break;
0752:                                        }
0753:                                        IElement pElement = pElements.get(y);
0754:                                        if (pElement != null) {
0755:                                            boolean add = true;
0756:                                            if (pElement instanceof  ITaggedValue) {
0757:                                                ITaggedValue pTV = (ITaggedValue) pElement;
0758:                                                if (pTV != null) {
0759:                                                    // don't want to include a tagged value of type documentation
0760:                                                    String name = pTV.getName();
0761:                                                    if (name
0762:                                                            .equals("documentation")) {
0763:                                                        add = false;
0764:                                                    }
0765:                                                    // also don't want to include hidden tagged values
0766:                                                    boolean bHidden = pTV
0767:                                                            .isHidden();
0768:                                                    if (bHidden) {
0769:                                                        add = false;
0770:                                                    }
0771:                                                }
0772:                                            }
0773:                                            if (add) {
0774:                                                pTempElements.add(pElement);
0775:                                            }
0776:                                        }
0777:                                    }
0778:                                }
0779:                            }
0780:                        }
0781:                    }
0782:                }
0783:                return flag;
0784:            }
0785:
0786:            public void searchWithWildcard(IFindResults pResults) {
0787:                // where is the wildcard located in the string - the first, last, or somewhere in the middle
0788:                //WildcardLocation loc = GetLocationOfWildcard(m_SearchString);
0789:                int loc = getLocationOfWildcard(m_SearchString);
0790:                if ((loc == 1/*WILDCARD_LOC_LAST*/)
0791:                        || (loc == 0/*WILDCARD_LOC_FIRST*/)) {
0792:                    // if the wildcard is the first or last character, we can remove it, and then begin the search
0793:                    String toMatch = m_SearchString;
0794:                    toMatch.replace('*', ' ');
0795:                    String search = toMatch;
0796:                    if (m_CaseSensitive) {
0797:                        // if we are case sensitive, we can use the element locator on a much narrower search
0798:                        String tempStr;
0799:                        if ((m_ResultType == 0)/*FIND_TYPE_ELEMENT)*/
0800:                                || (m_SearchAlias)) {
0801:                            tempStr = buildXPathString(m_SearchString);
0802:                        } else {
0803:                            tempStr = "//*";
0804:                        }
0805:                        // if this search has returned S_FALSE then the user was asked about something
0806:                        // and they said not to continue
0807:                        if (searchUsingElementLocator(tempStr, pResults)) {
0808:                            searchForDiagrams(tempStr, pResults);
0809:                            process(search, loc, pResults);
0810:                        }
0811:                    } else {
0812:                        // since we are not case sensitive, we have to get all of the elements and then do more
0813:                        // processing on their name
0814:                        String tempStr = "//*";
0815:                        // if this search has returned S_FALSE then the user was asked about something
0816:                        // and they said not to continue
0817:                        if (searchUsingElementLocator(tempStr, pResults)) {
0818:                            searchForDiagrams(tempStr, pResults);
0819:                            process(search, loc, pResults);
0820:                        }
0821:                    }
0822:                } else if (loc == 2/*WILDCARD_LOC_MIDDLE*/) {
0823:                    String tempStr = "//*";
0824:                    // if this search has returned S_FALSE then the user was asked about something
0825:                    // and they said not to continue
0826:                    if (searchUsingElementLocator(tempStr, pResults)) {
0827:                        searchForDiagrams(tempStr, pResults);
0828:                        process(m_SearchString, loc, pResults);
0829:                    }
0830:                }
0831:            }
0832:
0833:            public boolean findInDiagrams(IElement pElement) {
0834:                boolean result = true;
0835:                if (pElement != null) {
0836:                    FindUtilities.startWaitCursor(m_Dialog);
0837:                    // get the core product
0838:                    IProduct pProduct = ProductHelper.getProduct();
0839:                    if (pProduct != null) {
0840:                        // get the presentation finder off of the IProduct
0841:                        PresentationFinder pPresentationFinder = new PresentationFinder();
0842:                        if (pPresentationFinder != null) {
0843:                            // find in diagrams
0844:                            ETList<IPresentationTarget> pPresentationTargets = null;
0845:                            if (pElement instanceof  IActor) {
0846:                                pPresentationTargets = pPresentationFinder
0847:                                        .getPresentationTargets(pElement);
0848:                            } else if (pElement instanceof  IFeature) {
0849:                                IFeature pFeature = (IFeature) pElement;
0850:                                if (pFeature != null) {
0851:                                    IClassifier pClassifier = pFeature
0852:                                            .getFeaturingClassifier();
0853:                                    if (pClassifier != null) {
0854:                                        pPresentationTargets = pPresentationFinder
0855:                                                .getPresentationTargets(pClassifier);
0856:                                    }
0857:                                }
0858:                            } else {
0859:                                pPresentationTargets = pPresentationFinder
0860:                                        .getPresentationTargets(pElement);
0861:                            }
0862:                            if (pPresentationTargets != null) {
0863:                                int count = pPresentationTargets.size();
0864:                                if (count > 0) {
0865:                                    IDiagramAndPresentationNavigator pNavigator = new DiagramAndPresentationNavigator();
0866:                                    if (pNavigator != null) {
0867:                                        boolean bHandled = pNavigator
0868:                                                .navigateToPresentationTarget(
0869:                                                        0, pElement,
0870:                                                        pPresentationTargets);
0871:                                    }
0872:                                } else {
0873:                                    result = false;
0874:                                }
0875:                            } else {
0876:                                result = false;
0877:                            }
0878:                        }
0879:                    }
0880:                    FindUtilities.endWaitCursor(m_Dialog);
0881:                }
0882:                return result;
0883:            }
0884:
0885:            public ETList<IWSProject> getProjects(boolean bAskAboutUnopened) {
0886:                // TODO Right now getting all projects - see c++ for details
0887:                // get the workspace from the core product
0888:                ETList<IWSProject> pProjects = new ETArrayList<IWSProject>();
0889:                try {
0890:                    IWorkspace pWorkspace = ProductHelper.getWorkspace();
0891:                    if (pWorkspace != null) {
0892:                        // get all of the projects in the workspace
0893:                        ETList<IWSProject> wsProjects = pWorkspace
0894:                                .getWSProjects();
0895:                        if (wsProjects != null) {
0896:                            ETList<IWSProject> unopened = new ETArrayList<IWSProject>();
0897:                            // loop through the list of projects in the workspace
0898:                            int count = wsProjects.size();
0899:                            for (int x = 0; x < count; x++) {
0900:                                IWSProject wsProject = wsProjects.get(x);
0901:                                if (wsProject != null) {
0902:                                    // if they have chosen to search the workspace, add the project, no questions asked
0903:                                    if (m_Scope == 1/*FIND_SCOPE_WORKSPACE*/) {
0904:                                        boolean isOpen = wsProject.isOpen();
0905:                                        if (isOpen) {
0906:                                            pProjects.add(wsProject);
0907:                                        } else {
0908:                                            unopened.add(wsProject);
0909:                                        }
0910:                                    } else {
0911:                                        // they have chosen to search by project, they may have more than one project selected
0912:                                        // so we need to check what they have selected
0913:                                        String name = wsProject.getName();
0914:                                        if (name.length() > 0) {
0915:                                            // check the list of projects that they have selected
0916:                                            for (int x2 = 0; x2 < m_Projects
0917:                                                    .size(); x2++) {
0918:                                                Object obj = m_Projects.get(x2);
0919:                                                if (obj instanceof  String) {
0920:                                                    String projName = (String) obj;
0921:                                                    if (projName.equals(name)) {
0922:                                                        // have it selected, so add it to our list
0923:                                                        boolean isOpen = wsProject
0924:                                                                .isOpen();
0925:                                                        if (isOpen) {
0926:                                                            pProjects
0927:                                                                    .add(wsProject);
0928:                                                        } else {
0929:                                                            unopened
0930:                                                                    .add(wsProject);
0931:                                                        }
0932:                                                        break;
0933:                                                    }
0934:                                                }
0935:                                            }
0936:                                        }
0937:                                    }
0938:                                }
0939:                            }
0940:                            // we may have had some projects that were not open, those have been stored in
0941:                            // an array, and we need to ask the user if they want to open them.
0942:                            int unopenedCnt = unopened.size();
0943:                            if (unopenedCnt > 0) {
0944:                                String projList = "";
0945:                                for (int y = 0; y < unopenedCnt; y++) {
0946:                                    IWSProject wsProject = unopened.get(y);
0947:                                    if (wsProject != null) {
0948:                                        String temp = wsProject.getName();
0949:                                        if (y > 0) {
0950:                                            projList += "\n";
0951:                                        }
0952:                                        projList += temp;
0953:                                    }
0954:                                }
0955:                                int nResult = -1;
0956:                                if (bAskAboutUnopened) {
0957:                                    IPreferenceQuestionDialog cpDialog = new SwingPreferenceQuestionDialog(
0958:                                            m_Dialog);
0959:                                    if (cpDialog != null) {
0960:                                        String title = FindUtilities
0961:                                                .translateString("IDS_PROJNAME2");
0962:                                        String msg = FindUtilities
0963:                                                .translateString("IDS_UNOPENEDPROJECTS");
0964:                                        String fmsg = StringUtilities
0965:                                                .replaceSubString(msg, "%s",
0966:                                                        projList);
0967:                                        nResult = cpDialog
0968:                                                .displayFromStrings(
0969:                                                        "Default",
0970:                                                        "FindDialog",
0971:                                                        "OpenClosedProjects",
0972:                                                        "PSK_ALWAYS",
0973:                                                        "PSK_NEVER",
0974:                                                        "PSK_ASK",
0975:                                                        fmsg,
0976:                                                        SimpleQuestionDialogResultKind.SQDRK_RESULT_NO,
0977:                                                        title,
0978:                                                        SimpleQuestionDialogKind.SQDK_YESNO,
0979:                                                        MessageIconKindEnum.EDIK_ICONQUESTION,
0980:                                                        null);
0981:                                    }
0982:                                    if (nResult == SimpleQuestionDialogResultKind.SQDRK_RESULT_YES) {
0983:                                        for (int y = 0; y < unopenedCnt; y++) {
0984:                                            IWSProject wsProject = unopened
0985:                                                    .get(y);
0986:                                            if (wsProject != null) {
0987:                                                wsProject.open();
0988:                                                pProjects.add(wsProject);
0989:                                            }
0990:                                        }
0991:                                    }
0992:                                }
0993:                            }
0994:                        }
0995:                    }
0996:                } catch (Exception e) {
0997:                }
0998:                return pProjects;
0999:            }
1000:
1001:            public String buildXPathString(String searchString) {
1002:                String rv = "";
1003:                if (searchString != null) {
1004:                    String str = searchString;
1005:                    if (searchString.indexOf('*') == 0) {
1006:                        // if the wildcard is the first character
1007:                        String str2 = searchString.equals("*") ? "" : str
1008:                                .substring(1, str.length() - 1);
1009:                        // if the wildcard is the last character
1010:                        if (!m_IsReplace) {
1011:                            rv = "//*[contains(@name, \"";
1012:                            rv += str2;
1013:                            rv += "\")";
1014:                            if (m_SearchAlias) {
1015:                                rv += " or contains(@alias, \"";
1016:                                rv += str2;
1017:                                rv += "\")";
1018:                            }
1019:                            rv += "]";
1020:                        } else {
1021:                            // doing a replace
1022:                            if (m_SearchAlias) {
1023:                                rv = "//*[contains(@alias, \"";
1024:                                rv += str2;
1025:                                rv += "\")]";
1026:                            } else if (m_ResultType == 0/*FIND_TYPE_ELEMENT*/) {
1027:                                rv = "//*[contains(@name, \"";
1028:                                rv += str2;
1029:                                rv += "\")]";
1030:                            } else {
1031:                            }
1032:                        }
1033:                    } else {
1034:                        int last = str.length() - 1;
1035:                        if (str.indexOf('*') == last) {
1036:                            String str2 = str.substring(0, last - 1);
1037:                            if (!m_IsReplace) {
1038:                                // if the wildcard is the last character
1039:                                rv = "//*[starts-with(@name, \"";
1040:                                rv += str2;
1041:                                rv += "\")";
1042:                                if (m_SearchAlias) {
1043:                                    rv += " or starts-with(@alias, \"";
1044:                                    rv += str2;
1045:                                    rv += "\")";
1046:                                }
1047:                                rv += "]";
1048:                            } else {
1049:                                // doing a replace
1050:                                if (m_SearchAlias) {
1051:                                    rv = "//*[starts-with(@alias, \"";
1052:                                    rv += str2;
1053:                                    rv += "\")]";
1054:                                } else if (m_ResultType == 0/*FIND_TYPE_ELEMENT*/) {
1055:                                    rv = "//*[starts-with(@name, \"";
1056:                                    rv += str2;
1057:                                    rv += "\")]";
1058:                                } else {
1059:                                }
1060:                            }
1061:                        } else {
1062:                        }
1063:                    }
1064:                }
1065:                return rv;
1066:            }
1067:
1068:            public int getLocationOfWildcard(String searchString) {
1069:                int loc = -1;
1070:                if (searchString != null) {
1071:                    if (searchString.indexOf('*') == 0) {
1072:                        loc = 0; // WILDCARD_LOC_FIRST
1073:                    } else {
1074:                        int last = searchString.length() - 1;
1075:                        if (searchString.indexOf('*') == last) {
1076:                            loc = 1; // WILDCARD_LOC_LAST
1077:                        } else {
1078:                            loc = 2; // WILDCARD_LOC_MIDDLE
1079:                        }
1080:                    }
1081:                }
1082:                return loc;
1083:            }
1084:
1085:            public void process(String toMatch, int wildcardLoc,
1086:                    IFindResults pResults) {
1087:                if (pResults != null) {
1088:                    processElements(toMatch, wildcardLoc, pResults);
1089:                    processDiagrams(toMatch, wildcardLoc, pResults);
1090:                }
1091:            }
1092:
1093:            public void processElements(String toMatch, int wildcardLoc,
1094:                    IFindResults pResults) {
1095:                if (toMatch != null && pResults != null) {
1096:                    // get the elements from the results object
1097:                    ETList<IElement> tempElements = pResults.getElements();
1098:                    if (tempElements != null) {
1099:                        // loop through the elements that we think might be a match
1100:                        int count = tempElements.size();
1101:                        for (int x = count - 1; x >= 0; x--) {
1102:                            if (m_Cancelled) {
1103:                                break;
1104:                            }
1105:                            IElement pElement = tempElements.get(x);
1106:                            if (pElement != null) {
1107:                                String value = getValueToUse(pElement);
1108:                                if (value != null && value.length() > 0) {
1109:                                    boolean bSame = compareValues(toMatch,
1110:                                            value, wildcardLoc);
1111:                                    if (!(bSame)) {
1112:                                        // it didn't make it into the found elements yet because of its name or documentation
1113:                                        // see if the user wanted to also search the alias field
1114:                                        if (m_SearchAlias && !m_IsReplace) {
1115:                                            if (pElement instanceof  INamedElement) {
1116:                                                INamedElement pNamedElement = (INamedElement) pElement;
1117:                                                if (pNamedElement != null) {
1118:                                                    String alias = pNamedElement
1119:                                                            .getAlias();
1120:                                                    boolean bValid2 = compareValues(
1121:                                                            toMatch, alias,
1122:                                                            wildcardLoc);
1123:                                                    if (!(bValid2)) {
1124:                                                        // did not match, so remove it
1125:                                                        tempElements.remove(x);
1126:                                                    }
1127:                                                }
1128:                                            }
1129:                                        } else {
1130:                                            tempElements.remove(x);
1131:                                        }
1132:                                    }
1133:                                } else {
1134:                                    tempElements.remove(x);
1135:                                }
1136:                            }
1137:                        }
1138:                    }
1139:                }
1140:            }
1141:
1142:            public void processDiagrams(String toMatch, int wildcardLoc,
1143:                    IFindResults pResults) {
1144:                if (toMatch != null && pResults != null) {
1145:                    String toMatch2 = toMatch;
1146:                    // get the diagrams from the results object
1147:                    ETList<IProxyDiagram> pDiagrams = pResults.getDiagrams();
1148:                    if (pDiagrams != null) {
1149:                        // loop through the diagrams
1150:                        int count = pDiagrams.size();
1151:                        for (int x = count - 1; x >= 0; x--) {
1152:                            IProxyDiagram pDiagram = pDiagrams.get(x);
1153:                            if (pDiagram != null) {
1154:                                // are we in the replace dialog
1155:                                String str = "";
1156:                                if (!m_IsReplace) {
1157:                                    // no, in the find dialog, so get the name or the documentation of the diagram
1158:                                    if (m_ResultType == 0/*FIND_TYPE_ELEMENT*/) {
1159:                                        str = pDiagram.getName();
1160:                                    } else {
1161:                                        str = pDiagram.getDocumentation();
1162:                                    }
1163:                                    // had a problem where str was coming back null
1164:                                    if (str == null) {
1165:                                        str = "";
1166:                                    }
1167:                                    // should it be case sensitive
1168:                                    String str2 = str;
1169:                                    if (!m_CaseSensitive) {
1170:                                        str2 = str.toLowerCase();
1171:                                        toMatch2 = toMatch.toLowerCase();
1172:                                    }
1173:                                    // determine if the info matches the passed in string
1174:                                    boolean valid = process2(toMatch2, str2,
1175:                                            wildcardLoc);
1176:                                    if (!valid) {
1177:                                        // it didn't make it into the found elements yet because of its name or documentation
1178:                                        // see if the user wanted to also search the alias field
1179:                                        if (m_SearchAlias) {
1180:                                            // we aren't doing this check yet, because diagrams don't have an alias
1181:                                            // property, but leaving it here, so when they do we can use it
1182:                                            String alias = pDiagram.getAlias();
1183:                                            if (alias == null) {
1184:                                                alias = "";
1185:                                            }
1186:                                            String alias2 = alias;
1187:                                            if (!m_CaseSensitive) {
1188:                                                alias2 = alias.toLowerCase();
1189:                                            }
1190:                                            // determine if the info matches the passed in string
1191:                                            boolean valid2 = process2(toMatch2,
1192:                                                    alias2, wildcardLoc);
1193:                                            if (!valid2) {
1194:                                                // does not, so remove it
1195:                                                pDiagrams.remove(x);
1196:                                            }
1197:                                        } else {
1198:                                            // does not, so remove it
1199:                                            pDiagrams.remove(x);
1200:                                        }
1201:                                    }
1202:                                } else {
1203:                                    // in the replace dialog, so get the name or the documentation of the diagram
1204:                                    if (m_ResultType == 0/*FIND_TYPE_ELEMENT*/) {
1205:                                        str = pDiagram.getName();
1206:                                    } else if (m_SearchAlias) {
1207:                                        str = pDiagram.getAlias();
1208:                                    } else {
1209:                                        str = pDiagram.getDocumentation();
1210:                                    }
1211:                                    // should it be case sensitive
1212:                                    if (str == null) {
1213:                                        str = "";
1214:                                    }
1215:                                    String str2 = str;
1216:                                    if (!m_CaseSensitive) {
1217:                                        str2 = str.toLowerCase();
1218:                                        toMatch2 = toMatch.toLowerCase();
1219:                                    }
1220:                                    // determine if the info matches the passed in string
1221:                                    boolean valid = process2(toMatch2, str2,
1222:                                            wildcardLoc);
1223:                                    if (!valid) {
1224:                                        // does not, so remove it
1225:                                        pDiagrams.remove(x);
1226:                                    }
1227:                                }
1228:                            }
1229:                        }
1230:                    }
1231:                }
1232:            }
1233:
1234:            public boolean process2(String toMatch, String value,
1235:                    int wildcardLoc) {
1236:                boolean rv = false;
1237:                if (toMatch != null && value != null) {
1238:                    if (wildcardLoc == -1/*WILDCARD_LOC_UNKNOWN*/) {
1239:                        // if not doing a whole word search then just look for what was typed in in what
1240:                        // was passed in
1241:                        if (!m_WholeWordSearch) {
1242:                            if (value.indexOf(toMatch) > -1) {
1243:                                rv = true;
1244:                            }
1245:                        } else {
1246:                            // we are doing a whole word search
1247:                            int pos = value.indexOf(toMatch);
1248:                            if ((pos > -1)
1249:                                    && ((toMatch.length() == value.length()))) {
1250:                                // if we found the substring in the string and the substring and string length is
1251:                                // the same
1252:                                rv = true;
1253:                            } else if (pos > -1) {
1254:                                boolean bFirst = false;
1255:                                if (pos == 0) {
1256:                                    bFirst = true;
1257:                                }
1258:                                boolean bLast = false;
1259:                                if (pos + toMatch.length() == value.length()) {
1260:                                    bLast = true;
1261:                                }
1262:
1263:                                if (bLast) {
1264:                                    char charBefore = value.charAt(pos - 1);
1265:                                    if (charBefore == ' ') {
1266:                                        rv = true;
1267:                                    }
1268:                                } else if (bFirst) {
1269:                                    char charAfter = value.charAt(pos
1270:                                            + toMatch.length());
1271:                                    if (charAfter == ' ') {
1272:                                        rv = true;
1273:                                    }
1274:                                } else {
1275:                                    if (pos + toMatch.length() < value.length()) {
1276:                                        char charBefore = value.charAt(pos - 1);
1277:                                        char charAfter = value.charAt(pos
1278:                                                + toMatch.length());
1279:                                        if ((charBefore == ' ')
1280:                                                && (charAfter == ' ')) {
1281:                                            rv = true;
1282:                                        }
1283:                                    }
1284:                                }
1285:                            }
1286:                        }
1287:                    } else if (wildcardLoc == 1/*WILDCARD_LOC_LAST*/) {
1288:                        if (value.indexOf(toMatch) == 0) {
1289:                            rv = true;
1290:                        }
1291:                    } else if (wildcardLoc == 0/*WILDCARD_LOC_FIRST*/) {
1292:                        int len = value.length();
1293:                        int found = value.indexOf(toMatch);
1294:                        if (found > -1) {
1295:                            if (len - found == toMatch.length()) {
1296:                                rv = true;
1297:                            }
1298:                        }
1299:                    } else if (wildcardLoc == 2/*WILDCARD_LOC_MIDDLE*/) {
1300:                        int len = value.length();
1301:                        int found = toMatch.indexOf('*');
1302:                        String first = toMatch.substring(0, found - 1);
1303:                        if (value.indexOf(first) == 0) {
1304:                            String second = toMatch.substring(found + 1,
1305:                                    toMatch.length() - 1);
1306:                            int found2 = value.indexOf(second);
1307:                            if (found2 > -1) {
1308:                                if (len - found2 == second.length()) {
1309:                                    rv = true;
1310:                                }
1311:                            }
1312:                        }
1313:                    }
1314:                }
1315:                return rv;
1316:            }
1317:
1318:            public void searchForDiagrams(String searchString,
1319:                    IFindResults pResults) {
1320:                if (pResults != null) {
1321:                    if (searchString != null && searchString.length() > 0) {
1322:                        // if we have a project, then we do not need to figure out which ones to search
1323:                        if (m_Project != null) {
1324:                            searchForDiagrams2(searchString, m_Project,
1325:                                    pResults);
1326:                        } else {
1327:                            // get the application
1328:                            IApplication pApp = ProductHelper.getApplication();
1329:                            if (pApp != null) {
1330:                                // get the right projects - this will either be all of the projects in the workspace if the user chose
1331:                                // workspace, or the projects that they told us to look through
1332:                                ETList<IWSProject> pProjects = getProjects(false);
1333:                                if (pProjects != null) {
1334:                                    // loop through the projects that we determined were the correct ones
1335:                                    int count = pProjects.size();
1336:                                    for (int x = 0; x < count; x++) {
1337:                                        IWSProject wsProject = pProjects.get(x);
1338:                                        if (wsProject != null) {
1339:                                            // need to get the IProject, not the WSProject in order to use the element locator
1340:                                            String name = wsProject.getName();
1341:                                            IProject pProject = pApp
1342:                                                    .getProjectByName(name);
1343:                                            if (pProject != null) {
1344:                                                searchForDiagrams2(
1345:                                                        searchString, pProject,
1346:                                                        pResults);
1347:                                            }
1348:                                        }
1349:                                    }
1350:                                }
1351:                            }
1352:                        }
1353:                    }
1354:                }
1355:            }
1356:
1357:            public void searchForDiagrams2(String searchString,
1358:                    IProject pProject, IFindResults pResults) {
1359:                if ((pProject != null) && (pResults != null)) {
1360:                    if (searchString != null && searchString.length() > 0) {
1361:                        // get the diagrams from the results object - this will be the array that gets added to
1362:                        ETList<IProxyDiagram> pDiags = pResults.getDiagrams();
1363:                        if (pDiags != null) {
1364:                            IProxyDiagramManager pDiagManager = ProxyDiagramManager
1365:                                    .instance();
1366:                            if (pDiagManager != null) {
1367:                                // add all diagrams in this project to our array, it will be filtered out
1368:                                // later
1369:                                ETList<IProxyDiagram> pTempDiagrams = pDiagManager
1370:                                        .getDiagramsInDirectory(pProject);
1371:                                if (pTempDiagrams != null) {
1372:                                    int dcount = pTempDiagrams.size();
1373:                                    for (int x = 0; x < dcount; x++) {
1374:                                        IProxyDiagram pDiagram = pTempDiagrams
1375:                                                .get(x);
1376:                                        if (pDiagram != null) {
1377:                                            pDiags.add(pDiagram);
1378:                                        }
1379:                                    }
1380:                                }
1381:                            }
1382:                        }
1383:                    }
1384:                }
1385:            }
1386:
1387:            public boolean warnUserAboutTime() {
1388:                boolean bContinue = true;
1389:                if (!m_CaseSensitive) {
1390:                    IPreferenceQuestionDialog pDialog = new SwingPreferenceQuestionDialog(
1391:                            m_Dialog);
1392:                    if (pDialog != null) {
1393:                        String title = FindUtilities
1394:                                .translateString("IDS_PROJNAME2");
1395:                        String msg = FindUtilities
1396:                                .translateString("IDS_LONGTIME");
1397:                        int result = pDialog.displayFromStrings("Default",
1398:                                "FindDialog",
1399:                                "UML_ShowMe_Allow_Lengthy_Searches",
1400:                                "PSK_ALWAYS", "PSK_NEVER", "PSK_ASK", msg,
1401:                                SimpleQuestionDialogResultKind.SQDRK_RESULT_NO,
1402:                                title, SimpleQuestionDialogKind.SQDK_YESNO,
1403:                                MessageIconKindEnum.EDIK_ICONQUESTION, null);
1404:                        if (result != SimpleQuestionDialogResultKind.SQDRK_RESULT_YES) {
1405:                            bContinue = false;
1406:                        }
1407:                    }
1408:                }
1409:                return bContinue;
1410:            }
1411:
1412:            public String getValueToUse(IElement pElement) {
1413:                String value = "";
1414:                if (pElement != null) {
1415:                    boolean flag = true;
1416:                    if (m_IsReplace) {
1417:                        if (pElement instanceof  IProject) {
1418:                            flag = false;
1419:                        }
1420:                    }
1421:                    if (flag) {
1422:                        if (m_ResultType == 0)//FIND_TYPE_ELEMENT)
1423:                        {
1424:                            if (pElement instanceof  INamedElement) {
1425:                                INamedElement pNamedElement = (INamedElement) pElement;
1426:                                if (pNamedElement != null) {
1427:                                    value = pNamedElement.getName();
1428:                                }
1429:                            }
1430:                        } else if (m_SearchAlias) {
1431:                            if (pElement instanceof  INamedElement) {
1432:                                INamedElement pNamedElement = (INamedElement) pElement;
1433:                                if (pNamedElement != null) {
1434:                                    value = pNamedElement.getAlias();
1435:                                }
1436:                            }
1437:                        } else {
1438:                            value = pElement.getDocumentation();
1439:                            if (value == null) {
1440:                                value = "";
1441:                            }
1442:                        }
1443:                    }
1444:                }
1445:                return value;
1446:            }
1447:
1448:            public boolean compareValues(String toMatch, String value,
1449:                    int wildcardLoc) {
1450:                boolean bSame = false;
1451:                if (toMatch != null && value != null) {
1452:                    // are we case sensitive or not
1453:                    String toMatch2 = toMatch;
1454:                    String value2 = value;
1455:                    if (!m_CaseSensitive) {
1456:                        value2 = value2.toLowerCase();
1457:                        toMatch2 = toMatch2.toLowerCase();
1458:                    }
1459:                    // determine if the current element matches the passed in string
1460:                    boolean bValid = process2(toMatch2, value2, wildcardLoc);
1461:                    if (bValid) {
1462:                        bSame = true;
1463:                    }
1464:                }
1465:                return bSame;
1466:            }
1467:
1468:            public String replaceValue(String value) {
1469:                String newValue = "";
1470:                if (value != null) {
1471:                    newValue = value;
1472:                    if (!m_CaseSensitive) {
1473:                        // Compile with case-insensitivity
1474:                        Pattern pattern = Pattern.compile(m_SearchString,
1475:                                Pattern.CASE_INSENSITIVE);
1476:                        Matcher matcher = pattern.matcher(value);
1477:                        newValue = matcher.replaceAll(m_ReplaceString);
1478:                    } else {
1479:                        // Compile with case-sensitivity
1480:                        Pattern pattern = Pattern.compile(m_SearchString);
1481:                        Matcher matcher = pattern.matcher(value);
1482:                        newValue = matcher.replaceAll(m_ReplaceString);
1483:                    }
1484:                }
1485:                return newValue;
1486:            }
1487:        }
www___.___j_a_v___a___2__s_.___c___o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.