15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 package com.nokia.s60tools.hticonnection.preferences; |
18 package com.nokia.s60tools.hticonnection.preferences; |
19 |
19 |
|
20 import org.eclipse.core.runtime.CoreException; |
20 import org.eclipse.jface.preference.PreferencePage; |
21 import org.eclipse.jface.preference.PreferencePage; |
21 import org.eclipse.swt.SWT; |
22 import org.eclipse.swt.SWT; |
22 import org.eclipse.swt.layout.GridData; |
23 import org.eclipse.swt.layout.GridData; |
23 import org.eclipse.swt.layout.GridLayout; |
24 import org.eclipse.swt.layout.GridLayout; |
24 import org.eclipse.swt.widgets.Composite; |
25 import org.eclipse.swt.widgets.Composite; |
26 import org.eclipse.ui.IWorkbench; |
27 import org.eclipse.ui.IWorkbench; |
27 import org.eclipse.ui.IWorkbenchPreferencePage; |
28 import org.eclipse.ui.IWorkbenchPreferencePage; |
28 import org.eclipse.ui.PlatformUI; |
29 import org.eclipse.ui.PlatformUI; |
29 |
30 |
30 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
31 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
31 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI; |
32 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2; |
32 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
33 import com.nokia.carbide.remoteconnections.interfaces.IService; |
33 import com.nokia.carbide.remoteconnections.interfaces.IService; |
34 import com.nokia.s60tools.hticonnection.HtiApiActivator; |
34 import com.nokia.s60tools.hticonnection.HtiApiActivator; |
35 import com.nokia.s60tools.hticonnection.HtiConnectionHelpContextIDs; |
35 import com.nokia.s60tools.hticonnection.HtiConnectionHelpContextIDs; |
36 import com.nokia.s60tools.hticonnection.common.ProductInfoRegistry; |
36 import com.nokia.s60tools.hticonnection.common.ProductInfoRegistry; |
37 import com.nokia.s60tools.hticonnection.connection.HTIService; |
37 import com.nokia.s60tools.hticonnection.connection.HTIService; |
38 import com.nokia.s60tools.hticonnection.core.HtiConnection; |
38 import com.nokia.s60tools.hticonnection.core.HtiConnection; |
39 import com.nokia.s60tools.hticonnection.core.HtiConnection.ConnectionStatus; |
|
40 import com.nokia.s60tools.hticonnection.resources.Messages; |
39 import com.nokia.s60tools.hticonnection.resources.Messages; |
41 |
40 |
42 /** |
41 /** |
43 * Reference page for HTI API |
42 * Reference page for HTI API |
44 */ |
43 */ |
50 private Composite container; |
49 private Composite container; |
51 |
50 |
52 /** |
51 /** |
53 * UI component for configuring connection. |
52 * UI component for configuring connection. |
54 */ |
53 */ |
55 private IClientServiceSiteUI clientSiteUI; |
54 private IClientServiceSiteUI2 clientSiteUI; |
56 |
55 |
57 /** |
56 /** |
58 * Keeps information about if preferences page is created and open currently. |
57 * Keeps information about if preferences page is created and open currently. |
59 */ |
58 */ |
60 private static boolean isCreated = false; |
59 private static boolean isCreated = false; |
84 container.setLayout(new GridLayout(1, false)); |
83 container.setLayout(new GridLayout(1, false)); |
85 container.setLayoutData(new GridData(GridData.FILL_BOTH)); |
84 container.setLayoutData(new GridData(GridData.FILL_BOTH)); |
86 |
85 |
87 // Client Site UI for creating and selecting connection. |
86 // Client Site UI for creating and selecting connection. |
88 IService service = RemoteConnectionsActivator.getConnectionTypeProvider().findServiceByID(HTIService.ID); |
87 IService service = RemoteConnectionsActivator.getConnectionTypeProvider().findServiceByID(HTIService.ID); |
89 clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI(service); |
88 clientSiteUI = RemoteConnectionsActivator.getConnectionsManager().getClientSiteUI2(service); |
90 clientSiteUI.createComposite(container); |
89 clientSiteUI.createComposite(container); |
91 |
90 |
92 // Current connection needs to be selected or first in the list is selected. |
91 // Current connection needs to be selected or first in the list is selected. |
93 IConnection currentConnection = HtiApiActivator.getPreferences().getCurrentConnection(); |
92 String currentConnection = HtiApiActivator.getPreferences().getConnectionID(); |
94 if(currentConnection != null) { |
93 if(currentConnection != null) { |
95 clientSiteUI.selectConnection(currentConnection); |
94 clientSiteUI.selectConnection(currentConnection); |
96 } |
95 } |
97 |
96 |
98 setHelps(parent); |
97 setHelps(parent); |
99 |
98 |
100 return container; |
99 return container; |
101 } |
100 } |
102 |
101 |
122 doApply(); |
121 doApply(); |
123 } |
122 } |
124 |
123 |
125 /** |
124 /** |
126 * Apply settings |
125 * Apply settings |
|
126 * @throws CoreException |
127 */ |
127 */ |
128 private void doApply(){ |
128 private void doApply() { |
129 savePrefStoreValues(); |
129 savePrefStoreValues(); |
130 |
130 try { |
131 // Getting needed variables. |
131 HtiConnection.getInstance().changeConnection(clientSiteUI.getSelectedConnection()); |
132 HtiConnection htiConnection = HtiConnection.getInstance(); |
132 } catch (CoreException e) { |
133 IConnection currentConnection = clientSiteUI.getSelectedConnection(); |
133 e.printStackTrace(); |
134 |
|
135 // Restart datagateway if connection has been changed |
|
136 |
|
137 boolean isConnected = htiConnection.getConnectionStatus() != ConnectionStatus.SHUTDOWN; |
|
138 boolean isNewConnection = (currentConnection != null) && !(currentConnection.equals(htiConnection.getCurrentConnection())); |
|
139 |
|
140 if (isConnected && isNewConnection) { |
|
141 // Connection has been changed when connection is started. |
|
142 restartDataGateway(currentConnection, false); |
|
143 } |
|
144 else if(!isConnected || currentConnection == null) { |
|
145 // Connection isn't active or connections have been deleted. New connection can be set. |
|
146 HtiConnection.getInstance().setCurrentConnection(currentConnection, false); |
|
147 } |
134 } |
148 } |
135 } |
149 |
136 |
150 /* (non-Javadoc) |
137 /* (non-Javadoc) |
151 * @see org.eclipse.jface.preference.PreferencePage#performDefaults() |
138 * @see org.eclipse.jface.preference.PreferencePage#performDefaults() |
164 /** |
151 /** |
165 * Saves values to prefstore |
152 * Saves values to prefstore |
166 * @return True if saved successfully, else false |
153 * @return True if saved successfully, else false |
167 */ |
154 */ |
168 private void savePrefStoreValues() { |
155 private void savePrefStoreValues() { |
169 IConnection currentConnection = clientSiteUI.getSelectedConnection(); |
156 String currentConnection = clientSiteUI.getSelectedConnection(); |
170 String connectionID = (currentConnection == null) ? HtiApiPreferenceConstants.DEFAULT_CONNECTION_ID |
157 String connectionID = (currentConnection == null) ? HtiApiPreferenceConstants.DEFAULT_CONNECTION_ID |
171 : currentConnection.getIdentifier(); |
158 : currentConnection; |
172 if (!connectionID.equals(HtiApiActivator.getPreferences().getConnectionID())) { |
159 if (!connectionID.equals(HtiApiActivator.getPreferences().getConnectionID())) { |
173 HtiApiActivator.getPreferences().setConnectionID(connectionID); |
160 HtiApiActivator.getPreferences().setConnectionID(connectionID); |
174 } |
161 } |
175 } |
|
176 |
|
177 /** |
|
178 * Restarts Datagateway with settings from preference store. |
|
179 * @param isTesting True if testing connection and not trying to establish permanent connection. |
|
180 */ |
|
181 private boolean restartDataGateway(IConnection conn, boolean isTesting) { |
|
182 HtiConnection htiConn = HtiConnection.getInstance(); |
|
183 htiConn.stopConnection(); |
|
184 htiConn.setCurrentConnection(conn, false); |
|
185 return htiConn.startConnection(isTesting); |
|
186 } |
162 } |
187 |
163 |
188 /** |
164 /** |
189 * Returns true if preferences page is created and open. |
165 * Returns true if preferences page is created and open. |
190 * @return True if page is created. |
166 * @return True if page is created. |