This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 30017
Collapse All | Expand All

(-)NavigationSupport.java (-43 / +330 lines)
Lines 13-18 Link Here
13
13
14
package org.netbeans.modules.scripting.navigation;
14
package org.netbeans.modules.scripting.navigation;
15
15
16
import java.awt.Component;
17
import java.awt.Container;
18
import java.awt.Dialog;
16
import java.awt.event.ActionEvent;
19
import java.awt.event.ActionEvent;
17
import java.beans.PropertyVetoException;
20
import java.beans.PropertyVetoException;
18
import java.lang.reflect.*;
21
import java.lang.reflect.*;
Lines 28-33 Link Here
28
import java.util.Properties;
31
import java.util.Properties;
29
import java.util.Stack;
32
import java.util.Stack;
30
33
34
import javax.swing.*;
35
31
import org.openide.TopManager;
36
import org.openide.TopManager;
32
import org.openide.actions.ActionManager;
37
import org.openide.actions.ActionManager;
33
import org.openide.actions.ToolsAction;
38
import org.openide.actions.ToolsAction;
Lines 58-64 Link Here
58
	public Properties forteProps	= new Properties(System.getProperties());
63
	public Properties forteProps	= new Properties(System.getProperties());
59
	public final String moduleName = "fjscript";	// NOI18N	
64
	public final String moduleName = "fjscript";	// NOI18N	
60
65
61
	public boolean	topManagerLoaded = true; 
62
	/**
66
	/**
63
	* This ExplorerManager is the context for selected nodes in Fjscript.
67
	* This ExplorerManager is the context for selected nodes in Fjscript.
64
	* This is used by setCurObject to activate the currently selected object.
68
	* This is used by setCurObject to activate the currently selected object.
Lines 104-109 Link Here
104
	 */
108
	 */
105
	public PrintStream outStrm   = System.out;
109
	public PrintStream outStrm   = System.out;
106
110
111
	/**
112
	 * used to create objects
113
	 */
114
	private Dialog                 templateDialog = null;
115
	private NonGuiTemplateWizard   templateWizard = null;
116
107
        public NavigationSupport(InputStream in,PrintStream out) {
117
        public NavigationSupport(InputStream in,PrintStream out) {
108
            inStrm = in;
118
            inStrm = in;
109
            outStrm = out;
119
            outStrm = out;
Lines 118-130 Link Here
118
		boolean wasExited = exited;
128
		boolean wasExited = exited;
119
		exited = true;
129
		exited = true;
120
130
121
		// this should test TopManager.isInitialized(),
131
		if (!wasExited && TopManager.isInitialized())
122
		// but that doesn't exist, so use local topManagerLoaded,
132
					TopManager.getDefault().exit();
123
		// which is set in FjscriptMain.
124
		// 
125
///		if (!wasExited && TopManager.isInitialized())
126
		if (!wasExited && topManagerLoaded)
127
			TopManager.getDefault().exit();
128
		System.exit(status);
133
		System.exit(status);
129
	}
134
	}
130
135
Lines 159-166 Link Here
159
			// the system class loader won't be able to find them.
164
			// the system class loader won't be able to find them.
160
			// 
165
			// 
161
			ClassLoader curLoader;
166
			ClassLoader curLoader;
162
//			if (TopManager.isInitialized()) {
167
			if (TopManager.isInitialized()) {
163
			if (topManagerLoaded) {
164
				curLoader = TopManager.getDefault().currentClassLoader();
168
				curLoader = TopManager.getDefault().currentClassLoader();
165
				if (curLoader != null) {
169
				if (curLoader != null) {
166
					cls = curLoader.loadClass(className);
170
					cls = curLoader.loadClass(className);
Lines 172-178 Link Here
172
		}
176
		}
173
		catch (ClassNotFoundException e) {
177
		catch (ClassNotFoundException e) {
174
			if (showException)
178
			if (showException)
175
				printException("Fjscript.loadClass", e);	// NOI18N
179
				printException("NavigationSupport.loadClass", e);	// NOI18N
176
		}
180
		}
177
		return(cls);
181
		return(cls);
178
	}
182
	}
