1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-06 16:45:25 +02:00

[142968] fixed some "com.ibm.*" strings in the tutorial.

This commit is contained in:
David Dykstal 2006-12-14 22:04:00 +00:00
parent ba57b6db27
commit a4743e1ac9
3 changed files with 129 additions and 66 deletions

View file

@ -15,21 +15,25 @@
<pre><samp> <pre><samp>
package samples.ui.propertypages; package samples.ui.propertypages;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import RSESamples.*;
import org.eclipse.rse.files.ui.propertypages.SystemAbstractRemoteFilePropertyPageExtensionAction; import org.eclipse.rse.files.ui.propertypages.SystemAbstractRemoteFilePropertyPageExtensionAction;
import com.ibm.etools.systems.subsystems.*; import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import com.ibm.etools.systems.core.ui.*; import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.ui.SystemWidgetHelpers;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import java.util.*; import samples.RSESamplesPlugin;
/** /**
* A sample property page for a remote object, which in this case is scoped via the * A sample property page for a remote object, which in this case is scoped via the
* extension point xml to only apply to folder objects. * extension point xml to only apply to folder objects.
*/ */
public class <b>FolderInfoPropertyPage</b> public class FolderInfoPropertyPage
extends SystemAbstractRemoteFilePropertyPageExtensionAction extends SystemAbstractRemoteFilePropertyPageExtensionAction
implements SelectionListener implements SelectionListener
{ {
@ -47,33 +51,45 @@ public class <b>FolderInfoPropertyPage</b>
/** /**
* Constructor for FolderInfoPropertyPage. * Constructor for FolderInfoPropertyPage.
*/ */
public <b>FolderInfoPropertyPage</b>() public FolderInfoPropertyPage()
{ {
super(); super();
} }
// -------------------------- // --------------------------
// <i>Parent method overrides...</i> // Parent method overrides...
// -------------------------- // --------------------------
/**
* @see org.eclipse.rse.ui.propertypages.SystemBasePropertyPage#createContentArea(Composite) /* (non-Javadoc)
* @see org.eclipse.rse.files.ui.propertypages.SystemAbstractRemoteFilePropertyPageExtensionAction#createContentArea(org.eclipse.swt.widgets.Composite)
*/ */
protected Control <b>createContentArea</b>(Composite parent) protected Control createContentArea(Composite parent)
{ {
Composite composite = SystemWidgetHelpers.createComposite(parent, 2); Composite composite = SystemWidgetHelpers.createComposite(parent, 2);
ResourceBundle rb = RSESamplesPlugin.getDefault().getResourceBundle();
// draw the gui // draw the gui
sizeLabel = SystemWidgetHelpers.createLabeledLabel(composite, rb, &quot;pp.size.&quot;, false); sizeLabel = SystemWidgetHelpers.createLabeledLabel(composite,
filesLabel = SystemWidgetHelpers.createLabeledLabel(composite, rb, &quot;pp.files.&quot;, false); RSESamplesPlugin.getResourceString("pp.size.label"), //$NON-NLS-1$
foldersLabel = SystemWidgetHelpers.createLabeledLabel(composite, rb, &quot;pp.folders.&quot;, false); RSESamplesPlugin.getResourceString("pp.size.tooltip"), //$NON-NLS-1$
stopButton = SystemWidgetHelpers.createPushButton(composite, null, rb, &quot;pp.stopButton.&quot;); false);
filesLabel = SystemWidgetHelpers.createLabeledLabel(composite,
RSESamplesPlugin.getResourceString("pp.files.label"), //$NON-NLS-1$
RSESamplesPlugin.getResourceString("pp.files.tooltip"), //$NON-NLS-1$
false);
foldersLabel = SystemWidgetHelpers.createLabeledLabel(composite,
RSESamplesPlugin.getResourceString("pp.folders.label"), //$NON-NLS-1$
RSESamplesPlugin.getResourceString("pp.folders.tooltip"), //$NON-NLS-1$
false);
stopButton = SystemWidgetHelpers.createPushButton(composite, null,
RSESamplesPlugin.getResourceString("pp.stopButton.label"), //$NON-NLS-1$
RSESamplesPlugin.getResourceString("pp.stopButton.tooltip") //$NON-NLS-1$
);
stopButton.addSelectionListener(this); stopButton.addSelectionListener(this);
setValid(false); // Disable OK button until thread is done setValid(false); // Disable OK button until thread is done
// show &quot;Processing...&quot; message // show "Processing..." message
setMessage(RSESamplesPlugin.getPluginMessage(&quot;RSSG1002&quot;)); setMessage(RSESamplesPlugin.getPluginMessage("RSSG1002")); //$NON-NLS-1$
// create instance of Runnable to allow asynchronous GUI updates from background thread // create instance of Runnable to allow asynchronous GUI updates from background thread
guiUpdater = new RunnableGUIClass(); guiUpdater = new RunnableGUIClass();
@ -87,8 +103,9 @@ public class <b>FolderInfoPropertyPage</b>
/** /**
* Intercept from PreferencePage. Called when user presses Cancel button. * Intercept from PreferencePage. Called when user presses Cancel button.
* We stop the background thread. * We stop the background thread.
* @see org.eclipse.jface.preference.PreferencePage#performCancel()
*/ */
public boolean <b>performCancel</b>() public boolean performCancel()
{ {
killThread(); killThread();
return true; return true;
@ -99,7 +116,7 @@ public class <b>FolderInfoPropertyPage</b>
* If the user presses the X to close this dialog, we * If the user presses the X to close this dialog, we
* need to stop that background thread. * need to stop that background thread.
*/ */
public void <b>dispose</b>() public void dispose()
{ {
killThread(); killThread();
super.dispose(); super.dispose();
@ -109,9 +126,9 @@ public class <b>FolderInfoPropertyPage</b>
* Private method to kill our background thread. * Private method to kill our background thread.
* Control doesn't return until it ends. * Control doesn't return until it ends.
*/ */
private void <b>killThread</b>() private void killThread()
{ {
if (!stopped &amp;&amp; workerThread.isAlive()) if (!stopped && workerThread.isAlive())
{ {
stopped = true; stopped = true;
try { try {
@ -121,13 +138,14 @@ public class <b>FolderInfoPropertyPage</b>
} }
// ------------------------------------------- // -------------------------------------------
// <i>Methods from SelectionListener interface...</i> // Methods from SelectionListener interface...
// ------------------------------------------- // -------------------------------------------
/** /**
* From SelectionListener * From SelectionListener
* @see SelectionListener#widgetSelected(SelectionEvent)
*/ */
public void <b>widgetSelected</b>(SelectionEvent event) public void widgetSelected(SelectionEvent event)
{ {
if (event.getSource() == stopButton) if (event.getSource() == stopButton)
{ {
@ -137,27 +155,29 @@ public class <b>FolderInfoPropertyPage</b>
} }
/** /**
* From SelectionListener * From SelectionListener
* @see SelectionListener#widgetDefaultSelected(SelectionEvent)
*/ */
public void <b>widgetDefaultSelected</b>(SelectionEvent event) {} public void widgetDefaultSelected(SelectionEvent event)
{
}
// ---------------- // ----------------
// <i>Inner classes...</i> // Inner classes...
// ---------------- // ----------------
/** /**
* Inner class encapsulating the background work to be done, so it may be executed * Inner class encapsulating the background work to be done, so it may be executed
* in background thread. * in background thread.
*/ */
private class <b>RunnableClass</b> extends Thread private class RunnableClass extends Thread
{ {
IRemoteFile inputFolder; IRemoteFile inputFolder;
<b>RunnableClass</b>(IRemoteFile inputFolder) RunnableClass(IRemoteFile inputFolder)
{ {
this.inputFolder = inputFolder; this.inputFolder = inputFolder;
} }
public void <b>run</b>() public void run()
{ {
if (stopped) if (stopped)
return; return;
@ -174,12 +194,14 @@ public class <b>FolderInfoPropertyPage</b>
* Recursively walk a folder, updating the running tallies. * Recursively walk a folder, updating the running tallies.
* Update the GUI after processing each subfolder. * Update the GUI after processing each subfolder.
*/ */
private void <b>walkFolder</b>(IRemoteFile currFolder) private void walkFolder(IRemoteFile currFolder)
{ {
IRemoteFile[] folders = currFolder.getParentRemoteFileSubSystem().listFoldersAndFiles(currFolder); try
if ((folders != null) &amp;&amp; (folders.length&gt;0))
{ {
for (int idx=0; !stopped &amp;&amp; (idx&lt;folders.length); idx++) IRemoteFile[] folders = currFolder.getParentRemoteFileSubSystem().listFoldersAndFiles( currFolder, null);
if ((folders != null) && (folders.length>0))
{
for (int idx=0; !stopped && (idx&lt;folders.length); idx++)
{ {
// is this a folder? // is this a folder?
if (folders[idx].isDirectory()) if (folders[idx].isDirectory())
@ -196,17 +218,22 @@ public class <b>FolderInfoPropertyPage</b>
} }
} }
} }
} // <i>end of walkFolder method</i> }
catch (SystemMessageException e)
{
} // <i>end of inner class</i> }
} // end of walkFolder method
} // end of inner class
/** /**
* Inner class encapsulating the GUI work to be done from the * Inner class encapsulating the GUI work to be done from the
* background thread. * background thread.
*/ */
private class <b>RunnableGUIClass</b> implements Runnable private class RunnableGUIClass implements Runnable
{ {
public void <b>run</b>() public void run()
{ {
if (stopButton.isDisposed()) if (stopButton.isDisposed())
return; return;
@ -220,7 +247,7 @@ public class <b>FolderInfoPropertyPage</b>
{ {
setValid(true); // re-enable OK button setValid(true); // re-enable OK button
stopButton.setEnabled(false); // disable Stop button stopButton.setEnabled(false); // disable Stop button
clearMessage(); // clear &quot;Processing...&quot; message clearMessage(); // clear "Processing..." message
} }
} }
} }
@ -229,14 +256,13 @@ public class <b>FolderInfoPropertyPage</b>
/** /**
* Update the GUI with the current status * Update the GUI with the current status
*/ */
private void <b>updateGUI</b>() private void updateGUI()
{ {
Display.getDefault().asyncExec(guiUpdater); Display.getDefault().asyncExec(guiUpdater);
} }
} }
</samp></pre> </samp></pre>
</p> </p>
</body> </body>

View file

@ -15,37 +15,49 @@
<pre><samp> <pre><samp>
package samples.ui.actions; package samples.ui.actions;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.files.ui.actions.SystemAbstractRemoteFilePopupMenuExtensionAction; import org.eclipse.rse.files.ui.actions.SystemAbstractRemoteFilePopupMenuExtensionAction;
<b>import com.ibm.etools.systems.subsystems.*;</b> import org.eclipse.rse.shells.ui.RemoteCommandHelpers;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.subsystems.shells.core.subsystems.IRemoteCmdSubSystem;
/** public class ShowJarContents2 extends SystemAbstractRemoteFilePopupMenuExtensionAction {
* <i>An action that runs a command to display the contents of a Jar file.</i>
* <i>The plugin.xml file restricts this action so it only appears for .jar files.</i>
*/
public class ShowJarContents
extends SystemAbstractRemoteFilePopupMenuExtensionAction
{
/** public ShowJarContents2() {
* Constructor for ShowJarContents.
*/
public ShowJarContents()
{
super(); super();
} }
public void run() {
IRemoteFile selectedFile = getFirstSelectedRemoteFile();
String cmdToRun = "jar -tvf " + selectedFile.getAbsolutePath();
runCommand(cmdToRun);
}
private void runCommand(String command) {
IRemoteCmdSubSystem cmdss = getRemoteCmdSubSystem();
if (cmdss != null && cmdss.isConnected()) {
RemoteCommandHelpers.runUniversalCommand(getShell(), command, ".", cmdss);
} else {
MessageDialog.openError(getShell(), "No command subsystem", "Found no command subsystem");
}
}
/** /**
* @see org.eclipse.rse.ui.actions.SystemAbstractPopupMenuExtensionAction#run() * Gets the Command subsystem associated with the current host
*/ */
public void run() private IRemoteCmdSubSystem getRemoteCmdSubSystem() {
{ IHost myHost = getSubSystem().getHost();
<b>IRemoteFile selectedFile = getFirstSelectedRemoteFile();</b> IRemoteCmdSubSystem[] subsys = RemoteCommandHelpers.getCmdSubSystems(myHost);
<b>String cmdToRun = &quot;jar -tvf &quot; + selectedFile.getAbsolutePath();</b> for (int i = 0; i < subsys.length; i++) {
<b>runCommand(cmdToRun);</b> if (subsys[i].getSubSystemConfiguration().supportsCommands()) {
return subsys[i];
}
}
return null;
} }
} }
</samp></pre> </samp></pre>
</p> </p>
</body> </body>

View file

@ -68,13 +68,38 @@ Press <b>Finish</b> to create the <samp><a href="ShowJarContents1.html">ShowJarC
</li> </li>
<li>Edit the generated <samp>ShowJarContents.java</samp> file as follows: <li>Edit the generated <samp>ShowJarContents.java</samp> file as follows:
<ol> <ol>
<li type="i">Add import statement for <samp><b>import com.ibm.etools.systems.subsystems.*;</b></samp></li>
<li type="i">Add the following three statements to the body of the <samp>run()</samp> method:</li> <li type="i">Add the following three statements to the body of the <samp>run()</samp> method:</li>
<pre><code> <pre><code>
IRemoteFile selectedFile = getFirstSelectedRemoteFile(); IRemoteFile selectedFile = getFirstSelectedRemoteFile();
String cmdToRun = "jar -tvf " + selectedFile.getAbsolutePath(); String cmdToRun = "jar -tvf " + selectedFile.getAbsolutePath();
runCommand(cmdToRun); runCommand(cmdToRun);
</code></pre> </code></pre>
<li type="i">Add the following two methods to find the subsystem and run the command:</li>
<pre><code>
private void runCommand(String command) {
IRemoteCmdSubSystem cmdss = getRemoteCmdSubSystem();
if (cmdss != null && cmdss.isConnected()) {
RemoteCommandHelpers.runUniversalCommand(getShell(), command, ".", cmdss);
} else {
MessageDialog.openError(getShell(), "No command subsystem", "Found no command subsystem");
}
}
/**
* Gets the Command subsystem associated with the current host
*/
private IRemoteCmdSubSystem getRemoteCmdSubSystem() {
IHost myHost = getSubSystem().getHost();
IRemoteCmdSubSystem[] subsys = RemoteCommandHelpers.getCmdSubSystems(myHost);
for (int i = 0; i < subsys.length; i++) {
if (subsys[i].getSubSystemConfiguration().supportsCommands()) {
return subsys[i];
}
}
return null;
}
</code></pre>
<li type="i">User the "Source -> Organize Imports" context menu item to add the appropriate import statements.</li>
</ol> </ol>
The final result after editing is shown <a href="ShowJarContents2.html">here</a>. The final result after editing is shown <a href="ShowJarContents2.html">here</a>.
</li> </li>