This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
DriftAddDefinitionWizard.java
194 lines (157 loc) · 7.1 KB
/
DriftAddDefinitionWizard.java
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* RHQ Management Platform
* Copyright (C) 2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.rhq.coregui.client.drift.wizard;
import java.util.ArrayList;
import java.util.EnumSet;
import com.google.gwt.user.client.rpc.AsyncCallback;
import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.criteria.ResourceCriteria;
import org.rhq.core.domain.drift.DriftDefinitionTemplate;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.domain.util.PageList;
import org.rhq.core.domain.util.ResourceTypeUtility;
import org.rhq.coregui.client.CoreGUI;
import org.rhq.coregui.client.components.table.Table;
import org.rhq.coregui.client.components.wizard.WizardStep;
import org.rhq.coregui.client.gwt.GWTServiceLookup;
import org.rhq.coregui.client.inventory.resource.type.ResourceTypeRepository;
import org.rhq.coregui.client.util.message.Message;
/**
* @author Jay Shaughnessy
*/
public class DriftAddDefinitionWizard extends AbstractDriftAddDefinitionWizard {
private Table<?> table;
protected DriftAddDefinitionWizard(EntityContext context, ResourceType type, Table<?> table) {
super(context, type);
this.table = table;
final ArrayList<WizardStep> steps = new ArrayList<WizardStep>();
steps.add(new DriftAddDefinitionWizardInfoStep(DriftAddDefinitionWizard.this));
steps.add(new DriftAddDefinitionWizardConfigStep(DriftAddDefinitionWizard.this));
setSteps(steps);
}
@Override
public String getWindowTitle() {
switch (getEntityContext().getType()) {
case SubsystemView:
return MSG.view_drift_wizard_addTemplate_windowTitle();
default:
return MSG.view_drift_wizard_addDef_windowTitle();
}
}
@Override
public String getTitle() {
switch (getEntityContext().getType()) {
case SubsystemView:
return MSG.view_drift_wizard_addTemplate_title(ResourceTypeUtility.displayName(getType()));
default:
return MSG.view_drift_wizard_addDef_title(ResourceTypeUtility.displayName(getType()));
}
}
@Override
public String getSubtitle() {
return null;
}
@Override
public void execute() {
EntityContext context = getEntityContext();
switch (context.getType()) {
case Resource:
ResourceCriteria rc = new ResourceCriteria();
rc.addFilterId(context.getResourceId());
rc.fetchResourceType(true);
GWTServiceLookup.getDriftService().updateDriftDefinition(context, getNewDriftDefinition(),
new AsyncCallback<Void>() {
public void onSuccess(Void result) {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_drift_wizard_addDef_success(getNewDriftDefinition().getName()),
Message.Severity.Info));
getView().closeDialog();
DriftAddDefinitionWizard.this.table.refresh();
}
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(
MSG.view_drift_wizard_addDef_failure(getNewDriftDefinition().getName()), caught);
getView().closeDialog();
}
});
break;
case ResourceTemplate:
GWTServiceLookup.getDriftService().createTemplate(getType().getId(), getNewDriftDefinition(),
new AsyncCallback<DriftDefinitionTemplate>() {
public void onSuccess(DriftDefinitionTemplate result) {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_drift_wizard_addTemplate_success(getNewDriftDefinition().getName()),
Message.Severity.Info));
getView().closeDialog();
DriftAddDefinitionWizard.this.table.refresh();
}
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(
MSG.view_drift_wizard_addTemplate_failure(getNewDriftDefinition().getName()), caught);
getView().closeDialog();
}
});
break;
default:
throw new IllegalArgumentException("Entity Context Type not supported [" + context + "]");
}
}
public static void showWizard(final EntityContext context, final Table<?> table) {
assert context != null;
switch (context.getType()) {
case Resource:
ResourceCriteria rc = new ResourceCriteria();
rc.addFilterId(context.getResourceId());
rc.fetchResourceType(true);
GWTServiceLookup.getResourceService().findResourcesByCriteria(rc, new AsyncCallback<PageList<Resource>>() {
public void onSuccess(PageList<Resource> result) {
if (result.isEmpty()) {
throw new IllegalArgumentException("Entity not found [" + context + "]");
}
Resource resource = result.get(0);
showWizard(context, resource.getResourceType().getId(), table);
}
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(MSG.view_inventory_resources_loadFailed(), caught);
}
});
break;
case ResourceTemplate:
showWizard(context, context.getResourceTypeId(), table);
break;
default:
throw new IllegalArgumentException("Entity Context Type not supported [" + context + "]");
}
}
private static void showWizard(final EntityContext context, int resourceTypeId, final Table<?> table) {
ResourceTypeRepository.Cache.getInstance().getResourceTypes(resourceTypeId,
EnumSet.of(ResourceTypeRepository.MetadataType.driftDefinitionTemplates),
new ResourceTypeRepository.TypeLoadedCallback() {
public void onTypesLoaded(ResourceType type) {
DriftAddDefinitionWizard wizard = new DriftAddDefinitionWizard(context, type, table);
wizard.startWizard();
}
});
}
@Override
public void cancel() {
super.cancel();
}
}