Lines 192-201 Link Here
192
			}
196
			}
193
		}
197
		}
194
		catch (IllegalAccessException iae) {
198
		catch (IllegalAccessException iae) {
195
			printException("Fjscript.createObject", iae);	// NOI18N
199
			printException("NavigationSupport.createObject", iae);	// NOI18N
196
		}
200
		}
197
		catch (InstantiationException ie) {
201
		catch (InstantiationException ie) {
198
			printException("Fjscript.createObject", ie);	// NOI18N
202
			printException("NavigationSupport.createObject", ie);	// NOI18N
199
		}
203
		}
200
		
204
		
201
		return obj;
205
		return obj;
Lines 216-222 Link Here
216
	public int listMethods(Class c, boolean details) {
220
	public int listMethods(Class c, boolean details) {
217
		Method 		ms[];
221
		Method 		ms[];
218
		if (c == null) {
222
		if (c == null) {
219
			print("Fjscript.listMethods: ");	// NOI18N
223
			print("NavigationSupport.listMethods: ");	// NOI18N
220
			println(getString("MSG_NullClass"));
224
			println(getString("MSG_NullClass"));
221
			return CMD_FAIL;
225
			return CMD_FAIL;
222
		}
226
		}
Lines 236-242 Link Here
236
		}
240
		}
237
		catch(Exception e)
241
		catch(Exception e)
238
		{
242
		{
239
			printException("Fjscript.listMethods", e);	// NOI18N
243
			printException("NavigationSupport.listMethods", e);	// NOI18N
240
			return CMD_FAIL;
244
			return CMD_FAIL;
241
		}
245
		}
242
		return CMD_OK;
246
		return CMD_OK;
Lines 273-279 Link Here
273
		}
277
		}
274
		catch(Exception e)
278
		catch(Exception e)
275
		{
279
		{
276
			printException("Fjscript.listConstructors", e);	// NOI18N
280
			printException("NavigationSupport.listConstructors", e);	// NOI18N
277
			return CMD_FAIL;
281
			return CMD_FAIL;
278
		}
282
		}
279
		return CMD_OK;
283
		return CMD_OK;
Lines 330-336 Link Here
330
	public final static int DIRECTORY	= 1;
334
	public final static int DIRECTORY	= 1;
331
	public final static int JAR 		= 2;
335
	public final static int JAR 		= 2;
332
336
333
	public int mountFileSystem (String fileName, int type) {
337
	public FileSystem mountFileSystem (String fileName, int type) {
334
		FileSystem fs;
338
		FileSystem fs;
335
		fileName = expandVars(fileName);
339
		fileName = expandVars(fileName);
336
340
Lines 350-381 Link Here
350
										  new Integer(type),
354
										  new Integer(type),
351
										  new Integer(DIRECTORY),
355
										  new Integer(DIRECTORY),
352
										  new Integer(JAR)));
356
										  new Integer(JAR)));
353
				return CMD_FAIL;
357
				return null;
354
			}
358
			}
355
		  
359
		  
356
		}
360
		}
357
		catch (IOException ioe) {
361
		catch (IOException ioe) {
358
			printException("Fjscript.mountDirectory", ioe);	// NOI18N
362
			printException("NavigationSupport.mountDirectory", ioe);	// NOI18N
359
			return CMD_FAIL;
363
			return null;
360
		}
364
		}
361
		catch (java.beans.PropertyVetoException pe){
365
		catch (java.beans.PropertyVetoException pe){
362
			printException("Fjscript.mountFileSystem", pe);	// NOI18N
366
			printException("NavigationSupport.mountFileSystem", pe);	// NOI18N
363
			return CMD_FAIL;
367
			return null;
364
		}
368
		}
365
369
366
		TopManager.getDefault().getRepository().addFileSystem(fs);
370
		TopManager.getDefault().getRepository().addFileSystem(fs);
367
		return CMD_OK;
371
		return fs;
368
	}
372
	}
