JTree - Fetch URL from a tree node.
Now I have created one JTree and one JEditorPane.
Basically I am creating a help file. (a chm file in windows).
So I need to handle mouse click event on each node on JTree.
I have used such format to add a hyperlink.
sample code:---------------------------------------------------------------------------------------------------------------------------
javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("JTree");
javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("colors");
javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("blue");
treeNode2.add(treeNode3);
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("violet");
treeNode2.add(treeNode3);
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("red");
treeNode2.add(treeNode3);
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("yellow");
treeNode2.add(treeNode3);
treeNode1.add(treeNode2);
treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("s");
treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("<html><a href='C:\\Program Files\\Java\\jdk1.6\\README.html'>Read Me</a></html>");
treeNode2.add(treeNode3);
jTree1.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
TreeListener(evt);
private void TreeListener(java.awt.event.MouseEvent evt) {
int selRow= jTree1.getRowForLocation(evt.getX(), evt.getY());
TreePath tp = jTree1.getPathForLocation(evt.getX(), evt.getY());
if(selRow!=-1) {
if(evt.getClickCount()==1) {
jTree1.setSelectionPath(tp);
Now there is a hyperlink created for that node "Read Me".
My Question is ..........
How do I fetch this stored URL in each node for setting it to my JEditorPane....???
ok, it seems to be working now. I just return the JInternalFrame in the getTreeCellRendererComponent() method.
Similar Messages
-
Fetch URL from Application Server of Saved File
Hi,
I wrote a file on the Application Server using Open Dataset commands.
i can see it in AL11 transaction as getting saved on the server.
How can i fetch the path , where it got saved?
Regards,
AnanthaWelcome to SDN.
there is no url assigned to the file stored in the application server, if you want to provide a link for the same from your BSP application, you have to read the contents using open dataset and set it as cached response of your bsp application and set the link url.
the code will be like below.
open dataset .. to read the contents
create object cached_response type cl_http_response exporting add_c_msg = 1.
cached_response->set_data( file_content ).
cached_response->set_header_field( name = if_http_header_fields=>content_type
value = file_mime_type ).
cached_response->set_status( code = 200 reason = 'OK' ).
cached_response->server_cache_expire_rel( expires_rel = 180 ).
call function 'GUID_CREATE'
importing
ev_guid_32 = guid.
concatenate runtime->application_url '/' guid into display_url.
cl_http_server=>server_cache_upload( url = display_url
response = cached_response ).
Regards
Raja -
Error while fetching Users from AD Tree
Dear Gurus,
I am connecting my NetWeaver 7.01 GRC ABAP stack to AD for fetching the Users. I have successfully created the LDAP Server, Connector and System User and I am able to connect to the AD.
The problem I am facing is that when I put my Base Entry as the bootom level, I am able to create users using RSLDAPSYNC_USER program but when I put the base entry as my top level DC, it gives an error "Operation Failed" with code no LDAPRC001.
Kindly guide if I can fetch all users in a single go, using the top level base entry? Otherwise it will be very difficult for me to identifiy all low level OUs and then fetching data individually changing base entry every time.
Hope I am able to explain my problem..
Thanks
Jitendra TayalCheck this thread it might put you in the right direction,
Problem with LDAP connector
Regards
Juan -
How to run a form using tree node selection??
hi...
i have populated a tree with all the form name.There is a particular id for every form.i want to show a form using tree node selection.What i did...i write a trigger in button's click event when the tree node is selected then i get a id.if id=1 then open_form('test.fmx').when i want to execute this code then it is showing the same form 2 times.Can anyone help me to solve my problem?If so plz tell me what code i have to write to show a form using node selection?.I've done the same thing, and i think it works fine.
Check this code (Sorry for the long post, but i cannot find how to attach files.
PACKAGE menu_pk IS
--Initialization of the menu.
procedure Init;
--Called from WHEN-TREE-NODE-EXPANDED
procedure Expanded;
--Called from WHEN-TREE-NODE-ACTIVATED
procedure ExecuteCommand;
END;
PACKAGE BODY menu_pk IS
MENU_NAME constant varchar2(30) := 'menu.menu';
cursor c_menu(pRoot in varchar2) is
select apm_code, apm_parcode, apm_descr, decode(apm_type, 0, Ftree.EXPANDED_NODE, Ftree.LEAF_NODE) apm_type,
decode(apm_type, 0, 'menu', 1, 'form', 2, 'report') || '.ico' apm_icon
from app_menu
where apm_parcode = pRoot
order by apm_code asc;
procedure Init is
new_node ftree.node;
begin
for i in c_menu('root')
loop
new_node := Ftree.add_tree_node(MENU_NAME, FTree.ROOT_NODE,
Ftree.PARENT_OFFSET, Ftree.LAST_CHILD,
i.apm_type, i.apm_descr, i.apm_icon, i.apm_code);
end loop;
end;
procedure FillNode(pNode in FTree.Node) is
new_node ftree.node;
begin
for i in c_menu(FTree.get_tree_node_property(MENU_NAME, pNode, FTree.NODE_VALUE))
loop
new_node := Ftree.add_tree_node(MENU_NAME, pNode,
Ftree.PARENT_OFFSET, Ftree.LAST_CHILD,
i.apm_type, i.apm_descr, i.apm_icon, i.apm_code);
end loop;
end;
procedure DeleteNodeChilds is
node FTree.NODE;
begin
loop
node := FTree.Find_Tree_Node(MENU_NAME, '',
FTree.FIND_NEXT_CHILD, FTree.NODE_VALUE,
name_in('system.trigger_node'), name_in('system.trigger_node'));
exit when Ftree.ID_NULL(node);
FTree.delete_tree_node(MENU_NAME, node);
end loop;
end;
procedure Expanded is
begin
if (FTree.GET_TREE_NODE_PROPERTY(MENU_NAME, :system.trigger_node, FTree.Node_State) = FTree.EXPANDED_NODE) then
menu_pk.FillNode(name_in('system.trigger_node'));
else
menu_pk.DeleteNodeChilds;
end if;
end;
procedure ExecuteCommand is
cursor c_command(pCode in varchar2) is
select apm_form, apm_type
from app_menu
where apm_code = pCode;
fCommand c_command%rowtype;
fMenuCode varchar2(20);
begin
-- if it is as menu node then exit.
if (not FTree.Get_Tree_Node_Property(MENU_NAME, :system.trigger_node, FTree.NODE_STATE) = FTree.LEAF_NODE) then
return;
end if;
fMenuCode := FTree.Get_Tree_Node_Property(MENU_NAME, :system.trigger_node, FTree.NODE_VALUE);
open c_command(fMenuCode);
fetch c_command into fCommand;
close c_command;
if (fCommand.apm_type = 1) and (fCommand.apm_form is not null) then
globals.Set_MenuChoice(fMenuCode);
OPEN_FORM(fCommand.apm_form);--, ACTIVATE, SESSION);
end if;
end;
END;
The menu table definition follows.
create table APP_MENU
APM_CODE VARCHAR2(10) not null,
APM_PARCODE VARCHAR2(10) not null,
APM_DESCR VARCHAR2(40) not null,
APM_TYPE NUMBER(1) not null,
APM_FORM VARCHAR2(50)
alter table APP_MENU
add constraint APP_MENU_PRI primary key (APM_CODE);
Hope this helps -
Hello,
I am trying to configure a Tree in APEX 4.1 and I'm not sure if what I am trying to do is possible. Here is the situation: I work for a university that has the following colleges:
College of Arts & Communication
College of Business Administration
College of Education
College of Liberal Arts
College of Professional Studies
College of Sciences
Each of the above listed colleges have multiple majors that are unique to that college.
So my tree uses the college name for the parent node and each of the majors for that college as the child nodes. Each Major has a major code assigned to it, so when a user clicks on a major, a page loads with information about the students in that major. Colleges, however, do not have a major code and so if the user clicks on the college name in the tree, the page loads but has no data. So, what I would like is that if a user clicks on a mjor, the pages loads like currently set up, but if the user clicks on a college name, a different page loads with information about that college.
So the question is: Is it possible to have one page load, say Page 21, when a major (child node) is selected, and another page, Page 22, when a college (parent node) is selected?
Thanks,
BobYes, that is very much possible to call different urls/pages from different tree nodes. You need to format your query to use independent select statements (for each node) and finally use UNION to form the tree.
For example, you can do something like this:
SELECT CASE WHEN connect_by_isleaf = 1 THEN 0
WHEN level = 1 THEN 1
ELSE -1
END as status
, level
, name as title
, icon
, id as value
, tip as tooltip
, url as link
, seq as display
from
-- select statement for the parent node
UNION
-- select statement for the first/immediate child node
UNION
-- select statement for the level 2 child
start with parent is null
connect by NOCYCLE prior id = parent
order siblings by displayIn each select statement, you can specify the required link/url.
I hope this helps. -
Hello alllll
i have a master-detail block besides a tree block
All i wanna do Simply and logically is to select a tree node then a Master-Detail records related to this tree node is to be retrieved...
_i have the following code in the WHEN-TREE-NODE-SELECTED Trigger as follow:_
DECLARE
htree ITEM;
node_value VARCHAR2(100);
BEGIN
IF :SYSTEM.TRIGGER_NODE_SELECTED = 'TRUE' THEN
-- Find the tree itself.
htree := FIND_ITEM ('BL_TREE.IT_TREE');
-- Find the value of the node clicked on.
NODE_VALUE := FTREE.GET_TREE_NODE_PROPERTY( htree, :SYSTEM.TRIGGER_NODE , Ftree.NODE_LABEL );
GO_BLOCK ('STP_COMPANIES');
EXECUTE_QUERY;
END IF;
END;The above code retrieved data as a whole
but i want 2 filter the data selected from the tree node as i said 2 be displayed as filtered by the tree selection.
so i used the following code as follow:
GO_BLOCK ('GL_COST_CENTERS');
set_block_property('GL_COST_CENTERS', DEFAULT_WHERE, 'COMPANY_ID ='||
ftree.get_tree_node_property('BL_TREE.IT_TREE', :SYSTEM.TRIGGER_NODE, FTREE.NODE_VALUE));
EXECUTE_QUERY;Any help will be appreciated...
Thanks in Advance..
Regards,
Abdetu...Hello thanks for reply,
STP_COMPANIES your detail block? no it's the master
gets the "Label" of the tree node not the value of the selected nodei tried both but nothing retrieved...!
i thought that the value is the serial of the node and the lable is the text displayed on the tree node no ?
Is this code in the same When-Tree-Node-Selected trigger or a different trigger?yes WHEN-TREE-NODE-SELECTED as my post titled...
is GL_COST_CENTERS the master block? no it's the detail ; every company --- has many <- cost centers
are the tables related? yes
just query the master table and the detail table will automatically be filter through the relationship?i did and it works filtering through the company_id, But what i wanna do is 2 filter the data displayed in the two block Master-Detail according 2 the selection of the tree
Say i selected the ....
+ Assets node
|
|------ - Furnitures 's node is selected so alll the related details of the furniture is displayed in the Master-BLock
| |
| +----chairs
| |
| +----tables
|
+----- LAnds
|So the Tree is used 2 Query or retrieved the selected node's data accordingly...
hope i well explained my issue ..!
is it possible 2 do that ?!
Thanks Again..
Regards,
Abdetu... -
Help with building a JTree using tree node and node renderers
Hi,
I am having a few problems with JTree's. basically I want to build JTree from a web spider. The webspide searches a website checking links and stores the current url that is being processed as a string in the variable msg. I wan to use this variable to build a JTree in a new class and then add it to my GUI. I have created a tree node class and a renderer node class, these classes are built fine. can someone point me in the direction for actually using these to build my tree in a seperate class and then displaying it in a GUI class?
*nodeRenderer.java
import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.net.*;
public class nodeRenderer extends DefaultTreeCellRenderer
implements TreeCellRenderer
public static Icon icon= null;
public nodeRenderer() {
icon = new ImageIcon(getClass().getResource("icon.gif"));
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
treeNode node = (treeNode)(((DefaultMutableTreeNode)value).getUserObject());
if(icon != null) // set a custom icon
setOpenIcon(icon);
setClosedIcon(icon);
setLeafIcon(icon);
return this;
*treeNode.java
*this is the class to represent a node
import javax.swing.*;
import javax.swing.tree.*;
import java.util.*;
import java.net.*;
* Class used to hold information about a web site that has
* been searched by the spider class
public class treeNode
*Url from the WebSpiderController Class
*that is currently being processed
public String msg;
treeNode(String urlText)
msg = urlText;
String getUrlText()
return msg;
//gui.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class gui extends JFrame implements Runnable
*declare variable, boolean
*thread, a object and a center
*pane
protected URL urlInput;
protected Thread bgThread;
protected boolean run = false;
protected WebSpider webSpider;
public gui()
*create the gui here
setTitle("Testing Tool");
setSize(600,600);
//add Buttons to the tool bar
start.setText("Start");
start.setActionCommand("Start");
toolBar.add(start);
ButtonListener startListener = new ButtonListener();
start.addActionListener(startListener);
cancel.setText("Cancel");
cancel.setActionCommand("Cancel");
toolBar.add(cancel);
ButtonListener cancelListener = new ButtonListener();
cancel.addActionListener(cancelListener);
close.setText("Close");
close.setActionCommand("Close");
toolBar.add(close);
ButtonListener closeListener = new ButtonListener();
close.addActionListener(closeListener);
//creat a simple form
urlLabel.setText("Enter URL:");
urlLabel.setBounds(100,36,288,24);
formTab.add(urlLabel);
url.setBounds(170,36,288,24);
formTab.add(url);
current.setText("Currently Processing: ");
current.setBounds(100,80,288,24);
formTab.add(current);
//add scroll bars to the error messages screen and website structure
errorPane.setAutoscrolls(true);
errorPane.setHorizontalScrollBarPolicy(javax.swing.
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
errorPane.setVerticalScrollBarPolicy(javax.swing.
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
errorPane.setOpaque(true);
errorTab.add(errorPane);
errorPane.setBounds(0,0,580,490);
errorText.setEditable(false);
errorPane.getViewport().add(errorText);
errorText.setBounds(0,0,600,550);
treePane.setAutoscrolls(true);
treePane.setHorizontalScrollBarPolicy(javax.swing.
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
treePane.setVerticalScrollBarPolicy(javax.swing.
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
treePane.setOpaque(true);
treeTab.add(treePane);
treePane.setBounds(0,0,580,490);
treeText.setEditable(false);
treePane.getViewport().add(treeText);
treeText.setBounds(0,0,600,550);
//create the tabbed window
centerPane.setBorder(new javax.swing.border.EtchedBorder());
formTab.setLayout(null);
errorTab.setLayout(null);
treeTab.setLayout(null);
centerPane.addTab("Search Parameters", formTab);
centerPane.addTab("Error Messages", errorTab);
centerPane.addTab("Website Structure", treeTab);
//add the tool bar and tabbed pane
getContentPane().add(toolBar, java.awt.BorderLayout.NORTH);
getContentPane().add(centerPane, java.awt.BorderLayout.CENTER);
*create the tool bar pane, a center pane, add the buttons,
*labels, tabs, a text field for user input here
javax.swing.JPanel toolBar = new javax.swing.JPanel();
javax.swing.JButton start = new javax.swing.JButton();
javax.swing.JButton cancel = new javax.swing.JButton();
javax.swing.JButton close = new javax.swing.JButton();
javax.swing.JTabbedPane centerPane = new javax.swing.JTabbedPane();
javax.swing.JPanel formTab = new javax.swing.JPanel();
javax.swing.JLabel urlLabel = new javax.swing.JLabel();
javax.swing.JLabel current = new javax.swing.JLabel();
javax.swing.JTextField url = new javax.swing.JTextField();
javax.swing.JPanel errorTab = new javax.swing.JPanel();
javax.swing.JTextArea errorText = new javax.swing.JTextArea();
javax.swing.JScrollPane errorPane = new javax.swing.JScrollPane();
javax.swing.JPanel treeTab = new javax.swing.JPanel();
javax.swing.JTextArea treeText = new javax.swing.JTextArea();
javax.swing.JScrollPane treePane = new javax.swing.JScrollPane();
javax.swing.JTree searchTree = new javax.swing.JTree();
*show the gui
public static void main(String args[])
(new gui()).setVisible(true);
*listen for the button presses and set the
*boolean flag depending on which button is pressed
class ButtonListener implements ActionListener
public void actionPerformed(ActionEvent event)
Object object = event.getSource();
if (object == start)
run = true;
startActionPerformed(event);
if (object == cancel)
run = false;
startActionPerformed(event);
if (object == close)
System.exit(0);
*this method is called when the start or
*cancel button is pressed.
void startActionPerformed (ActionEvent event)
if (run == true && bgThread == null)
bgThread = new Thread(this);
bgThread.start();
if (run == false && bgThread != null)
webSpider.cancel();
*this mehtod will start the background thred.
*the background thread is required so that the
*GUI is still displayed
public void run()
try
webSpider = new WebSpider(this);
webSpider.clear();
urlInput = new URL(url.getText());
webSpider.addURL(urlInput);
webSpider.run();
bgThread=null;
catch (MalformedURLException e)
addressError addErr = new addressError();
addErr.addMsg = "URL ERROR - PLEASE CHECK";
SwingUtilities.invokeLater(addErr);
*this method is called by the web spider
*once a url is found. Validation of navigation
*happens here.
public boolean urlFound(URL urlInput,URL url)
CurrentlyProcessing pro = new CurrentlyProcessing();
pro.msg = url.toString();
SwingUtilities.invokeLater(pro);
if (!testLink(url))
navigationError navErr = new navigationError();
navErr.navMsg = "Broken Link "+url+" caused on "+urlInput+"\n";
return false;
if (!url.getHost().equalsIgnoreCase(urlInput.getHost()))
return false;
else
return true;
*this method is called internally to check
*that a link works
protected boolean testLink(URL url)
try
URLConnection connection = url.openConnection();
connection.connect();
return true;
catch (IOException e)
return false;
*this method is called when an error is
*found.
public void URLError(URL url)
*this method is called when an email
*address is found
public void emailFound(String email)
/*this method will update any errors found inc
*address errors and broken links
class addressError implements Runnable
public String addMsg;
public void run()
errorText.append(addMsg);
current.setText("Currently Processing: "+ addMsg);
class navigationError implements Runnable
public String navMsg;
public void run()
errorText.append(navMsg);
*this method will update the currently
*processing field on the GUI
class CurrentlyProcessing implements Runnable
public String msg;
public void run()
current.setText("Currently Processing: " + msg );
//webspider.java
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.tree.*;
import javax.swing.*;
*this class implements the spider.
public class WebSpider extends HTMLEditorKit
*make a collection of the URL's
protected Collection urlErrors = new ArrayList(3);
protected Collection urlsWaiting = new ArrayList(3);
protected Collection urlsProcessed = new ArrayList(3);
//report URL's to this class
protected gui report;
*this flag will indicate whether the process
*is to be cancelled
protected boolean cancel = false;
*The constructor
*report the urls to the wui class
public WebSpider(gui report)
this.report = report;
*get the urls from the above declared
*collections
public Collection getUrlErrors()
return urlErrors;
public Collection getUrlsWaiting()
return urlsWaiting;
public Collection getUrlsProcessed()
return urlsProcessed;
* Clear all of the collections.
public void clear()
getUrlErrors().clear();
getUrlsWaiting().clear();
getUrlsProcessed().clear();
*Set a flag that will cause the begin
*method to return before it is done.
public void cancel()
cancel = true;
*add the entered url for porcessing
public void addURL(URL url)
if (getUrlsWaiting().contains(url))
return;
if (getUrlErrors().contains(url))
return;
if (getUrlsProcessed().contains(url))
return;
/*WRITE TO LOG FILE*/
log("Adding to workload: " + url );
getUrlsWaiting().add(url);
*process a url
public void processURL(URL url)
try
/*WRITE TO LOGFILE*/
log("Processing: " + url );
// get the URL's contents
URLConnection connection = url.openConnection();
if ((connection.getContentType()!=null) &&
!connection.getContentType().toLowerCase().startsWith("text/"))
getUrlsWaiting().remove(url);
getUrlsProcessed().add(url);
log("Not processing because content type is: " +
connection.getContentType() );
return;
// read the URL
InputStream is = connection.getInputStream();
Reader r = new InputStreamReader(is);
// parse the URL
HTMLEditorKit.Parser parse = new HTMLParse().getParser();
parse.parse(r,new Parser(url),true);
catch (IOException e)
getUrlsWaiting().remove(url);
getUrlErrors().add(url);
log("Error: " + url );
report.URLError(url);
return;
// mark URL as complete
getUrlsWaiting().remove(url);
getUrlsProcessed().add(url);
log("Complete: " + url );
*start the spider
public void run()
cancel = false;
while (!getUrlsWaiting().isEmpty() && !cancel)
Object list[] = getUrlsWaiting().toArray();
for (int i=0;(i<list.length)&&!cancel;i++)
processURL((URL)list);
* A HTML parser callback used by this class to detect links
protected class Parser extends HTMLEditorKit.ParserCallback
protected URL urlInput;
public Parser(URL urlInput)
this.urlInput = urlInput;
public void handleSimpleTag(HTML.Tag t,MutableAttributeSet a,int pos)
String href = (String)a.getAttribute(HTML.Attribute.HREF);
if((href==null) && (t==HTML.Tag.FRAME))
href = (String)a.getAttribute(HTML.Attribute.SRC);
if (href==null)
return;
int i = href.indexOf('#');
if (i!=-1)
href = href.substring(0,i);
if (href.toLowerCase().startsWith("mailto:"))
report.emailFound(href);
return;
handleLink(urlInput,href);
public void handleStartTag(HTML.Tag t,MutableAttributeSet a,int pos)
handleSimpleTag(t,a,pos); // handle the same way
protected void handleLink(URL urlInput,String str)
try
URL url = new URL(urlInput,str);
if (report.urlFound(urlInput,url))
addURL(url);
catch (MalformedURLException e)
log("Found malformed URL: " + str);
*log the information of the spider
public void log(String entry)
System.out.println( (new Date()) + ":" + entry );
I have a seperate class for parseing the HTML. Any help would be greatly appreciated
mrvHi Sorry to be a pain again,
I have re worked the gui class so it looks like this now:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class gui extends JFrame implements Runnable
*declare variable, boolean
*thread, a object and a center
*pane
protected URL urlInput;
protected Thread bgThread;
protected boolean run = false;
protected WebSpider webSpider;
public String msgInfo;
public String brokenUrl;
public String goodUrl;
public String deadUrl;
protected DefaultMutableTreeNode rootNode;
protected DefaultTreeModel treeModel;
public gui()
*create the gui here
setTitle("Testing Tool");
setSize(600,600);
//add Buttons to the tool bar
start.setText("Start");
start.setActionCommand("Start");
toolBar.add(start);
ButtonListener startListener = new ButtonListener();
start.addActionListener(startListener);
cancel.setText("Cancel");
cancel.setActionCommand("Cancel");
toolBar.add(cancel);
ButtonListener cancelListener = new ButtonListener();
cancel.addActionListener(cancelListener);
close.setText("Close");
close.setActionCommand("Close");
toolBar.add(close);
ButtonListener closeListener = new ButtonListener();
close.addActionListener(closeListener);
//creat a simple form
urlLabel.setText("Enter URL:");
urlLabel.setBounds(100,36,288,24);
formTab.add(urlLabel);
url.setBounds(170,36,288,24);
formTab.add(url);
current.setText("Currently Processing: ");
current.setBounds(100,80,288,24);
formTab.add(current);
//add scroll bars to the error messages screen and website structure
errorPane.setAutoscrolls(true);
errorPane.setHorizontalScrollBarPolicy(javax.swing.
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
errorPane.setVerticalScrollBarPolicy(javax.swing.
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
errorPane.setOpaque(true);
errorTab.add(errorPane);
errorPane.setBounds(0,0,580,490);
errorText.setEditable(false);
errorPane.getViewport().add(errorText);
errorText.setBounds(0,0,600,550);
treePane.setAutoscrolls(true);
treePane.setHorizontalScrollBarPolicy(javax.swing.
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
treePane.setVerticalScrollBarPolicy(javax.swing.
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
treePane.setOpaque(true);
treeTab.add(treePane);
treePane.setBounds(0,0,580,490);
treeText.setEditable(false);
treePane.getViewport().add(treeText);
treeText.setBounds(0,0,600,550);
//JTree
// NEW CODE
rootNode = new DefaultMutableTreeNode("Root Node");
treeModel = new DefaultTreeModel(rootNode);
treeModel.addTreeModelListener(new MyTreeModelListener());
tree = new JTree(treeModel);
tree.setEditable(true);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setShowsRootHandles(true);
treeText.add(tree);
//create the tabbed window
centerPane.setBorder(new javax.swing.border.EtchedBorder());
formTab.setLayout(null);
errorTab.setLayout(null);
treeTab.setLayout(null);
centerPane.addTab("Search Parameters", formTab);
centerPane.addTab("Error Messages", errorTab);
centerPane.addTab("Website Structure", treeTab);
//add the tool bar and tabbed pane
getContentPane().add(toolBar, java.awt.BorderLayout.NORTH);
getContentPane().add(centerPane, java.awt.BorderLayout.CENTER);
*create the tool bar pane, a center pane, add the buttons,
*labels, tabs, a text field for user input here
javax.swing.JPanel toolBar = new javax.swing.JPanel();
javax.swing.JButton start = new javax.swing.JButton();
javax.swing.JButton cancel = new javax.swing.JButton();
javax.swing.JButton close = new javax.swing.JButton();
javax.swing.JTabbedPane centerPane = new javax.swing.JTabbedPane();
javax.swing.JPanel formTab = new javax.swing.JPanel();
javax.swing.JLabel urlLabel = new javax.swing.JLabel();
javax.swing.JLabel current = new javax.swing.JLabel();
javax.swing.JTextField url = new javax.swing.JTextField();
javax.swing.JPanel errorTab = new javax.swing.JPanel();
javax.swing.JTextArea errorText = new javax.swing.JTextArea();
javax.swing.JScrollPane errorPane = new javax.swing.JScrollPane();
javax.swing.JPanel treeTab = new javax.swing.JPanel();
javax.swing.JTextArea treeText = new javax.swing.JTextArea();
javax.swing.JScrollPane treePane = new javax.swing.JScrollPane();
javax.swing.JTree tree = new javax.swing.JTree();
*show the gui
public static void main(String args[])
(new gui()).setVisible(true);
*listen for the button presses and set the
*boolean flag depending on which button is pressed
class ButtonListener implements ActionListener
public void actionPerformed(ActionEvent event)
Object object = event.getSource();
if (object == start)
run = true;
startActionPerformed(event);
if (object == cancel)
run = false;
startActionPerformed(event);
if (object == close)
System.exit(0);
*this method is called when the start or
*cancel button is pressed.
void startActionPerformed (ActionEvent event)
if (run == true && bgThread == null)
bgThread = new Thread(this);
bgThread.start();
//new line of code
treeText.addObject(msgInfo);
if (run == false && bgThread != null)
webSpider.cancel();
*this mehtod will start the background thred.
*the background thread is required so that the
*GUI is still displayed
public void run()
try
webSpider = new WebSpider(this);
webSpider.clear();
urlInput = new URL(url.getText());
webSpider.addURL(urlInput);
webSpider.run();
bgThread = null;
catch (MalformedURLException e)
addressError addErr = new addressError();
addErr.addMsg = "URL ERROR - PLEASE CHECK";
SwingUtilities.invokeLater(addErr);
*this method is called by the web spider
*once a url is found. Validation of navigation
*happens here.
public boolean urlFound(URL urlInput,URL url)
CurrentlyProcessing pro = new CurrentlyProcessing();
pro.msg = url.toString();
SwingUtilities.invokeLater(pro);
if (!testLink(url))
navigationError navErr = new navigationError();
navErr.navMsg = "Broken Link "+url+" caused on "+urlInput+"\n";
brokenUrl = url.toString();
return false;
if (!url.getHost().equalsIgnoreCase(urlInput.getHost()))
return false;
else
return true;
*this method is returned if there is no link
*on a web page, e.g. there us a dead end
public void urlNotFound(URL urlInput)
deadEnd dEnd = new deadEnd();
dEnd.dEMsg = "No links on "+urlInput+"\n";
deadUrl = urlInput.toString();
*this method is called internally to check
*that a link works
protected boolean testLink(URL url)
try
URLConnection connection = url.openConnection();
connection.connect();
goodUrl = url.toString();
return true;
catch (IOException e)
return false;
*this method is called when an error is
*found.
public void urlError(URL url)
*this method is called when an email
*address is found
public void emailFound(String email)
/*this method will update any errors found inc
*address errors and broken links
class addressError implements Runnable
public String addMsg;
public void run()
current.setText("Currently Processing: "+ addMsg);
errorText.append(addMsg);
class navigationError implements Runnable
public String navMsg;
public void run()
errorText.append(navMsg);
class deadEnd implements Runnable
public String dEMsg;
public void run()
errorText.append(dEMsg);
*this method will update the currently
*processing field on the GUI
public class CurrentlyProcessing implements Runnable
public String msg;
//new line
public String msgInfo = msg;
public void run()
current.setText("Currently Processing: " + msg );
* NEW CODE
* NEED THIS CODE SOMEWHERE
* treeText.addObject(msgInfo);
public DefaultMutableTreeNode addObject(Object child)
DefaultMutableTreeNode parentNode = null;
TreePath parentPath = tree.getSelectionPath();
if (parentPath == null)
parentNode = rootNode;
else
parentNode = (DefaultMutableTreeNode)
(parentPath.getLastPathComponent());
return addObject(parentNode, child, true);
public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
Object child)
return addObject(parent, child, false);
public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent,
Object child,boolean shouldBeVisible)
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);
if (parent == null)
parent = rootNode;
treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
if (shouldBeVisible)
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
return childNode;
public class MyTreeModelListener implements TreeModelListener
public void treeNodesChanged (TreeModelEvent e)
DefaultMutableTreeNode node;
node = (DefaultMutableTreeNode)
(e.getTreePath().getLastPathComponent());
try
int index = e.getChildIndices()[0];
node = (DefaultMutableTreeNode)
(node.getChildAt(index));
catch (NullPointerException exc)
public void treeNodesInserted(TreeModelEvent e)
public void treeStructureChanged(TreeModelEvent e)
public void treeNodesRemoved(TreeModelEvent e)
I beleive that this line of code is required:
treeText.addObject(msgInfo);
I have placed it where the action events start the spider, but i keep getting this error:
cannot resolve symbol
symbol : method addObject (java.lang.String)
location: class javax.swing.JTextArea
treeText.addObject(msgInfo);
Also the jtree is not showing the window that I want it to and I am not too sure why. could you have a look to see why? i think it needs a fresh pair of eyes.
Many thanks
MrV -
How to cut, copy and paste a tree node in JTree?????
Hi, Java GUI guru. Thank you for your help in advance.
I am working on a File Explorer project with JTree. There are cut, copy and paste item menus in my menu bar. I need three EventAction methods or classes to implements the three tasks. I tried to use Clipboard to copy and paste tree node. But I can not copy any tree node from my tree.
Are there any body has sample source code about cut, copy, and paste for tree? If possible, would you mind send me your sample source code to [email protected]
I would appreciate you very very much for your help!!!!
X.G.Hi, Paul Clapham:
Thank you for your quick answer.
I store the node in a DefaultMutableTreeNode variable, and assign it to another DefaultMutableTreeNode variable. I set up two classes (CopyNode and PasteNode). Here they are as follows:
//CopyNode class
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
public class CopyNode implements ActionListener{
private TreeList jtree;
String treeNodeName;
TreePath currentSelection;
DefaultMutableTreeNode currentNode;
public CopyNode(TreeList t){
jtree = t;
public void actionPerformed(ActionEvent e){
currentSelection = jtree.tree.getSelectionPath();
if(currentSelection != null){
currentNode = (DefaultMutableTreeNode)(currentSelection.getLastPathComponent());
treeNodeName = currentNode.toString();
//PasteNode class
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
public class PasteNode extends DefaultMutableTreeNode{
private TreeList jtree;
CopyNode copyNode;
public PasteNode(TreeList t){
jtree = t;
copyNode = new CopyNode(t);
public DefaultMutableTreeNode addObject(Object child){
DefaultMutableTreeNode parentNode = null;
TreePath parentPath = jtree.tree.getSelectionPath();
if(parentPath == null){
parentNode = jtree.root;
else{
parentNode = (DefaultMutableTreeNode)parentPath.getLastPathComponent();
return addObject(parentNode, child, true);
public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible){
DefaultMutableTreeNode childNode = copyNode.currentNode;
if(parent == null){
parent = jtree.root;
jtree.treemodel.insertNodeInto(childNode, parent, parent.getChildCount());
if(shouldBeVisible){
jtree.tree.scrollPathToVisible(new TreePath(childNode.getPath()));
return childNode;
I used these two classes objects in "actionPerformed(ActionEvent e)" methods in my tree:
//invoke copyNode
copyItem = new JMenuItem("Copy");
copyItem.addActionListener(copyNode);
//invoke pasteNode
pasteItem = new JMenuItem("Paste");
pasteItem.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
pasteName.addObject(copyName.treeNodeName);
When I run the drive code, making a copy some node from my tree list, I got bunch of error messages.
Can you figour out what is wrong in my two classes? If you have sample code, would you mind mail me for reference.
Thank you very much in advance.
X.G. -
How to hide a tree node from the GUI but still keep it in the tree model?
Hi, All
I used a JTree in my project in which I have a DefaultTreeModel to store all the tree structure and a JTree show it on the screen. But for some reason, I want to hide some of the nodes from the user, but I don't want to remove them from the tree model because later on I still need to use them.
I searched on the web, some people suggested method to hide the root node, but that's not appliable to my project because I want to hide some non-root nodes; Some people also suggested to collapse the parent node when there are child to hide, it is not appliable to me either, because there still some other childnodes (sibling of the node to hide) I want to show.
How can I hide some of the tree node from the user? Thanks for any information.
LindaHere's an example using a derivation of DefaultTreeModel that shows (or does not show) two types of Sneech (appologies to the good Dr Zeus) by overiding two methods on the model.
Now, there are many things wrong with this example (using instanceof, for example), but it's pretty tight and shows one way of doing what you want.
Note: to make it useful, you''d have to change the implementation of setShowStarBelliedSneeches() to do something more sophisticated than simply firing a structure change event on the root node. You'd want to find all the star bellied sneech nodes and call fireTreeNodesRemoved(). That way the tree would stay expanded rather than collapse as it does now.
import javax.swing.JTree;
import javax.swing.JScrollPane;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.tree.TreePath;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
class FilteredTree
private class PlainBelliedSneech {
public String toString() { return "Plain Bellied Sneech"; }
private class StarBelliedSneech {
public String toString() { return "Star Bellied Sneech"; }
private class FilteredTreeModel
extends DefaultTreeModel
private boolean mShowStarBelliedSneeches= true;
private DefaultMutableTreeNode mRoot;
FilteredTreeModel(DefaultMutableTreeNode root)
super(root);
mRoot= root;
public Object getChild(Object parent, int index)
DefaultMutableTreeNode node=
(DefaultMutableTreeNode) parent;
if (mShowStarBelliedSneeches)
return node.getChildAt(index);
int pos= 0;
for (int i= 0, cnt= 0; i< node.getChildCount(); i++) {
if (((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject()
instanceof PlainBelliedSneech)
if (cnt++ == index) {
pos= i;
break;
return node.getChildAt(pos);
public int getChildCount(Object parent)
DefaultMutableTreeNode node=
(DefaultMutableTreeNode) parent;
if (mShowStarBelliedSneeches)
return node.getChildCount();
int childCount= 0;
Enumeration children= node.children();
while (children.hasMoreElements()) {
if (((DefaultMutableTreeNode) children.nextElement()).getUserObject()
instanceof PlainBelliedSneech)
childCount++;
return childCount;
public boolean getShowStarBelliedSneeches() {
return mShowStarBelliedSneeches;
public void setShowStarBelliedSneeches(boolean showStarBelliedSneeches)
if (showStarBelliedSneeches != mShowStarBelliedSneeches) {
mShowStarBelliedSneeches= showStarBelliedSneeches;
Object[] path= { mRoot };
int[] childIndices= new int[root.getChildCount()];
Object[] children= new Object[root.getChildCount()];
for (int i= 0; i< root.getChildCount(); i++) {
childIndices= i;
children[i]= root.getChildAt(i);
fireTreeStructureChanged(this, path, childIndices, children);
private FilteredTree()
final DefaultMutableTreeNode root= new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode parent;
DefaultMutableTreeNode child;
for (int i= 0; i< 2; i++) {
parent= new DefaultMutableTreeNode(new PlainBelliedSneech());
root.add(parent);
for (int j= 0; j< 2; j++) {
child= new DefaultMutableTreeNode(new StarBelliedSneech());
parent.add(child);
for (int k= 0; k< 2; k++)
child.add(new DefaultMutableTreeNode(new PlainBelliedSneech()));
for (int j= 0; j< 2; j++)
parent.add(new DefaultMutableTreeNode(new PlainBelliedSneech()));
parent= new DefaultMutableTreeNode(new StarBelliedSneech());
root.add(parent);
for (int j= 0; j< 2; j++) {
child= new DefaultMutableTreeNode(new PlainBelliedSneech());
parent.add(child);
for (int k= 0; k< 2; k++)
child.add(new DefaultMutableTreeNode(new StarBelliedSneech()));
for (int j= 0; j< 2; j++)
parent.add(new DefaultMutableTreeNode(new StarBelliedSneech()));
final FilteredTreeModel model= new FilteredTreeModel(root);
JTree tree= new JTree(model);
tree.setShowsRootHandles(true);
tree.putClientProperty("JTree.lineStyle", "Angled");
tree.setRootVisible(false);
JScrollPane sp= new JScrollPane(tree);
sp.setPreferredSize(new Dimension(200,400));
final JCheckBox check= new JCheckBox("Show Star Bellied Sneeches");
check.setSelected(model.getShowStarBelliedSneeches());
check.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
model.setShowStarBelliedSneeches(check.isSelected());
JPanel panel= new JPanel(new BorderLayout());
panel.add(check, BorderLayout.NORTH);
panel.add(sp, BorderLayout.CENTER);
JOptionPane.showOptionDialog(
null, panel, "Sneeches on Beeches",
JOptionPane.DEFAULT_OPTION,
JOptionPane.PLAIN_MESSAGE,
null, new String[0], null
System.exit(0);
public static void main(String[] argv) {
new FilteredTree(); -
Can't remove a node from a tree
I am using the custom tree dataDescriptor provided in Flex live
doc. It works for creating the tree and add notes, however when I
try to remove a node from the tree it cant work. Does anyone have
any idea?
This is the code for MyCustomeTreeDataDescriptor.as
package
import mx.collections.ArrayCollection;
import mx.collections.CursorBookmark;
import mx.collections.ICollectionView;
import mx.collections.IViewCursor;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;
import mx.controls.treeClasses.*;
public class MyCustomTreeDataDescriptor implements
ITreeDataDescriptor
// The getChildren method requires the node to be an Object
// with a children field.
// If the field contains an ArrayCollection, it returns the
field
// Otherwise, it wraps the field in an ArrayCollection.
public function getChildren(node:Object,
model:Object=null):ICollectionView
try
if (node is Object) {
if(node.children is ArrayCollection){
return node.children;
}else{
return new ArrayCollection(node.children);
catch (e:Error) {
trace("[Descriptor] exception checking for getChildren");
return null;
// The isBranch method simply returns true if the node is an
// Object with a children field.
// It does not support empty branches, but does support null
children
// fields.
public function isBranch(node:Object,
model:Object=null):Boolean {
try {
if (node is Object) {
if (node.children != null) {
return true;
catch (e:Error) {
trace("[Descriptor] exception checking for isBranch");
return false;
// The hasChildren method Returns true if the node actually
has children.
public function hasChildren(node:Object,
model:Object=null):Boolean {
if (node == null)
return false;
var children:ICollectionView = getChildren(node, model);
try {
if (children.length > 0)
return true;
catch (e:Error) {
return false;
// The getData method simply returns the node as an Object.
public function getData(node:Object,
model:Object=null):Object {
try {
return node;
catch (e:Error) {
return null;
// The addChildAt method does the following:
// If the parent parameter is null or undefined, inserts
// the child parameter as the first child of the model
parameter.
// If the parent parameter is an Object and has a children
field,
// adds the child parameter to it at the index parameter
location.
// It does not add a child to a terminal node if it does not
have
// a children field.
public function addChildAt(parent:Object, child:Object,
index:int,
model:Object=null):Boolean {
var event:CollectionEvent = new
CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
event.kind = CollectionEventKind.ADD;
event.items = [child];
event.location = index;
if (!parent) {
var iterator:IViewCursor = model.createCursor();
iterator.seek(CursorBookmark.FIRST, index);
iterator.insert(child);
else if (parent is Object) {
if (parent.children != null) {
if(parent.children is ArrayCollection) {
parent.children.addItemAt(child, index);
if (model){
model.dispatchEvent(event);
model.itemUpdated(parent);
return true;
else {
parent.children.splice(index, 0, child);
if (model)
model.dispatchEvent(event);
return true;
return false;
// The removeChildAt method does the following:
// If the parent parameter is null or undefined, removes
// the child at the specified index in the model.
// If the parent parameter is an Object and has a children
field,
// removes the child at the index parameter location in the
parent.
public function removeChildAt(parent:Object, child:Object,
index:int, model:Object=null):Boolean
var event:CollectionEvent = new
CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
event.kind = CollectionEventKind.REMOVE;
event.items = [child];
event.location = index;
//handle top level where there is no parent
if (!parent)
var iterator:IViewCursor = model.createCursor();
iterator.seek(CursorBookmark.FIRST, index);
iterator.remove();
if (model)
model.dispatchEvent(event);
return true;
else if (parent is Object)
if (parent.children != undefined)
parent.children.splice(index, 1);
if (model)
model.dispatchEvent(event);
return true;
return false;
This is my tree definition:
<mx:Tree width="143" top="0" bottom="0" left="0"
height="100%"
id="publicCaseTree"
dataDescriptor="{new MyCustomTreeDataDescriptor()}"
dataProvider="{ac}"
defaultLeafIcon="@Embed('assets/caseIcon.png')"
change="publicTreeChanged(event)"
dragEnabled="true"
dragMoveEnabled="false"/>
This is how I remove the selected node from the tree. When
Delete button is clicked, the doDeleteCase function is
exectuted.
public function publicTreeChanged(event:Event):void {
selectedNode =
publicCaseTree.dataDescriptor.getData(Tree(event.target).selectedItem,
ac);
public function doDeleteCase(event:Event):void{
publicCaseTree.dataDescriptor.removeChildAt(publicCaseTree.firstVisibleItem,
selectedNode, 0, ac);
Any help would be appreciated.Thanks.Finally I removed nodes from tree, but not sure I did in the
right way. Anybody encounter the same problem, please
discuss. -
Fetching a URL from a socket output or input stream in a proxy server
We have written a proxy server in java .
It connects with a client on some local port and forwards the request of the client to main server through socket connections.
The code is as follows...
* BasicProxyServer.java
* A simple multithreaded proxy server.
* A client connects to theserver. The server starts a
* separate threads for data flow though two Sockets.
* The first socket communicates with the socket of the client.
* The second socket is used to communcate with the main server
* for which this server is a proxy. The sockets are connected by pipes.
import java.net.*;
import java.io.*;
public class BasicProxyServer {
private static int serverPort;
private static String primaryServerHost;
private static int primaryServerPort;
// 1st arg: port to listen on
// 2nd arg: primary server IP
// 3rd arg: primary server port
public static void main(String [] args) {
serverPort = Integer.parseInt(args[0]);
primaryServerHost = args[1];
primaryServerPort = Integer.parseInt(args[2]);
BasicServer bserv = new BasicServer(serverPort,primaryServerHost,primaryServerPort);
class BasicServer extends Thread {
private int serverPort;
private String primaryHost;
private int primaryPort;
private ServerSocket servSock = null;
public BasicServer(int port, String primSrv, int primPort) {
serverPort = port;
primaryHost = primSrv;
primaryPort = primPort;
start();
public void run() {
Socket clientSock = null;
Socket primaryServerSock = null;
try {
servSock = new ServerSocket(serverPort);
catch (IOException e) {
e.printStackTrace();
while(true) {
try {
clientSock = servSock.accept();
primaryServerSock = new Socket(primaryHost, primaryPort);
PipedInputStream fromClient = new PipedInputStream();
PipedOutputStream toMainServer = new PipedOutputStream(fromClient);
PipedInputStream fromMainServer = new PipedInputStream();
PipedOutputStream toClient = new PipedOutputStream(fromMainServer);
Talk clientToMainServer = new Talk(clientSock, fromClient, primaryServerSock, toMainServer);
Talk mainServerToClient = new Talk(primaryServerSock, fromMainServer, clientSock, toClient);
clientToMainServer.start();
mainServerToClient.start();
catch (IOException e) {
e.printStackTrace();
// Override finalize() to close server socket
protected void finalize() {
if (servSock != null) {
try {
servSock.close();
} catch (IOException e) {
e.printStackTrace();
servSock = null;
class Talk extends Thread {
private Socket incoming;
private Socket outgoing;
private InputStream in;
private OutputStream out;
private InputStream from;
private OutputStream to;
Talk(Socket inSock, InputStream in, Socket outSock, OutputStream out) {
this.in = in;
this.out = out;
incoming = inSock;
outgoing = outSock;
public void run() {
int aByte;
try {
from = incoming.getInputStream();
to = outgoing.getOutputStream();
while(( aByte = from.read()) != -1 ) { //read from socket
out.write(aByte); // write to pipe`
// read the byte from the pipe
to.write(in.read()); // write it to the output socket stream
to.flush();
to.close();
from.close();
if(incoming != null) {
incoming.close();
incoming = null;
if(outgoing != null) {
outgoing.close();
outgoing = null;
catch (SocketException e) {
// there is one for a closed socket. Seems to have no effect.
// e.printStackTrace();
catch (IOException e) {
e.printStackTrace();
Here,when client gives any URL in the address bar in the web browser the request is forwarded to this proxy server.
We want to fetch the URL which client enters in order to implement content filtering and also store the most visited sites by each user .
But we don't know how to fetch the URL from the socket input or output stream.
Can you suggest any suitable solution for the same??Shailesh24 wrote:
We want to fetch the URL which client enters in order to implement content filtering and also store the most visited sites by each user .
But we don't know how to fetch the URL from the socket input or output stream.
Can you suggest any suitable solution for the same??Yes. Write a proxy server that actually speaks HTTP. -
WD ABAP: selecting a tree node from program and scroll to it
Hi guys!
I am using a tree in Web Dynpro ABAP. I would like to select/highlight one node from the coding, without user interaction. Is it possible? I couldn't find any (obvious) way so far...
If it is possible, then let us go a little bit further. Suppose, that the tree grew so big, that cannot fit in the container. Suppose, that you can scroll the tree up/down to see all the nodes. Now, if you mark one tree node from the coding, is it possible somehow, that you scroll the tree automatically, so that the selected node is visible?
I am interested in any solutions within WD ABAP.
If you can only answer one of the questions, that is also appreciated!
Thanks for the help in advance.
Best regards,
Janos Kis
Aerospace&Defense(ERP)Hi Thomas,
thanks for the advice, it works, I have already tried it. The tree node in the lead selection appears highlighted.
The scrolling doesn't work, though. I have tried to put the tree in a scroll container, and I have also tried it without (relying on the browser to scroll). Neither of them worked, it doesn't scroll to the selected node, it remains offscreen. Can you think of a way, to bring it automatically within the visible range? Ideas, anyone?
Actually we would like to implement a search function in the tree, and show the result within the tree (highlight the node, expand, if necessary, and bring it on the screen, if off-screen)
A negative answer is good enough for me, so that I know, that I can stop looking for a solution. Thanks in advance.
Janos -
Invoking taskflow dynamically on to dynamic Region from Tree Nodes
Hello,
I have a tree , each node represents application task flow want to invoke the corresponding task flow when node is clicked into same Dynamic Region, is it possible?
Any idea will be greatly appreciated.
Thanks
RamThanks for quick response, I have a mouse double click event on tree node to fire task flow.
I added a method in region bean to change and update the view scope from treeListener.
public void handleTreeDoubleClick(ClientEvent ce){
System.out.println(ce.getComponent().toString());
RichTree tree = (RichTree)ce.getComponent();
System.out.println("double click");
System.out.println("sNodeValue : menuTreeSelectionListener "+sNodeValue);
FacesContext fctx = FacesContext.getCurrentInstance();
String rowKeyString = sNodeValue;
RegionBean regionBean = new RegionBean();
// regionBean.setDynamicTaskFlowId(TaskFlowId.parse(""));
System.out.println("changing the task flow ...");
regionBean.refreshRegion(TaskFlowId.parse("/WEB-INF/task-flow-welcome.xml#task-flow-welcome"));
public void refreshRegion(TaskFlowId TaskFlowId) {
System.out.println("taskflow id :"+TaskFlowId.toString());
this.setDynamicTaskFlowId(TaskFlowId);
oracle.adf.view.rich.context.AdfFacesContext adfFacesContext = oracle.adf.view.rich.context.AdfFacesContext.getCurrentInstance();
adfFacesContext.getPageFlowScope().put("CurrentTaskflowId", TaskFlowId);
But region is not getting refrehed with new taskflow id:
console output.............
changing the task flow ...
taskflow id :/WEB-INF/task-flow-welcome.xml#task-flow-welcome
any thoughts?
Thanks
Ram -
Navigation from tree node to page
Hi
plz suggest me from where should i start. I have similar use case as given in this link
http://jdevadf.oracle.com/adf-richclient-demo/faces/index.jspx
left side i have tree and right side pages .Whenever i click on tree node corresponding page should display.
How can i achieve this ?
Thanks
niteshYou know that the sample you are referring to comes with the source code. You just have to click on the page source link to get to the source.
One way to archive this is to use a link element to render the node. The link can directly navigate to the right target or show the right region.
If you need something not sophisticated you can use a selection listener (http://www.oracle.com/technetwork/developer-tools/adf/learnmore/november2011-otn-harvest-1389769.pdf) and to everything from a bean method.
As you did not give any information about your Jdev version and how the tree is connected to the navigation it's hard to give more advice.
Timo -
A Cisco Stack 3750X switch report the following error message:
%UTIL-3-TREE: Data structure error--attempt to remove an unthreaded node from a tree.
every minute +-20 sec
Cisco IOS Software, C3750E Software (C3750E-IPBASEK9-M), Version 15.0(2)SE4, RELEASE SOFTWARE (fc1)
analog bug: https://tools.cisco.com/bugsearch/bug/CSCsz93221WS-C3750G-24PS-E C3750-IPBASEK9-M version 12.2(53)SE2
After implementing 802.1x with Avaya IP phones
%UTIL-3-TREE: Data structure error--attempt to remove an unthreaded node from a tree
Port then fails authentication and goes into vl-err-dis
Maybe you are looking for
-
How can I apply existing WCS "WLAN Config" templates to a new WLC?
We've been running a pair of WLC 4402s managed by WCS, thus we are still on the older 7.0.235.0 (WCS) / 7.0.235.3 (WLC) release. I'm trying to add an additional WLC 4402-50 as a hot spare. I first ran the manual setup steps to give it an IP in our ra
-
Editing channels in a task using DAQmx in Labview
Dear All A few days back while I was trying to build an application to dynamically change my tasks in Labview ,I have encountered the following problems 1)MAX is allowing me to configure multiple channels onto the same physical analog input channels.
-
Balance transfer across company codes
Hello, I want to transfer open balance from one account to another. Both accounts have different company code. Can you please suggest me way to transfer balance in this case? SAP standard transaction FP40 doesn't allow balance transfer accross compan
-
Can't figure out how to update my old system
-
Type Mismatch Error with Window Class
i have been trying in vain to recreate various examples that spawn popup windows. i have been certain to follow instructions carefully in each example (from both livedocs and the forums and other sites)...copying and pasting the code where applicable