List of usage examples for java.util TreeSet iterator
public Iterator<E> iterator()
From source file:org.dasein.cloud.vcloud.compute.vAppSupport.java
private @Nullable VirtualMachine toVirtualMachine(@Nonnull String vdcId, @Nonnull String parentVAppId, @Nonnull Node vmNode, @Nonnull Iterable<VLAN> vlans) throws CloudException, InternalException { Node n = vmNode.getAttributes().getNamedItem("href"); VirtualMachine vm = new VirtualMachine(); vm.setProviderMachineImageId("unknown"); vm.setArchitecture(Architecture.I64); vm.setClonable(true);//from ww w .ja v a 2s .c o m vm.setCreationTimestamp(0L); vm.setCurrentState(VmState.PENDING); vm.setImagable(true); vm.setLastBootTimestamp(0L); vm.setLastPauseTimestamp(0L); vm.setPausable(false); vm.setPersistent(true); vm.setPlatform(Platform.UNKNOWN); vm.setProviderOwnerId(getContext().getAccountNumber()); vm.setRebootable(true); vm.setProviderRegionId(getContext().getRegionId()); vm.setProviderDataCenterId(vdcId); if (n != null) { vm.setProviderVirtualMachineId((getProvider()).toID(n.getNodeValue().trim())); } n = vmNode.getAttributes().getNamedItem("status"); if (n != null) { vm.setCurrentState(toState(n.getNodeValue().trim())); } String vmName = null; String computerName = null; n = vmNode.getAttributes().getNamedItem("name"); if (n != null) { vmName = n.getNodeValue().trim(); } NodeList attributes = vmNode.getChildNodes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (attribute.getNodeName().equalsIgnoreCase("Description") && attribute.hasChildNodes()) { vm.setDescription(attribute.getFirstChild().getNodeValue().trim()); } else if (attribute.getNodeName().equalsIgnoreCase("GuestCustomizationSection") && attribute.hasChildNodes()) { NodeList elements = attribute.getChildNodes(); String adminPassword = null; for (int j = 0; j < elements.getLength(); j++) { Node element = elements.item(j); if (element.getNodeName().equalsIgnoreCase("AdminPassword") && element.hasChildNodes()) { adminPassword = element.getFirstChild().getNodeValue().trim(); } else if (element.getNodeName().equalsIgnoreCase("ComputerName") && element.hasChildNodes()) { computerName = element.getFirstChild().getNodeValue().trim(); } } if (adminPassword != null) { vm.setRootUser(vm.getPlatform().isWindows() ? "administrator" : "root"); vm.setRootPassword(adminPassword); } } else if (attribute.getNodeName().equalsIgnoreCase("DateCreated") && attribute.hasChildNodes()) { vm.setCreationTimestamp((getProvider()).parseTime(attribute.getFirstChild().getNodeValue().trim())); } else if (attribute.getNodeName().equalsIgnoreCase("NetworkConnectionSection") && attribute.hasChildNodes()) { NodeList elements = attribute.getChildNodes(); TreeSet<String> addrs = new TreeSet<String>(); for (int j = 0; j < elements.getLength(); j++) { Node element = elements.item(j); if (element.getNodeName().equalsIgnoreCase("NetworkConnection")) { if (element.hasChildNodes()) { NodeList parts = element.getChildNodes(); Boolean connected = null; String addr = null; for (int k = 0; k < parts.getLength(); k++) { Node part = parts.item(k); if (part.getNodeName().equalsIgnoreCase("IpAddress") && part.hasChildNodes()) { addr = part.getFirstChild().getNodeValue().trim(); } if (part.getNodeName().equalsIgnoreCase("IsConnected") && part.hasChildNodes()) { connected = part.getFirstChild().getNodeValue().trim().equalsIgnoreCase("true"); } } if ((connected == null || connected) && addr != null) { addrs.add(addr); } } if (element.hasAttributes()) { Node net = element.getAttributes().getNamedItem("network"); if (net != null) { String netNameOrId = net.getNodeValue().trim(); boolean compat = (getProvider()).isCompat(); for (VLAN vlan : vlans) { boolean matches = false; if (!compat && vlan.getProviderVlanId().equals(netNameOrId)) { matches = true; } else if (compat && vlan.getProviderVlanId().equals("/network/" + netNameOrId)) { matches = true; } else if (vlan.getName().equals(netNameOrId)) { matches = true; } if (matches) { vm.setProviderVlanId(vlan.getProviderVlanId()); break; } } } } } } if (addrs.size() > 0) { if (addrs.size() == 1) { RawAddress a = new RawAddress(addrs.iterator().next()); if (isPublicIpAddress(a)) { vm.setPublicAddresses(a); } else { vm.setPrivateAddresses(a); } } else { ArrayList<RawAddress> pub = new ArrayList<RawAddress>(); ArrayList<RawAddress> priv = new ArrayList<RawAddress>(); for (String addr : addrs) { RawAddress r = new RawAddress(addr); if (isPublicIpAddress(r)) { pub.add(r); } else { priv.add(r); } } if (priv.size() > 0) { vm.setPrivateAddresses(priv.toArray(new RawAddress[priv.size()])); } if (pub.size() > 0) { vm.setPublicAddresses(pub.toArray(new RawAddress[pub.size()])); } } } } else if (attribute.getNodeName().equalsIgnoreCase("ovf:OperatingSystemSection") && attribute.hasChildNodes()) { NodeList os = attribute.getChildNodes(); for (int j = 0; j < os.getLength(); j++) { Node osdesc = os.item(j); if (osdesc.getNodeName().equalsIgnoreCase("ovf:Description") && osdesc.hasChildNodes()) { String desc = osdesc.getFirstChild().getNodeValue(); vm.setPlatform(Platform.guess(desc)); if (desc.contains("32") || (desc.contains("x86") && !desc.contains("64"))) { vm.setArchitecture(Architecture.I32); } } } } else if (attribute.getNodeName().equalsIgnoreCase("ovf:VirtualHardwareSection") && attribute.hasChildNodes()) { NodeList hardware = attribute.getChildNodes(); int memory = 0, cpu = 0; for (int j = 0; j < hardware.getLength(); j++) { Node item = hardware.item(j); if (item.getNodeName().equalsIgnoreCase("ovf:item") && item.hasChildNodes()) { NodeList bits = item.getChildNodes(); String rt = null; int qty = 0; for (int k = 0; k < bits.getLength(); k++) { Node bit = bits.item(k); if (bit.getNodeName().equalsIgnoreCase("rasd:ResourceType") && bit.hasChildNodes()) { rt = bit.getFirstChild().getNodeValue().trim(); } else if (bit.getNodeName().equalsIgnoreCase("rasd:VirtualQuantity") && bit.hasChildNodes()) { try { qty = Integer.parseInt(bit.getFirstChild().getNodeValue().trim()); } catch (NumberFormatException ignore) { // ignore } } } if (rt != null) { if (rt.equals("3")) { // cpu cpu = qty; } else if (rt.equals("4")) { // memory memory = qty; } /* else if( rt.equals("10") ) { // NIC } else if( rt.equals("17") ) { // disk } */ } } } VirtualMachineProduct product = null; for (VirtualMachineProduct prd : listProducts("bogus", VirtualMachineProductFilterOptions.getInstance().withArchitecture(Architecture.I64))) { if (prd.getCpuCount() == cpu && memory == prd.getRamSize().intValue()) { product = prd; break; } } if (product == null) { vm.setProductId("custom:" + cpu + ":" + memory); } else { vm.setProductId(product.getProviderProductId()); } } } if (vm.getProviderVirtualMachineId() == null) { return null; } if (vmName != null) { vm.setName(vmName); } else if (computerName != null) { vm.setName(computerName); } else { vm.setName(vm.getProviderVirtualMachineId()); } if (vm.getDescription() == null) { vm.setDescription(vm.getName()); } Platform p = vm.getPlatform(); if (p == null || p.equals(Platform.UNKNOWN) || p.equals(Platform.UNIX)) { p = Platform.guess(vm.getName() + " " + vm.getDescription()); if (Platform.UNIX.equals(vm.getPlatform())) { if (p.isUnix()) { vm.setPlatform(p); } } else { vm.setPlatform(p); } } try { vCloudMethod method = new vCloudMethod(getProvider()); String xml = method.get("vApp", vm.getProviderVirtualMachineId() + "/metadata"); if (xml != null && !xml.equals("")) { method.parseMetaData(vm, xml); String t; if (vm.getCreationTimestamp() < 1L) { t = (String) vm.getTag("dsnCreated"); if (t != null) { try { vm.setCreationTimestamp(Long.parseLong(t)); } catch (Throwable parseWarning) { if (logger.isDebugEnabled()) { logger.warn("Failed to parse creation timestamp.", parseWarning); } else { logger.warn("Failed to parse creation timestamp."); } } } } t = (String) vm.getTag("dsnImageId"); logger.debug("dsnImageId = " + t); if (t != null && "unknown".equals(vm.getProviderMachineImageId())) { vm.setProviderMachineImageId(t); logger.debug("Set provider machine image to " + t); } } } catch (Throwable warning) { if (logger.isDebugEnabled()) { logger.warn("Failed to get and parse vm metadata.", warning); } else { logger.warn("Failed to get and parse vm metadata."); } } vm.setTag(PARENT_VAPP_ID, parentVAppId); return vm; }
From source file:org.wise.vle.utils.FileManager.java
/** * Compare the parent and child projects to find differences. * These differences include whether a node was added, deleted, * moved, or not moved and whether the content for the node * was modified./* ww w.j a va 2s. com*/ * @param curriculumBaseDir the curriculum directory * @param parentProjectUrl the parent project url e.g. 236/wise4.project.json * @param projectUrl the child project url e.g. 235/wise4.project.json * @return the results of the analysis of the difference between the * parent and child project * @throws IOException */ public static String reviewUpdateProject(String curriculumBaseDir, String parentProjectUrl, String projectUrl) throws IOException { //stores node id to the node or sequence JSONObject for child project nodes HashMap<String, JSONObject> childNodeIdToNodeOrSequence = new HashMap<String, JSONObject>(); //stores the filename to the node id for child project nodes HashMap<String, String> childFileNameToId = new HashMap<String, String>(); //stores the node id to the node step number for child project nodes HashMap<String, String> childNodeIdToStepNumber = new HashMap<String, String>(); //stores node id to the node or sequence JSONObject for parent project nodes HashMap<String, JSONObject> parentNodeIdToNodeOrSequence = new HashMap<String, JSONObject>(); //stores the filename to the node id for parent project nodes HashMap<String, String> parentFileNameToNodeId = new HashMap<String, String>(); //stores the node id to the node step number for parent project nodes HashMap<String, String> parentNodeIdToStepNumber = new HashMap<String, String>(); //stores the .html file name to the .ht node id HashMap<String, String> htmlToHt = new HashMap<String, String>(); /* * stores the node id to status of the node. status can be * "added" * "deleted" * "moved" * "not moved" */ HashMap<String, String> nodeIdToStatus = new HashMap<String, String>(); /* * stores the node id to whether that node was modified or not. modified can be * "true" * "false" * (note these are String values) */ HashMap<String, String> nodeIdToModified = new HashMap<String, String>(); String fileSeparator = System.getProperty("file.separator"); //get the child project folder e.g. /Users/geoffreykwan/dev/apache-tomcat-5.5.27/webapps/curriculum/236 String fullProjectFolderUrl = curriculumBaseDir + projectUrl.substring(0, projectUrl.lastIndexOf(fileSeparator)); //get the child project file e.g. /Users/geoffreykwan/dev/apache-tomcat-5.5.27/webapps/curriculum/236/wise4.project.json String fullProjectFileUrl = curriculumBaseDir + projectUrl; //get the parent project folder e.g. /Users/geoffreykwan/dev/apache-tomcat-5.5.27/webapps/curriculum/235 String fullParentProjectFolderUrl = curriculumBaseDir + parentProjectUrl.substring(0, parentProjectUrl.lastIndexOf(fileSeparator)); //get the parent project file e.g. /Users/geoffreykwan/dev/apache-tomcat-5.5.27/webapps/curriculum/235/wise4.project.json String fullParentProjectFileUrl = curriculumBaseDir + parentProjectUrl; //get the project JSONObject for parent and child projects JSONObject childProject = getProjectJSONObject(fullProjectFileUrl); JSONObject parentProject = getProjectJSONObject(fullParentProjectFileUrl); //parse the parent and child projects to obtain mappings that we will use later parseProjectJSONObject(childProject, childNodeIdToNodeOrSequence, childFileNameToId, childNodeIdToStepNumber); parseProjectJSONObject(parentProject, parentNodeIdToNodeOrSequence, parentFileNameToNodeId, parentNodeIdToStepNumber); /* * compare the parent and child folders to determine if node * content files have been modified */ compareFolder(new File(fullParentProjectFolderUrl), new File(fullProjectFolderUrl), parentFileNameToNodeId, htmlToHt, nodeIdToModified); /* * compare the sequences in the parent and child projects * to determine if sequences have been added, deleted, moved, * or modified and if nodes have been added, deleted, or * moved (node modification detection is handled in the * compareFolder() call above) */ compareSequences(parentProject, childProject, parentNodeIdToNodeOrSequence, childNodeIdToNodeOrSequence, parentNodeIdToStepNumber, childNodeIdToStepNumber, nodeIdToStatus, nodeIdToModified); /* * a collection of NodeInfo objects for nodes in the child and * parent project */ TreeSet<NodeInfo> childAndParentNodes = new TreeSet<NodeInfo>(new NodeInfoComparator()); /* * a collection to keep track of all the node ids we have * added to the childAndParentNodes collection for quicker * lookup */ TreeSet<String> nodeIdsAdded = new TreeSet<String>(); /* * we must add nodes from the parent project first because we want * to show the author the structure of the parent project and * then add any additional nodes from the child project. we will * show them the parent project structure and how the nodes in the * parent project are different from the child project. any nodes * that are in the child project and not the parent project will * be also added to show that those nodes will be deleted. */ //get all the node ids from the parent project Set<String> parentKeySet = parentNodeIdToStepNumber.keySet(); //loop through all the sequences and nodes in the parent project Iterator<String> parentIdIterator = parentKeySet.iterator(); while (parentIdIterator.hasNext()) { //get a node id String parentId = parentIdIterator.next(); //get the step number for this node id String stepNumber = parentNodeIdToStepNumber.get(parentId); String title = ""; String nodeType = ""; try { //get the JSONObject for the node JSONObject parentNode = parentNodeIdToNodeOrSequence.get(parentId); //get the title and node type title = parentNode.getString("title"); nodeType = parentNode.getString("type"); } catch (JSONException e) { e.printStackTrace(); } //create a NodeInfo object with the info from the node NodeInfo parentNodeInfo = new NodeInfo(stepNumber, parentId, title, nodeType, "parent"); //add the NodeInfo to the collection childAndParentNodes.add(parentNodeInfo); //add the node id to the collection nodeIdsAdded.add(parentId); } //get all the nod ids from the child project Set<String> childKeySet = childNodeIdToStepNumber.keySet(); //loop through all the sequences and nodes in the child project Iterator<String> childIdIterator = childKeySet.iterator(); while (childIdIterator.hasNext()) { //get a node id String childId = childIdIterator.next(); //get the step number for this node id String stepNumber = childNodeIdToStepNumber.get(childId); String title = ""; String nodeType = ""; try { //get the JSONObject for the node JSONObject childNode = childNodeIdToNodeOrSequence.get(childId); //get the title and node type title = childNode.getString("title"); nodeType = childNode.getString("type"); } catch (JSONException e) { e.printStackTrace(); } //check if we have already added a node with this node id if (!nodeIdsAdded.contains(childId)) { //we have not added it before //create a NodeInfo object with the info from the node NodeInfo childNodeInfo = new NodeInfo(stepNumber, childId, title, nodeType, "child"); //add the NodeInfo to the collection childAndParentNodes.add(childNodeInfo); //add the node id to the collection nodeIdsAdded.add(childId); } } /* * the JSONArray that will contain the status info for all the nodes * such as whether a node was added, deleted, moved, or modified */ JSONArray nodeStatuses = new JSONArray(); //loop through all the NodeInfo objects Iterator<NodeInfo> childAndParentNodesIterator = childAndParentNodes.iterator(); while (childAndParentNodesIterator.hasNext()) { //get a node NodeInfo node = childAndParentNodesIterator.next(); //get the info from the node String nodeId = node.getNodeId(); String stepNumber = node.getStepNumber(); String title = node.getTitle(); String nodeType = node.getNodeType(); //get the status of the node ("added", "deleted", "moved", "not moved") String status = nodeIdToStatus.get(nodeId); //get whether the node was modified ("true" or "false") String modified = nodeIdToModified.get(nodeId); if (status == null) { //if there is no status value it means it was not moved status = "not moved"; } if (modified == null) { //if there was no modified value it means it was not modified modified = "false"; } try { //put all the values for this node into a JSONObject JSONObject nodeStatus = new JSONObject(); nodeStatus.put("stepNumber", stepNumber); nodeStatus.put("title", title); nodeStatus.put("nodeId", nodeId); nodeStatus.put("status", status); nodeStatus.put("modified", modified); nodeStatus.put("nodeType", nodeType); //add the node to the array nodeStatuses.put(nodeStatus); } catch (JSONException e) { e.printStackTrace(); } } //return the status array to the client return nodeStatuses.toString(); }
From source file:com.safi.workshop.sqlexplorer.sqleditor.ExtendedCompletionProposal.java
/** * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, * int)//from w ww . jav a 2 s . c o m */ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { if (dictionary == null) return null; String text = viewer.getDocument().get(); String string = text.substring(0, documentOffset); if (string.equals("")) //$NON-NLS-1$ return null; int position = string.length() - 1; char character; while (position > 0) { character = string.charAt(position); if (!Character.isJavaIdentifierPart(character) && (character != '.')) break; --position; } if (position == 0) position = -1; string = string.substring(position + 1); // JFaceDbcPlugin.error("String: "+string,new Exception()); if (StringUtils.isBlank(string)) { List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); String[] names = dictionary.getAllCatalogSchemas(); ICompletionProposal[] tempProps = new ICompletionProposal[names.length]; for (int i = 0; i < names.length; i++) { tempProps[i] = new CompletionProposal(names[i], documentOffset, 0, names[i].length(), catalogImage, names[i], null, null); } proposals.addAll(Arrays.asList(tempProps)); names = dictionary.getAllTables(); tempProps = new ICompletionProposal[names.length]; for (int i = 0; i < names.length; i++) { tempProps[i] = new CompletionProposal(names[i], documentOffset, 0, names[i].length(), tableImage, names[i], null, null); } proposals.addAll(Arrays.asList(tempProps)); names = dictionary.getAllExternalObjects(); tempProps = new ICompletionProposal[names.length]; for (int i = 0; i < names.length; i++) { tempProps[i] = new CompletionProposal(names[i], documentOffset, 0, names[i].length(), keywordImage, names[i], null, null); } proposals.addAll(Arrays.asList(tempProps)); return proposals.toArray(new ICompletionProposal[proposals.size()]); } // if (string == null || string.equals("")) // return null; string = string.toLowerCase(); int length = string.length(); // if (length < 1) // return null; int dotIndex = string.lastIndexOf("."); //$NON-NLS-1$ if (string.charAt(length - 1) == ' ') { return null; } else if (string.charAt(length - 1) == '.') {// Last typed character // is '.' String name = string.substring(0, length - 1); if (name == null) return null; int otherDot = name.lastIndexOf("."); if (otherDot != -1) name = name.substring(otherDot + 1); if (name == null || name.equals("")) return null; TreeSet st = (TreeSet) dictionary.getColumnListByTableName(name); if (st != null) { ArrayList list = (ArrayList) dictionary.getByTableName(name); if (list == null) return null; TableNode nd = null; if (list.size() >= 1) nd = (TableNode) list.get(0); else return null; Object[] obj = st.toArray(); String[] arr = new String[obj.length]; System.arraycopy(obj, 0, arr, 0, obj.length); ICompletionProposal[] result = new ICompletionProposal[arr.length]; String tableDesc = null; if (nd != null) tableDesc = nd.getTableDesc(); for (int i = 0; i < arr.length; i++) { result[i] = new CompletionProposal(arr[i], documentOffset, 0, arr[i].length(), colImage, arr[i], null, tableDesc); } return result; } INode node = (INode) dictionary.getByCatalogSchemaName(name); if (node != null) { Object children[] = node.getChildNodes(); ArrayList propList = new ArrayList(); if (children != null) { for (Object element : children) { String childName = element.toString().toLowerCase(); if (childName.equals("table") || childName.equals("view") || childName.equals("tables")) { Object[] tables = ((INode) element).getChildNodes(); if (tables != null) { for (Object table : tables) { Image tmpImage = null; String tableName = table.toString(); if (table instanceof TableNode) { if (((TableNode) table).isTable()) tmpImage = tableImage; else if (((TableNode) table).isView()) tmpImage = viewImage; propList.add(new ExtendedCompletionProposal(tableName, documentOffset, 0, tableName.length(), tmpImage, tableName, (TableNode) table)); } } } } } } ICompletionProposal[] res = new ICompletionProposal[propList.size()]; System.arraycopy(propList.toArray(), 0, res, 0, propList.size()); Arrays.sort(res, new ICompletionProposalComparator()); return res; } } else if (dotIndex == -1)// The string does not contain "." { String[] keywordProposal = Dictionary.matchKeywordsPrefix(string); ICompletionProposal[] resKey = new ICompletionProposal[keywordProposal.length]; for (int i = 0; i < keywordProposal.length; i++) { resKey[i] = new CompletionProposal(keywordProposal[i], documentOffset - length, length, keywordProposal[i].length(), keywordImage, keywordProposal[i], null, null); } String[] proposalsString = dictionary.matchTablePrefix(string.toLowerCase()); ArrayList propList = new ArrayList(); for (String element : proposalsString) { ArrayList ls = dictionary.getTableObjectList(element); for (int j = 0; j < ls.size(); j++) { TableNode tbNode = (TableNode) ls.get(j); Image tmpImage = null; if (tbNode.isView()) tmpImage = viewImage; else if (tbNode.isTable()) tmpImage = tableImage; ICompletionProposal cmp = new ExtendedCompletionProposal(element, documentOffset - length, length, element.length(), tmpImage, element, tbNode); propList.add(cmp); } } String[] proposalsString2 = dictionary.matchCatalogSchemaPrefix(string.toLowerCase()); ICompletionProposal[] resKey2 = new ICompletionProposal[proposalsString2.length]; for (int i = 0; i < proposalsString2.length; i++) { resKey2[i] = new CompletionProposal(proposalsString2[i], documentOffset - length, length, proposalsString2[i].length(), catalogImage, proposalsString2[i], null, null); } ICompletionProposal[] res = new ICompletionProposal[propList.size() + keywordProposal.length + resKey2.length]; System.arraycopy(resKey, 0, res, 0, resKey.length); System.arraycopy(propList.toArray(), 0, res, resKey.length, propList.size()); System.arraycopy(resKey2, 0, res, resKey.length + propList.size(), resKey2.length); Arrays.sort(res, new ICompletionProposalComparator()); return res; } else if (dotIndex != -1) { String firstPart = string.substring(0, dotIndex); int otherDot = firstPart.indexOf("."); if (otherDot != -1) firstPart = firstPart.substring(otherDot + 1); String lastPart = string.substring(dotIndex + 1); if (lastPart == null || firstPart == null || lastPart.equals("") || firstPart.equals("")) return null; TreeSet st = (TreeSet) dictionary.getColumnListByTableName(firstPart); if (st != null) { Iterator iter = st.iterator(); ArrayList propList = new ArrayList(); while (iter.hasNext()) { String colName = (String) iter.next(); int length2 = lastPart.length(); if (colName.length() >= length2) { if ((colName.substring(0, lastPart.length())).equalsIgnoreCase(lastPart)) { CompletionProposal cmp = new CompletionProposal(colName, documentOffset - length2, length2, colName.length(), colImage, colName, null, null); propList.add(cmp); } } } ICompletionProposal[] res = new ICompletionProposal[propList.size()]; System.arraycopy(propList.toArray(), 0, res, 0, propList.size()); return res; } INode node = (INode) dictionary.getByCatalogSchemaName(firstPart); if (node != null) { String[] proposalsString = dictionary.matchTablePrefix(lastPart.toLowerCase()); ArrayList propList = new ArrayList(); for (String element : proposalsString) { ArrayList ls = dictionary.getTableObjectList(element); for (int j = 0; j < ls.size(); j++) { TableNode tbNode = (TableNode) ls.get(j); Image tmpImage = null; TableFolderNode totn = (TableFolderNode) tbNode.getParent(); INode catSchema = totn.getParent(); if (catSchema == node) { if (tbNode.isView()) tmpImage = viewImage; else if (tbNode.isTable()) tmpImage = tableImage; ICompletionProposal cmp = new ExtendedCompletionProposal(element, documentOffset - lastPart.length(), lastPart.length(), element.length(), tmpImage, element, tbNode); propList.add(cmp); } } } ICompletionProposal[] res = new ICompletionProposal[propList.size()]; System.arraycopy(propList.toArray(), 0, res, 0, propList.size()); return res; } } return null; }
From source file:com.peterbochs.PeterBochsDebugger.java
private JSplitPane getJSplitPane2() { jSplitPane2 = new JSplitPane(); jSplitPane2.setPreferredSize(new java.awt.Dimension(1009, 781)); jSplitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT); {/* ww w.j a v a 2 s . c o m*/ jSplitPane1 = new JSplitPane(); jSplitPane2.add(jSplitPane1, JSplitPane.TOP); jSplitPane1.setDividerLocation(400); { jTabbedPane1 = new JMaximizableTabbedPane(); jSplitPane1.add(jTabbedPane1, JSplitPane.RIGHT); jTabbedPane1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { jTabbedPane1StateChanged(evt); } }); { jPanel10 = new JPanel(); BorderLayout jPanel10Layout = new BorderLayout(); jPanel10.setLayout(jPanel10Layout); jTabbedPane1.addTab(MyLanguage.getString("Instruction"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/text_padding_top.png")), jPanel10, null); jPanel10.setPreferredSize(new java.awt.Dimension(604, 452)); { jInstructionControlPanel = new JPanel(); jPanel10.add(jInstructionControlPanel, BorderLayout.NORTH); { ComboBoxModel jInstructionComboBoxModel = new DefaultComboBoxModel(new String[] {}); jInstructionComboBox = new JComboBox(); jInstructionControlPanel.add(jInstructionComboBox); jInstructionControlPanel.add(getDisassembleButton()); jInstructionComboBox.setModel(jInstructionComboBoxModel); jInstructionComboBox.setEditable(true); jInstructionComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jInstructionComboBoxActionPerformed(evt); } }); } { disassembleCurrentIPButton = new JButton(); jInstructionControlPanel.add(disassembleCurrentIPButton); jInstructionControlPanel.add(getJInstructionUpTenButton()); jInstructionControlPanel.add(getJInstructionUpButton()); jInstructionControlPanel.add(getJButton22()); jInstructionControlPanel.add(getJButton3()); jInstructionControlPanel.add(getJButton12()); disassembleCurrentIPButton.setText(MyLanguage.getString("Disassemble") + " cs:eip"); disassembleCurrentIPButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { disassembleCurrentIPButtonActionPerformed(evt); } }); } } { instructionTableScrollPane = new JScrollPane(); jPanel10.add(instructionTableScrollPane, BorderLayout.CENTER); { instructionTable = new JTable(); instructionTableScrollPane.setViewportView(instructionTable); instructionTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); instructionTable.setModel(new InstructionTableModel()); instructionTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); instructionTable.getTableHeader().setReorderingAllowed(false); instructionTable.getColumnModel().getColumn(0).setMaxWidth(20); instructionTable.getColumnModel().getColumn(1).setPreferredWidth(40); instructionTable.getColumnModel().getColumn(2).setPreferredWidth(200); instructionTable.getColumnModel().getColumn(3).setPreferredWidth(40); instructionTable.setDefaultRenderer(String.class, new InstructionTableCellRenderer()); instructionTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { instructionTableMouseClicked(evt); } }); } } } { jPanel4 = new JPanel(); jTabbedPane1 .addTab(MyLanguage.getString("Breakpoint"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/cancel.png")), jPanel4, null); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); { jScrollPane9 = new JScrollPane(); jPanel4.add(jScrollPane9, BorderLayout.CENTER); { breakpointTable = new JTable(); breakpointTable.getTableHeader().setReorderingAllowed(false); jScrollPane9.setViewportView(breakpointTable); breakpointTable.setModel(jBreakpointTableModel); breakpointTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); breakpointTable.getColumnModel().getColumn(0) .setCellRenderer(new BreakpointTableCellRenderer()); breakpointTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { breakpointTableMouseClicked(evt); } }); breakpointTable.getColumnModel().getColumn(2).setPreferredWidth(100); breakpointTable.getColumnModel().getColumn(3).setPreferredWidth(20); } } { jPanel12 = new JPanel(); jPanel4.add(jPanel12, BorderLayout.SOUTH); { jAddBreakpointButton = new JButton(); jPanel12.add(jAddBreakpointButton); jAddBreakpointButton.setText(MyLanguage.getString("Add")); jAddBreakpointButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jAddBreakpointButtonActionPerformed(evt); } }); } { jDeleteBreakpointButton = new JButton(); jPanel12.add(jDeleteBreakpointButton); jDeleteBreakpointButton.setText(MyLanguage.getString("Del")); jDeleteBreakpointButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jDeleteBreakpointButtonActionPerformed(evt); } }); } { jRefreshBreakpointButton = new JButton(); jPanel12.add(jRefreshBreakpointButton); jRefreshBreakpointButton.setText(MyLanguage.getString("Refresh")); jRefreshBreakpointButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jRefreshBreakpointButtonActionPerformed(evt); } }); } { jEnableBreakpointButton = new JButton(); jPanel12.add(jEnableBreakpointButton); jEnableBreakpointButton.setText(MyLanguage.getString("Enable")); jEnableBreakpointButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jEnableBreakpointButtonActionPerformed(evt); } }); } { jDisableBreakpointButton = new JButton(); jPanel12.add(jDisableBreakpointButton); jDisableBreakpointButton.setText(MyLanguage.getString("Disable")); jDisableBreakpointButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jDisableBreakpointButtonActionPerformed(evt); } }); } { jSaveBreakpointButton = new JButton(); jPanel12.add(jSaveBreakpointButton); jSaveBreakpointButton.setText(MyLanguage.getString("Save")); jSaveBreakpointButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jSaveBreakpointButtonActionPerformed(evt); } }); } { jLoadBreakpointButton = new JDropDownButton(); jPanel12.add(jLoadBreakpointButton); jPanel12.add(getJSBButton()); jPanel12.add(getJSBAButton()); jLoadBreakpointButton.setText(MyLanguage.getString("Load")); jLoadBreakpointButton.add(loadElfMenuItem); jLoadBreakpointButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jLoadBreakpointButtonActionPerformed(evt); } }); } } } { jPanel1 = new JPanel(); jTabbedPane1.addTab(MyLanguage.getString("Bochs"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/application_xp_terminal.png")), jPanel1, null); jTabbedPane1.addTab("ELF", new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/linux.png")), getJELFBreakpointPanel(), null); DiskPanel diskPanel = getDiskPanel(); if (diskPanel.getFile() != null) { jTabbedPane1.addTab(diskPanel.getFile().getName(), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/package.png")), diskPanel, null); } BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); { jScrollPane4 = new JScrollPane(); jPanel1.add(jScrollPane4, BorderLayout.CENTER); { bochsEditorPane = new JEditorPane(); jScrollPane4.setViewportView(bochsEditorPane); } } { jPanel2 = new JPanel(); TableLayout jPanel2Layout = new TableLayout(new double[][] { { TableLayout.FILL, 411.0, TableLayout.MINIMUM, TableLayout.MINIMUM }, { TableLayout.FILL } }); jPanel2Layout.setHGap(5); jPanel2Layout.setVGap(5); jPanel2.setLayout(jPanel2Layout); jPanel1.add(jPanel2, BorderLayout.SOUTH); { bochsCommandTextField = new JTextField(); jPanel2.add(bochsCommandTextField, "0, 0, 1, 0"); bochsCommandTextField.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { jBochsCommandTextFieldKeyPressed(evt); } public void keyTyped(KeyEvent evt) { bochsCommandTextFieldKeyTyped(evt); } }); } { bochsCommandButton = new JButton(); jPanel2.add(bochsCommandButton, "2, 0"); jPanel2.add(getJClearBochsButton(), "3, 0"); bochsCommandButton.setText("Run"); bochsCommandButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { bochsCommandButtonActionPerformed(evt); } }); } } } } { jTabbedPane3 = new JMaximizableTabbedPane(); jSplitPane1.add(jTabbedPane3, JSplitPane.LEFT); { jPanel8 = new JPanel(); BorderLayout jPanel8Layout = new BorderLayout(); jPanel8.setLayout(jPanel8Layout); jTabbedPane3 .addTab(MyLanguage.getString("Memory"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/memory.png")), jPanel8, null); { jScrollPane2 = new JScrollPane(); jPanel8.add(jScrollPane2, BorderLayout.CENTER); { jHexTable1 = new HexTable(); jHexTable1.getColumnModel().getColumn(0).setPreferredWidth(30); for (int x = 1; x < 9; x++) { jHexTable1.getColumnModel().getColumn(x).setPreferredWidth(10); } jScrollPane2.setViewportView(jHexTable1); jHexTable1.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); jHexTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jHexTable1.setCellSelectionEnabled(true); jHexTable1.getTableHeader().setReorderingAllowed(false); jHexTable1.setDefaultRenderer(String.class, new MemoryTableCellRenderer()); jHexTable1.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { jHexTable1MouseClicked(evt); } }); } } { jPanel9 = new JPanel(); FlowLayout jPanel9Layout = new FlowLayout(); jPanel9.setLayout(jPanel9Layout); jPanel8.add(jPanel9, BorderLayout.NORTH); { jMemoryAddressComboBox = new JComboBox(); jPanel9.add(jMemoryAddressComboBox); jMemoryAddressComboBox.setSelectedItem("0x00000000"); jMemoryAddressComboBox.setEditable(true); jMemoryAddressComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jMemoryAddressComboBoxActionPerformed(evt); } }); new Thread("addMemoryAddressComboBox thread") { public void run() { TreeSet<String> vector = Setting.getInstance().getMemoryCombo(); Iterator<String> iterator = vector.iterator(); while (iterator.hasNext()) { addMemoryAddressComboBox(iterator.next()); } } }.start(); jMemoryAddressComboBox.setSelectedItem("0x00000000"); } { jGOMemoryButton = new JButton(); jPanel9.add(jGOMemoryButton); jPanel9.add(getJGoLinearButton()); jPanel9.add(getJPreviousMemoryButton()); jPanel9.add(getJNextMemoryPageButton()); jPanel9.add(getJButton2()); jPanel9.add(getJButton5()); jGOMemoryButton.setText(MyLanguage.getString("Go")); jGOMemoryButton.setToolTipText(MyLanguage.getString("Physical_address")); jGOMemoryButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { jGOMemoryButtonActionPerformed(evt); } }); } { jBinaryRadioButton = new JRadioButton(); jPanel9.add(jBinaryRadioButton); jBinaryRadioButton.setText("2"); jBinaryRadioButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { jBinaryRadioButtonItemStateChanged(evt); } }); jBinaryRadioButton.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { jBinaryRadioButtonStateChanged(evt); } }); getButtonGroup1().add(jBinaryRadioButton); } { jOctRadioButton1 = new JRadioButton(); jPanel9.add(jOctRadioButton1); jOctRadioButton1.setText("8"); jOctRadioButton1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { jOctRadioButton1ItemStateChanged(evt); } }); jOctRadioButton1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { jOctRadioButton1StateChanged(evt); } }); getButtonGroup1().add(jOctRadioButton1); } { jDecRadioButton = new JRadioButton(); jPanel9.add(jDecRadioButton); jDecRadioButton.setText("10"); jDecRadioButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { jDecRadioButtonItemStateChanged(evt); } }); jDecRadioButton.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { jDecRadioButtonStateChanged(evt); } }); getButtonGroup1().add(jDecRadioButton); } { jHexRadioButton = new JRadioButton(); jPanel9.add(jHexRadioButton); jHexRadioButton.setText("16"); jHexRadioButton.setSelected(true); jHexRadioButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { jHexRadioButtonItemStateChanged(evt); } }); jHexRadioButton.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { jHexRadioButtonStateChanged(evt); } }); getButtonGroup1().add(jHexRadioButton); } } } { jPanel5 = new JPanel(); jTabbedPane3 .addTab(MyLanguage.getString("GDT"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/gdt.png")), jPanel5, null); BorderLayout jPanel5Layout = new BorderLayout(); jPanel5.setLayout(jPanel5Layout); { jScrollPane3 = new JScrollPane(); jPanel5.add(jScrollPane3, BorderLayout.CENTER); jPanel5.add(getJPanel14(), BorderLayout.NORTH); { GDTTableModel jGDTTableModel = new GDTTableModel(); jGDTTable = new JTable(); jGDTTable.setModel(jGDTTableModel); jScrollPane3.setViewportView(jGDTTable); jGDTTable.getColumnModel().getColumn(0).setMaxWidth(40); jGDTTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); jGDTTable.getTableHeader().setReorderingAllowed(false); jGDTTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { jGDTTableMouseClicked(evt); } }); } } } { jPanel6 = new JPanel(); BorderLayout jPanel6Layout = new BorderLayout(); jPanel6.setLayout(jPanel6Layout); jTabbedPane3 .addTab(MyLanguage.getString("IDT"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/idt.png")), jPanel6, null); { jScrollPane10 = new JScrollPane(); jPanel6.add(jScrollPane10, BorderLayout.CENTER); jPanel6.add(getJPanel15(), BorderLayout.NORTH); { IDTTableModel jIDTTableModel = new IDTTableModel(); jIDTTable = new JTable(); jIDTTable.setModel(jIDTTableModel); jScrollPane10.setViewportView(jIDTTable); jIDTTable.getColumnModel().getColumn(0).setMaxWidth(40); jIDTTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); jIDTTable.getTableHeader().setReorderingAllowed(false); jIDTTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { jIDTTableMouseClicked(evt); } }); } } } { jPanel7 = new JPanel(); BorderLayout jPanel7Layout = new BorderLayout(); jPanel7.setLayout(jPanel7Layout); jTabbedPane3 .addTab(MyLanguage.getString("LDT"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/ldt.png")), jPanel7, null); jTabbedPane3.addTab(MyLanguage.getString("Search_memory"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/memory.png")), getJPanel17(), null); jTabbedPane3.addTab("bochsout.txt", new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/script.png")), getJPanel31(), null); { jScrollPane11 = new JScrollPane(); jPanel7.add(jScrollPane11, BorderLayout.CENTER); jPanel7.add(getJPanel16(), BorderLayout.NORTH); { LDTTableModel jLDTTableModel = new LDTTableModel(); jLDTTable = new JTable(); jLDTTable.setModel(jLDTTableModel); jScrollPane11.setViewportView(jLDTTable); jLDTTable.getColumnModel().getColumn(0).setMaxWidth(40); jLDTTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); jLDTTable.getTableHeader().setReorderingAllowed(false); jLDTTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { jLDTTableMouseClicked(evt); } }); } } } } } { jTabbedPane2 = new JMaximizableTabbedPane(); // jTabbedPane2.setCloseIcon(true); // jTabbedPane2.setMaxIcon(true); // // jTabbedPane2.addCloseListener(new CloseListener() { // public void closeOperation(MouseEvent e) { // jTabbedPane2.remove(jTabbedPane2.getOverTabIndex()); // } // }); // // jTabbedPane2.addMaxListener(new MaxListener() { // public void maxOperation(MouseEvent e) { // jTabbedPane2.detachTab(jTabbedPane2.getOverTabIndex()); // } // }); jSplitPane2.add(jTabbedPane2, JSplitPane.BOTTOM); { registerPanelScrollPane = new JScrollPane(); jTabbedPane2.addTab(MyLanguage.getString("Register"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/text_kerning.png")), registerPanelScrollPane, null); { registerPanel = new RegisterPanel(this); registerPanelScrollPane.setViewportView(registerPanel); } } { jPanel3 = new JPanel(); jTabbedPane2.addTab(MyLanguage.getString("History"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/book_addresses.png")), jPanel3, null); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); { jScrollPane6 = new JScrollPane(); jPanel3.add(jScrollPane6, BorderLayout.CENTER); jPanel3.add(getJPanel13(), BorderLayout.NORTH); jScrollPane6.setViewportView(getJHistoryTable()); } } { jPanel11 = new JPanel(); jTabbedPane2 .addTab(MyLanguage.getString("Paging"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/page_copy.png")), jPanel11, null); jTabbedPane2.addTab(MyLanguage.getString("Address_translate"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/page_go.png")), getJAddressTranslatePanel(), null); jTabbedPane2.addTab("Page table graph (experimental)", new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/page_lightning.png")), getJPageTableGraphPanel(), null); if (!Global.debug) { jTabbedPane2.removeTabAt(jTabbedPane2.getTabCount() - 1); } jTabbedPane2.addTab(MyLanguage.getString("Table_translate"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/page_refresh.png")), getJTableTranslateScrollPane(), null); jTabbedPane2.addTab(MyLanguage.getString("ELF_dump"), new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/linux.png")), getJELFDumpScrollPane(), null); jTabbedPane2.addTab("OS debug informations", new ImageIcon(getClass().getClassLoader() .getResource("com/peterbochs/icons/famfam_icons/bug.png")), getJOSDebugStandardPanel(), null); BorderLayout jPanel11Layout = new BorderLayout(); jPanel11.setLayout(jPanel11Layout); jPanel11.add(getJSplitPane3(), BorderLayout.CENTER); jPanel11.add(getJPanel19(), BorderLayout.NORTH); } } return jSplitPane2; }