369
373
370
	public int mountDir(String fileName) {
374
	public FileSystem mountDir(String fileName) {
371
		return mountDirectory(fileName);
375
		return mountDirectory(fileName);
372
	}
376
	}
373
377
374
	public int mountDirectory(String fileName) {
378
	public FileSystem mountDirectory(String fileName) {
375
		return mountFileSystem(fileName, DIRECTORY);
379
		return mountFileSystem(fileName, DIRECTORY);
376
	}
380
	}
377
381
378
	public int mountJar(String fileName) {
382
	public FileSystem mountJar(String fileName) {
379
		return mountFileSystem(fileName, JAR);
383
		return mountFileSystem(fileName, JAR);
380
	}
384
	}
381
385
Lines 405-415 Link Here
405
				}
409
				}
406
			}
410
			}
407
			else if (o instanceof JarFileSystem) {
411
			else if (o instanceof JarFileSystem) {
408
				JarFileSystem jfs=(JarFileSystem) o;
412
                JarFileSystem jfs=(JarFileSystem) o;
409
				if (jfs.getJarFile().equals(theFile)) {
413
                File jfsFile = jfs.getJarFile();
410
					fs=jfs;
414
                boolean equal = jfsFile.equals(theFile);
411
					break;
415
                //
412
				}
416
                // check for canonical file, too, to handle case
417
                // where mounted jar is a symbolic link (b4363096)
418
                //
419
                if (!equal) {
420
                    try {
421
                    equal = jfsFile.equals(theFile.getCanonicalFile());
422
                    }
423
                    catch (IOException io) {
424
                    //ignore
425
                    }
426
                }
427
                if (equal) {
428
                    fs=jfs;
429
                    break;
430
                }
413
			}
431
			}
414
			//else  need to handle other file systems (CVS, Teamware, etc)
432
			//else  need to handle other file systems (CVS, Teamware, etc)
415
			//--why isn't there a generic equals(fileName) for FileSystem?
433
			//--why isn't there a generic equals(fileName) for FileSystem?
Lines 427-432 Link Here
427
		return CMD_OK;
445
		return CMD_OK;
428
	}
446
	}
429
447
448
    public int unmountAll() {
449
        Repository repo = TopManager.getDefault().getRepository();
450
        Enumeration all=repo.getFileSystems();
451
        while (all.hasMoreElements()) {
452
            FileSystem fs = (FileSystem)all.nextElement();
453
            if (!fs.isHidden() && !fs.isDefault())
454
                repo.removeFileSystem(fs);
455
        }
456
        return CMD_OK;
457
    }
458
430
	public Object loadCommandClass (Object dataObj) {
459
	public Object loadCommandClass (Object dataObj) {
431
460
432
		if (dataObj == null)
461
		if (dataObj == null)
Lines 610-619 Link Here
610
			explorerMgr.setSelectedNodes(arr);
639
			explorerMgr.setSelectedNodes(arr);
611
		}
640
		}
612
		catch (PropertyVetoException e) {
641
		catch (PropertyVetoException e) {
613
			printException("Fjscript.setSelectedNodes", e);	// NOI18N
642
			printException("NavigationSupport.setSelectedNodes", e);	// NOI18N
614
		}
643
		}
615
		catch (IllegalArgumentException e) {
644
		catch (IllegalArgumentException e) {
616
			printException("Fjscript.setSelectedNodes", e);	// NOI18N
645
			printException("NavigationSupport.setSelectedNodes", e);	// NOI18N
617
		}
646
		}
618
	}
647
	}
619
648
Lines 695-701 Link Here
695
			return dataObj;
724
			return dataObj;
696
		}
725
		}
697
		catch(DataObjectNotFoundException donf) {
726
		catch(DataObjectNotFoundException donf) {
698
			printException("Fjscript.findObject", donf);	// NOI18N
727
			printException("NavigationSupport.findObject", donf);	// NOI18N
699
		}
728
		}
700
		return null;
729
		return null;
701
	}
730
	}
Lines 802-816 Link Here
802
			}
831
			}
