Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import javax.swing.AbstractAction;
import javax.swing.Action;
Expand Down Expand Up @@ -183,6 +184,38 @@ public void removeConnectionListener(ConnectionListener listener) {
// No need to lock - use thread-safe collection
connectionListeners.remove(listener);
}

/**
* Remove a connection from list of recent connections. Any stored settings will be removed
* @param execEnv environment
*/
public void deleteConnectionFromRecentConnections(ExecutionEnvironment execEnv) {
synchronized (recentConnections) {
recentConnections.remove(execEnv);
forget(execEnv);
storeRecentConnectionsList(true);
}
}


/**
* Add a connection to a recent connection list.
* @param execEnv environment
* @return true if a connection was added to a list
*/
public boolean addConnectionToRecentConnections(ExecutionEnvironment execEnv) {
if (execEnv.isLocal()) {
return false;
}
synchronized (recentConnections) {
if (recentConnections.contains(execEnv)) {
return false;
}
recentConnections.add(0, execEnv);
storeRecentConnectionsList(false);
return true;
}
}

public List<ExecutionEnvironment> getRecentConnections() {
synchronized (recentConnections) {
Expand All @@ -194,13 +227,24 @@ public List<ExecutionEnvironment> getRecentConnections() {
synchronized (recentConnections) {
recentConnections.remove(execEnv);
recentConnections.add(0, execEnv);
storeRecentConnectionsList();
storeRecentConnectionsList(false);
}
}

/*package-local for test purposes*/ void storeRecentConnectionsList() {
/**
* Store recent connection list.
* @param clear true if settings is cleared before stored
*/
/*package-local for test purposes*/ void storeRecentConnectionsList(boolean clear) {
Preferences prefs = NbPreferences.forModule(ConnectionManager.class);
synchronized (recentConnections) {
if (clear) {
try {
prefs.clear();
} catch (BackingStoreException ex) {
log.log(Level.WARNING,"Cannot clear ConnectionManager preferences", ex);
}
}
for (int i = 0; i < recentConnections.size(); i++) {
prefs.put(getConnectoinsHistoryKey(i), ExecutionEnvironmentFactory.toUniqueID(recentConnections.get(i)));
}
Expand Down Expand Up @@ -302,6 +346,7 @@ public boolean isConnectedTo(final ExecutionEnvironment execEnv) {
if (checkHostInfo) {
return HostInfoUtils.isHostInfoAvailable(execEnv);
} else {
updateRecentConnectionsList(execEnv);
return true;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import junit.framework.Test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.netbeans.junit.RandomlyFails;
import org.netbeans.modules.nativeexecution.ConcurrentTasksSupport;
import org.netbeans.modules.nativeexecution.ConcurrentTasksSupport.Counters;
import org.netbeans.modules.nativeexecution.test.NativeExecutionBaseTestCase;
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
import org.netbeans.modules.nativeexecution.test.ForAllEnvironments;
import org.netbeans.modules.nativeexecution.test.NativeExecutionBaseTestSuite;
import org.netbeans.modules.nativeexecution.test.NativeExecutionTestSupport;
Expand All @@ -50,26 +49,22 @@ public ConnectionManagerTest(String name, ExecutionEnvironment testExecutionEnvi
super(name, testExecutionEnvironment);
}

@BeforeClass
public static void setUpClass() throws Exception {
}

@AfterClass
public static void tearDownClass() throws Exception {
}

@Override
public void setUp() throws Exception {
}

@Override
public void tearDown() throws Exception {
}

public static Test suite() {
public static junit.framework.Test suite() {
return new NativeExecutionBaseTestSuite(ConnectionManagerTest.class);
}

@Test
public void testDeleteConnection() throws Exception {
ExecutionEnvironment env = ExecutionEnvironmentFactory.createNew("test","127.0.0.1");
ConnectionManager.getInstance().updateRecentConnectionsList(env);
List<ExecutionEnvironment> ret = ConnectionManager.getInstance().getRecentConnections();
assertTrue(!ret.isEmpty());
ConnectionManager.getInstance().deleteConnectionFromRecentConnections(env);
List<ExecutionEnvironment> ret2 = ConnectionManager.getInstance().getRecentConnections();
assertTrue(ret2.isEmpty());
}

@Test
public void testGetRecentConnections() throws Exception {
String section = "remote.platforms";
ExecutionEnvironment[] envs = NativeExecutionTestSupport.getTestExecutionEnvironmentsFromSection(section);
Expand All @@ -90,6 +85,7 @@ public void testGetRecentConnections() throws Exception {

@RandomlyFails
@ForAllEnvironments(section = "remote.platforms")
@Test
public void testConnectDisconnect() throws Exception {
final ExecutionEnvironment execEnv = getTestExecutionEnvironment();
assert (execEnv != null);
Expand Down Expand Up @@ -122,6 +118,7 @@ public void testConnectDisconnect() throws Exception {
System.out.println(getName() + " finished");
}

@Test
public void testGetConnectToAction() throws Exception {
final int threadsNum = 10;
RcFile rcFile = NativeExecutionTestSupport.getRcFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ private void doWork() {
// (exception supressed in FetchHostInfoTask.compute)
if (!ConnectionManager.getInstance().isConnectedTo(env)) {
return;
} else {
// because we can reuse an existing connection we need to try update a recent connection list
ConnectionManager.getInstance().addConnectionToRecentConnections(env);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ RemoteInfoDialog.hostField.AccessibleContext.accessibleName=Remote Host Name
NewHostInfoTitle=Connection Information:
RemoteInfoDialog.btnKnownHosts.text=&Known Hosts
RemoteInfoDialog.btnNewHost.text=&Other Host
RemoteInfoDialog.btnDeleteHost.text=Delete
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8" ?>

<!--

Expand Down Expand Up @@ -44,13 +44,19 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="pnlConnectionInfo" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="btnKnownHosts" min="-2" max="-2" attributes="0"/>
<Component id="pnlConnectionInfo" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="btnKnownHosts" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbKnownHosts" pref="254" max="32767" attributes="0"/>
</Group>
<Component id="btnNewHost" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbKnownHosts" pref="224" max="32767" attributes="0"/>
<Component id="btnDeleteHost" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="btnNewHost" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
Expand All @@ -63,6 +69,7 @@
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cbKnownHosts" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnKnownHosts" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnDeleteHost" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnNewHost" min="-2" max="-2" attributes="0"/>
Expand Down Expand Up @@ -128,7 +135,7 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="324" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
Expand All @@ -139,7 +146,7 @@
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="userField" alignment="0" pref="226" max="32767" attributes="2"/>
<Component id="userField" alignment="0" pref="364" max="32767" attributes="2"/>
<Component id="hostField" alignment="0" pref="226" max="32767" attributes="2"/>
<Component id="portField" alignment="0" min="-2" max="-2" attributes="1"/>
</Group>
Expand Down Expand Up @@ -271,5 +278,15 @@
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="btnDeleteHost">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/netbeans/modules/dlight/terminal/ui/Bundle.properties" key="RemoteInfoDialog.btnDeleteHost.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnDeleteHostActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private void initComponents() {
hostField = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
portField = new javax.swing.JTextField();
btnDeleteHost = new javax.swing.JButton();

buttonGroup1.add(btnKnownHosts);
btnKnownHosts.setSelected(true);
Expand Down Expand Up @@ -115,7 +116,7 @@ public void itemStateChanged(java.awt.event.ItemEvent evt) {
pnlConnectionInfo.setLayout(pnlConnectionInfoLayout);
pnlConnectionInfoLayout.setHorizontalGroup(
pnlConnectionInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 324, Short.MAX_VALUE)
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(pnlConnectionInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlConnectionInfoLayout.createSequentialGroup()
.addContainerGap()
Expand All @@ -125,7 +126,7 @@ public void itemStateChanged(java.awt.event.ItemEvent evt) {
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlConnectionInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(userField, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
.addComponent(userField, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
.addComponent(hostField, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE)
.addComponent(portField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap()))
Expand Down Expand Up @@ -154,6 +155,13 @@ public void itemStateChanged(java.awt.event.ItemEvent evt) {
hostField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(RemoteInfoDialog.class, "RemoteInfoDialog.hostField.AccessibleContext.accessibleName")); // NOI18N
portField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(RemoteInfoDialog.class, "RemoteInfoDialog.portField.AccessibleContext.accessibleName")); // NOI18N

btnDeleteHost.setText(org.openide.util.NbBundle.getMessage(RemoteInfoDialog.class, "RemoteInfoDialog.btnDeleteHost.text")); // NOI18N
btnDeleteHost.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDeleteHostActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
Expand All @@ -163,10 +171,14 @@ public void itemStateChanged(java.awt.event.ItemEvent evt) {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlConnectionInfo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(btnKnownHosts)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnKnownHosts)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbKnownHosts, 0, 254, Short.MAX_VALUE))
.addComponent(btnNewHost))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbKnownHosts, 0, 224, Short.MAX_VALUE))
.addComponent(btnNewHost))
.addComponent(btnDeleteHost)))
.addContainerGap())
);
layout.setVerticalGroup(
Expand All @@ -175,7 +187,8 @@ public void itemStateChanged(java.awt.event.ItemEvent evt) {
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbKnownHosts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnKnownHosts))
.addComponent(btnKnownHosts)
.addComponent(btnDeleteHost))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnNewHost)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
Expand All @@ -196,7 +209,29 @@ private void btnNewHostItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIR
}
}//GEN-LAST:event_btnNewHostItemStateChanged

private void btnDeleteHostActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteHostActionPerformed
ExecutionEnvironment selected = (ExecutionEnvironment) cbKnownHosts.getSelectedItem();
if (selected != null) {
ConnectionManager.getInstance().deleteConnectionFromRecentConnections(selected);
cbKnownHosts.removeItem(selected);
if (cbKnownHosts.getItemCount() == 0) {
btnKnownHosts.setEnabled(false);
btnNewHost.setSelected(true);
}
Preferences prefs = NbPreferences.forModule(RemoteInfoDialog.class);
String eeID = prefs.get(LAST_SELECTED_HOST, "");
if (!eeID.isEmpty()) {
ExecutionEnvironment ee = ExecutionEnvironmentFactory.fromUniqueID(eeID);
if (ee.equals(selected)) {
prefs.remove(LAST_SELECTED_HOST);
last = null;
}
}
}
}//GEN-LAST:event_btnDeleteHostActionPerformed

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnDeleteHost;
private javax.swing.JRadioButton btnKnownHosts;
private javax.swing.JRadioButton btnNewHost;
private javax.swing.ButtonGroup buttonGroup1;
Expand Down Expand Up @@ -255,6 +290,7 @@ private void fillHosts() {

private void selectMode(boolean knownHosts) {
cbKnownHosts.setEnabled(knownHosts);
btnDeleteHost.setEnabled(knownHosts);
Component[] components = pnlConnectionInfo.getComponents();
for (Component component : components) {
component.setEnabled(!knownHosts);
Expand Down
Loading