Skip to content

Commit de396bd

Browse files
committed
modify UI when link a cluster in Eclipse
1 parent 8c3ba44 commit de396bd

File tree

1 file changed

+88
-4
lines changed
  • PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.azureexplorer/src/com/microsoft/azuretools/azureexplorer/forms

1 file changed

+88
-4
lines changed

PluginsAndFeatures/azure-toolkit-for-eclipse/com.microsoft.azuretools.azureexplorer/src/com/microsoft/azuretools/azureexplorer/forms/AddNewClusterForm.java

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
package com.microsoft.azuretools.azureexplorer.forms;
22

3-
import org.eclipse.jface.dialogs.TitleAreaDialog;
3+
import org.eclipse.jface.resource.JFaceResources;
44
import org.eclipse.swt.SWT;
5+
import org.eclipse.swt.graphics.Cursor;
6+
import org.eclipse.swt.graphics.Image;
57
import org.eclipse.swt.layout.GridData;
68
import org.eclipse.swt.layout.GridLayout;
79
import org.eclipse.swt.widgets.Composite;
810
import org.eclipse.swt.widgets.Control;
911
import org.eclipse.swt.widgets.Display;
1012
import org.eclipse.swt.widgets.Label;
13+
import org.eclipse.swt.widgets.Link;
1114
import org.eclipse.swt.widgets.Shell;
1215
import org.eclipse.swt.widgets.Text;
16+
import org.eclipse.swt.widgets.ToolBar;
17+
import org.eclipse.swt.widgets.ToolItem;
18+
import org.eclipse.ui.PartInitException;
19+
import org.eclipse.ui.PlatformUI;
20+
21+
import static org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter;
22+
23+
import java.net.MalformedURLException;
24+
import java.net.URL;
25+
26+
import org.eclipse.jface.dialogs.IDialogConstants;
1327

1428
import com.microsoft.azure.hdinsight.common.ClusterManagerEx;
1529
import com.microsoft.azure.hdinsight.sdk.cluster.HDInsightAdditionalClusterDetail;
@@ -58,12 +72,76 @@ protected void configureShell(Shell newShell) {
5872
newShell.setText("Link New HDInsight Cluster");
5973
}
6074