803
		}
832
		}
804
	}
833
	}
834
835
    /**
836
     * Run the specified action on the current data object (curDataObj).
837
     * Loads the class <actionName> and calls its actionPerformed method
838
     * on the current data object. 
839
     *
840
     * @param actionName full class name of the action to run
841
     */
842
    public int doAction (String actionName)  {
843
        return doAction(actionName, 0);
844
    }
845
        
846
    /**
847
     * A variant of doAction for passing modifiers such as ActionEvent.CTRL_MASK.
848
     * Run the specified action on the current data object (curDataObj).
849
     * Loads the class <actionName> and calls its actionPerformed method
850
     * on the current data object. 
851
     *
852
     * @param actionName full class name of the action to run
853
     * @param modifiers the modifier keys held down during this action
854
     */
855
    public int doAction (String actionName, int modifiers)  {
856
        return doAction(actionName, modifiers, 0, "");
857
    }
858
        
859
    /**
860
     * Run the specified action on the current data object (curDataObj).
861
     * Loads the class <actionName> and calls its actionPerformed method
862
     * on the current data object. 
863
     * A variant of doAction with the full set of options for creating the ActionEvent passed to the action.
864
     *
865
     * @param actionName full class name of the action to run
866
     * @param modifiers the modifier keys held down during this action
867
     * @param id an integer that identifies the event
868
     * @param command a string that may specify a command (possibly one of several) associated with the event
869
     *
870
     * @see java.awt.event.ActionEvent
871
     */
872
    public int doAction (String actionName, int modifiers, int id, String command)  {
873
        String origName = actionName;
805
874
806
	public int doAction (String actionName)  {
807
		checkCurDataObj();
875
		checkCurDataObj();
808
876
809
		Class cls = loadClass(actionName, false);
877
		Class cls = loadClass(actionName, false);
810
		if (cls == null)
878
		if (cls == null) {
811
			cls = loadClass("org.openide.actions." + actionName, false);
879
		    actionName = "org.openide.actions." + actionName;
880
		    cls = loadClass(actionName, false);
881
		}
812
		if (cls == null) {
882
		if (cls == null) {
813
			println(getString("MSG_NoClass", actionName));
883
			println(getString("MSG_NoClass", origName));
814
			return CMD_FAIL;
884
			return CMD_FAIL;
815
		}
885
		}
816
	  
886
	  
Lines 825-831 Link Here
825
		}
895
		}
826
		
896
		
827
		Node node = curDataObj.getNodeDelegate();
897
		Node node = curDataObj.getNodeDelegate();
828
		((SystemAction) obj).actionPerformed(new ActionEvent(node, 0, "")); // NOI18N
898
		((SystemAction) obj).actionPerformed(new ActionEvent(node, id, command, modifiers)); // NOI18N
829
899
830
		return CMD_OK;
900
		return CMD_OK;
831
	}
901
	}
