-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAbstractAddNewAttributeDialog.java
More file actions
114 lines (97 loc) · 4.17 KB
/
AbstractAddNewAttributeDialog.java
File metadata and controls
114 lines (97 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Copyright 2013 Amazon Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://aws.amazon.com/apache2.0
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and
* limitations under the License.
*/
package com.amazonaws.eclipse.dynamodb;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
public abstract class AbstractAddNewAttributeDialog extends MessageDialog {
String newAttributeName = "";
public String getNewAttributeName() {
return newAttributeName.trim();
}
protected AbstractAddNewAttributeDialog() {
super(Display.getCurrent().getActiveShell(), "Enter New Attribute Name", null, "Enter a new attribute name", MessageDialog.NONE, new String[] { "OK", "Cancel" }, 0);
}
@Override
protected Control createCustomArea(Composite parent) {
final Text text = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(text);
text.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
newAttributeName = text.getText();
validate();
}
});
return parent;
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
super.createButtonsForButtonBar(parent);
validate();
}
private final class LoadEnvironmentsThread extends CancelableThread {
@Override
public void run() {
final List<EnvironmentDescription> environments = new ArrayList<>();
try {
environments.addAll(elasticBeanstalkClient.describeEnvironments().getEnvironments());
} catch (Exception e) {
if (isServiceSignUpException(e)) {
StatusManager.getManager().handle(newServiceSignUpErrorStatus(e), StatusManager.SHOW | StatusManager.LOG);
} else {
Status status = new Status(Status.ERROR, ElasticBeanstalkPlugin.PLUGIN_ID,
"Unable to load existing environments: " + e.getMessage(), e);
StatusManager.getManager().handle(status, StatusManager.LOG);
}
setRunning(false);
return;
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
List<String> environmentNames = new ArrayList<>();
for ( EnvironmentDescription environment : environments ) {
// Skip any terminated environments, since we can safely reuse their names
if ( isEnvironmentTerminated(environment) ) {
continue;
}
environmentNames.add(environment.getEnvironmentName());
}
Collections.sort(environmentNames);
synchronized (LoadEnvironmentsThread.this) {
if ( !isCanceled() ) {
existingEnvironmentNames.clear();
existingEnvironmentNames.addAll(environmentNames);
environmentNamesLoaded.setValue(true);
runValidators();
}
}
} finally {
setRunning(false);
}
}
});
}
}
abstract public void validate();
}