75+
// we cannot just override method 'helpPressed' since the method is defined as private in the parent class 'TrayDialog'
76+
// so we disable the default help button and mock a button with different usage
77+
protected void helpPressed() {
78+
try {
79+
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL("https://go.microsoft.com/fwlink/?linkid=866472"));
80+
} catch (PartInitException | MalformedURLException e) {
81+
// TODO Auto-generated catch block
82+
e.printStackTrace();
83+
}
84+
}
85+
86+
private ToolBar createHelpImageButton(Composite parent, Image image) {
87+
ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
88+
((GridLayout) parent.getLayout()).numColumns++;
89+
toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
90+
final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
91+
toolBar.setCursor(cursor);
92+
toolBar.addDisposeListener(e -> cursor.dispose());
93+
ToolItem fHelpButton = new ToolItem(toolBar, SWT.CHECK);
94+
fHelpButton.setImage(image);
95+
fHelpButton.setToolTipText(JFaceResources.getString("helpToolTip")); //$NON-NLS-1$
96+
fHelpButton.addSelectionListener(widgetSelectedAdapter(e -> helpPressed()));
97+
return toolBar;
98+
}
99+
100+
private Link createHelpLink(Composite parent) {
101+
Link link = new Link(parent, SWT.WRAP | SWT.NO_FOCUS);
102+
((GridLayout) parent.getLayout()).numColumns++;
103+
link.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
104+
link.setText("<a>"+IDialogConstants.HELP_LABEL+"</a>"); //$NON-NLS-1$ //$NON-NLS-2$
105+
link.setToolTipText(IDialogConstants.HELP_LABEL);
106+
link.addSelectionListener(widgetSelectedAdapter(e -> helpPressed()));
107+
return link;
108+
}
109+
110+
@Override
111+
protected Control createHelpControl(Composite parent) {
112+
Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
113+
if (helpImage != null) {
114+
return createHelpImageButton(parent, helpImage);
115+
}
116+
return createHelpLink(parent);
117+
}
118+
119+
@Override
120+
protected Control createButtonBar(Composite parent) {
121+
Composite composite = new Composite(parent, SWT.NONE);
122+
GridLayout layout = new GridLayout();
123+
layout.marginWidth = 0;
124+
layout.marginHeight = 0;
125+
layout.horizontalSpacing = 0;
126+
composite.setLayout(layout);
127+
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
128+
composite.setFont(parent.getFont());
129+
130+
// mock a new help button
131+
Control helpControl = createHelpControl(composite);
132+
((GridData) helpControl.getLayoutData()).horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
133+
Control buttonSection = super.createButtonBar(composite);
134+
((GridData) buttonSection.getLayoutData()).grabExcessHorizontalSpace = true;
135+
return composite;
136+
}
137+
61138
@Override
62139
protected Control createDialogArea(Composite parent) {
63140
setTitle("Link New HDInsight Cluster");
64141
setMessage("Please enter HDInsight Cluster details");
142+
// disable the default help button
65143
setHelpAvailable(false);
66-
144+
67145
Composite container = new Composite(parent, SWT.NONE);
68146
GridLayout gridLayout = new GridLayout();
69147
gridLayout.numColumns = 2;
@@ -84,6 +162,7 @@ protected Control createDialogArea(Composite parent) {
84162
gridData.horizontalAlignment = SWT.FILL;
85163
gridData.grabExcessHorizontalSpace = true;
86164
clusterNameField.setLayoutData(gridData);
165+
clusterNameField.setToolTipText("The HDInsight cluster name, such as 'mycluster' of cluster URL 'mycluster.azurehdinsight.net'.\n\n Click the '?'(Help) button to get more details.");
87166

88167
Label storageNameLabel = new Label(container, SWT.LEFT);
89168
storageNameLabel.setText("Storage Name:");
@@ -95,6 +174,7 @@ protected Control createDialogArea(Composite parent) {
95174
gridData.horizontalAlignment = SWT.FILL;
96175
gridData.grabExcessHorizontalSpace = true;
97176
storageNameField.setLayoutData(gridData);
177+
storageNameField.setToolTipText("The default storage account of the HDInsight cluster, which can be found from HDInsight cluster properties of Azure portal.\n\n Click the '?'(Help) button to get more details");
98178

99179
Label storageKeyLabel = new Label(container, SWT.LEFT);
100180
storageKeyLabel.setText("Storage Key:");
@@ -106,6 +186,7 @@ protected Control createDialogArea(Composite parent) {
106186
gridData.horizontalAlignment = SWT.FILL;
107187
gridData.grabExcessHorizontalSpace = true;
108188
storageKeyField.setLayoutData(gridData);
189+
storageKeyField.setToolTipText("The storage key of the default storage account, which can be found from HDInsight cluster storage accounts of Azure portal.\n\n Click the '?'(Help) button to get more details.");
109190

110191
Label userNameLabel = new Label(container, SWT.LEFT);
111192
userNameLabel.setText("User Name:");
@@ -117,7 +198,8 @@ protected Control createDialogArea(Composite parent) {
117198
gridData.horizontalAlignment = SWT.FILL;
118199
gridData.grabExcessHorizontalSpace = true;
119200
userNameField.setLayoutData(gridData);
120-
201+
userNameField.setToolTipText("The user name of the HDInsight cluster.\n\n Click the '?'(Help) button to get more details.");
202+
121203
Label passwordLabel = new Label(container, SWT.LEFT);
122204
passwordLabel.setText("Password:");
123205
gridData = new GridData();
@@ -128,7 +210,8 @@ protected Control createDialogArea(Composite parent) {
128210
gridData.horizontalAlignment = SWT.FILL;
129211
gridData.grabExcessHorizontalSpace = true;
130212
passwordField.setLayoutData(gridData);
131-
213+
passwordField.setToolTipText("The password of the HDInsight cluster user provided.\n\n Click the '?'(Help) button to get more details.");
214+
132215
return super.createDialogArea(parent);
133216
}
134217

@@ -214,4 +297,5 @@ public void run() {
214297
});
215298
PluginUtil.showBusy(false, getShell());
216299
}
300+
217301
}

0 commit comments

Comments
 (0)