Lines 932-942 Link Here
932
		if (curObj != null) {
1002
		if (curObj != null) {
933
			String clsName = curObj.getClass().getName();
1003
			String clsName = curObj.getClass().getName();
934
			String name = clsName.substring(clsName.lastIndexOf('.')+1);
1004
			String name = clsName.substring(clsName.lastIndexOf('.')+1);
1005
            String helpStr;
935
1006
936
			if (curObj instanceof CommandHelper) {
1007
            if (curObj instanceof CommandHelper
1008
                && (helpStr = ((CommandHelper)curObj).help()) != "") {
937
				println(getString("MSG_CmdClass", name));
1009
				println(getString("MSG_CmdClass", name));
938
				println(getString("MSG_UndClass"));
1010
				println(getString("MSG_UndClass"));
939
				println(((CommandHelper)curObj).help());
1011
				println(helpStr);
940
			}
1012
			}
941
			else {
1013
			else {
942
				println(getString("MSG_MethodsOn", name));
1014
				println(getString("MSG_MethodsOn", name));
Lines 1006-1012 Link Here
1006
    */
1078
    */
1007
1079
1008
	public int loadPropertyFile (String fileName) {
1080
	public int loadPropertyFile (String fileName) {
1009
		final String methodName = "Fjscript.loadPropertyFile"; // NOI18N
1081
		final String methodName = "NavigationSupport.loadPropertyFile"; // NOI18N
1010
1082
1011
		Exception exc = null;
1083
		Exception exc = null;
1012
		fileName = expandVars(fileName);
1084
		fileName = expandVars(fileName);
Lines 1174-1180 Link Here
1174
                    ModuleInstaller.deployTestModule (new File (fileName).getAbsoluteFile ());
1246
                    ModuleInstaller.deployTestModule (new File (fileName).getAbsoluteFile ());
1175
		}
1247
		}
1176
		catch (IOException ioe) {
1248
		catch (IOException ioe) {
1177
			printException("Fjscript.loadModule", ioe);
1249
			printException("NavigationSupport.loadModule", ioe);
1178
			return CMD_FAIL;
1250
			return CMD_FAIL;
1179
		}
1251
		}
1180
		
1252
		
Lines 1343-1348 Link Here
1343
	}
1415
	}
1344
        
1416
        
1345
        
1417
        
1418
    /**
1419
     * Run the new from template with the given template.
1420
     * You can use the templateSetXXX commands to set the values. When
1421
     * done do templateInstantiate.
1422
     */
1423
    public void templateStart(String folder, String name) {
1424
        DataObject child = getTemplate(folder, name);
1425
1426
        if (child == null) {
1427
            outStrm.println(  "Template " 
1428
                            + folder
1429
                            + "/"
1430
                            + name
1431
                            + "not found.");
1432
            return;
1433
        }
1434
        templateWizard = new NonGuiTemplateWizard();
1435
        templateWizard.setTemplate(child);
1436
        templateDialog = TopManager.getDefault().createDialog(templateWizard);
1437
    }
1438
1439
    public void templateFinish() throws Throwable {
1440
        if (templateWizard == null) {
1441
            outStrm.println(
1442
                "You must do a templateStart before you can run this command.");
1443
            return;
1444
        }
1445
        templateWizard.finish();
1446
        templateWizard = null;
1447
        templateDialog = null;
1448
    }
1449
1450
    public Dialog templateGetDialog() {
1451
        return templateDialog;
1452
    }
1453
1454
    public TemplateWizard templateGetWizard() {
1455
        return templateWizard;
1456
    }
1457
1458
    public void templatePrintDialog() {
1459
        if (templateDialog == null) {
1460
            outStrm.println("You must run templateStart before this command.");
1461
            return;
1462
        }
1463
        outStrm.println(templateDialog.getClass().getName() + ":");
1464
        printDialog(templateDialog, "");
1465
    }
1466
1467
    public void printDialog(Container cont, String indent) {
1468
        Component[] comps;
1469
1470
        indent = indent + "    ";
1471
        comps = cont.getComponents();
1472
        for (int i = 0; i < comps.length; i++) {
1473
            String txt = "";
1474
1475
            try {
1476
                Method getText;
1477
1478
                getText = comps[i].getClass().getMethod("getText", null);
1479
                txt = (String) getText.invoke(comps[i], null);
1480
            } catch (Throwable t) {
1481
                txt = "";
1482
            }
1483
            outStrm.println(  indent
1484
                            + comps[i].getClass().getName()
1485
                            + ":"
1486
                            + comps[i].getName()
1487
                            + ":"
1488
                            + txt);
1489
            if (comps[i] instanceof Container) {
1490
                printDialog((Container) comps[i], indent);
1491
            }
1492
        }
1493
    }
1494
1495
    public void templatePrintTextField(String name) {
1496
        JTextField tFld = getTextField(name);
1497
1498
        if (tFld != null) {
1499
            outStrm.println(tFld.getText());
1500
        }
1501
    }
1502
1503
    public void templateSetTextField(String name, String value) {
1504
        JTextField tFld = getTextField(name);
1505
1506
        if (tFld != null) {
1507
            tFld.setText(value);
1508
        }
1509
    }
1510
1511
    public void templateClickButton(String name) {
1512
        AbstractButton b = getButton(name);
1513
1514
        if (b != null) {
1515
            b.doClick();
1516
        }
1517
    }
1518
1519
1520
    protected JTextField getTextField(String name) {
1521
        if (templateDialog == null) {
1522
            outStrm.println(
1523
                    "You must run templateStart before running this command.");
1524
            return null;
1525
        }
1526
        JTextField tFld = getTextField(templateDialog, name);
1527
        if (tFld == null) {
1528
            outStrm.println("Text field " + name + " not found.");
1529
            return null;
1530
        }
1531
        return tFld;
1532
    }
1533
1534
    protected JTextField getTextField(Container cont, String name) {
1535
        Component[] comps;
1536
1537
        comps = cont.getComponents();
1538
        for (int i = 0; i < comps.length; i++) {
1539
            if (       comps[i] instanceof JLabel
1540
                    && i + 1 < comps.length
1541
                    && comps[i+1] instanceof JTextField) {
1542
                JLabel lab = (JLabel) comps[i];
1543
1544
                if (lab.getText().equals(name)) {
1545
                    return (JTextField) comps[i+1];
1546
                }
1547
            }
1548
            if (comps[i] instanceof Container) {
1549
                JTextField rval;
1550
1551
                if ((rval = getTextField((Container) comps[i], name)) != null) {
1552
                    return rval;
1553
                }
1554
            }
1555
        }
1556
        return null;
1557
    }
1558
1559
    protected AbstractButton getButton(String name) {
1560
        if (templateDialog == null) {
1561
            outStrm.println(
1562
                    "You must run templateStart before running this command.");
1563
            return null;
1564
        }
1565
        AbstractButton button = (AbstractButton) getComponent(templateDialog,
1566
                                                          name,
1567
                                                          AbstractButton.class);
1568
        if (button == null) {
1569
            outStrm.println("Button " + name + " not found.");
1570
            return null;
1571
        }
1572
        return button;
1573
    }
1574
1575
    protected Component getComponent(Container cont,
1576
                                            String name,
1577
                                            Class theClass) {
1578
        Component[] comps;
1579
1580
        comps = cont.getComponents();
1581
        for (int i = 0; i < comps.length; i++) {
1582
            if (theClass.isAssignableFrom(comps[i].getClass())) {
1583
                String txt = null;
1584
1585
                if (       comps[i].getName() != null
1586
                        && comps[i].getName().equals(name)) {
1587
                    return comps[i];
1588
                }
1589
                try {
1590
                    Method getText = null;
1591
1592
                    getText = comps[i].getClass().getMethod("getText", null);
1593
                    txt = (String) getText.invoke(comps[i], null);
1594
                } catch (Throwable t) {
1595
                    txt = null;
1596
                }
1597
                if (txt != null && txt.equals(name)) {
1598
                    return comps[i];
1599
                }
1600
            }
1601
            if (comps[i] instanceof Container) {
1602
                Component rval;
1603
1604
                rval = getComponent((Container) comps[i], name, theClass);
1605
                if (rval != null) {
1606
                    return rval;
1607
                }
1608
            }
1609
        }
1610
        return null;
1611
    }
1612
1613
    public class NonGuiTemplateWizard extends TemplateWizard {
1614
        public void finish() throws Throwable {
1615
            handleInstantiate();
1616
        }
1617
    }
1618
1619
    // The equivalent to the unix cat command for InputStream
1620
    public int printInputStream(InputStream is) {
1621
        byte[] buf = new byte[1024];
1622
        int len;
1623
        try {
1624
            while ((len = is.read(buf)) > 0) {
1625
                outStrm.write(buf, 0, len);
1626
            }
1627
        } catch (IOException ioe) {
1628
            printException("NonGui.printInputStream", ioe);
1629
            return CMD_FAIL;
1630
        }
1631
        return CMD_OK;
1632
    }
1346
}
1633
}
1347
1634
1348
//
1635
//

Return to bug 30017