groupsres.addContainerProperty("Group ID", String.class, null);
groupsres.addContainerProperty("Group Name", String.class, null);
// list.setVisibleColumns(new Object[] { "Type Name" });
for (int i = 0; i < groupArray.size(); i++) {
Group group = groupArray.get(i);
groupsres.addItem(
new Object[] { Integer.toString(group.getGroupID()),
group.getGroupName() }, i);
groupnumberres++;
}
} catch (DAOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
groupsres.setVisibleColumns(new Object[] {"Group Name"});
// Options
resName.setMaxLength(45);
resDescription.setMaxLength(250);
resDescription.setRows(6);
resDescription.setColumns(25);
checb.setValue(true);
groupsres.setSelectable(true);
groupsres.setMultiSelect(true);
groupsres.setHeight("300px");
groupsres.setWidth("350px");
groupsres.select(groupsres.firstItemId());
groupsres.setNullSelectionAllowed(false);
resLayout.setSizeFull();
resLayout.setSpacing(true);
HorizontalLayout nameLayout = new HorizontalLayout();
nameLayout.addComponent(resLabe);
resLayout.addComponent(nameLayout);
resLayout.setComponentAlignment(nameLayout, Alignment.MIDDLE_RIGHT);
HorizontalLayout layout1 = new HorizontalLayout();
layout1.addComponent(resName);
layout1.addComponent(checb);
layout1.setSpacing(true);
resLayout.addComponent(layout1);
HorizontalLayout descriptLayout = new HorizontalLayout();
descriptLayout.addComponent(descriptionLabelres);
resLayout.addComponent(descriptLayout);
resLayout.setComponentAlignment(descriptLayout, Alignment.MIDDLE_RIGHT);
resLayout.addComponent(resDescription);
resLayout.setHeight("200");
HorizontalLayout horizont = new HorizontalLayout();
horizont.addComponent(resLayout);
horizont.setComponentAlignment(resLayout, Alignment.MIDDLE_CENTER);
horizont.addComponent(list);
horizont.setSpacing(true);
HorizontalLayout horizontlay = new HorizontalLayout();
horizontlay.addComponent(horizont);
horizontlay.setComponentAlignment(horizont, Alignment.MIDDLE_CENTER);
horizontlay.setSizeFull();
resPanel.addComponent(horizontlay);
HorizontalLayout groupLayout = new HorizontalLayout();
//groupLayout.addComponent(list);
groupLayout.addComponent(groupsres);
groupLayout.addComponent(editGroupRes);
groupLayout.setSpacing(true);
HorizontalLayout groupLayoutLayout = new HorizontalLayout();
groupLayoutLayout.addComponent(groupLayout);
groupLayoutLayout.setComponentAlignment(groupLayout,
Alignment.MIDDLE_CENTER);
groupLayoutLayout.setSizeFull();
groupLayoutLayout.setSpacing(true);
resPanel.addComponent(groupLayoutLayout);
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.addComponent(save);
HorizontalLayout buttonLayoutLayout = new HorizontalLayout();
buttonLayoutLayout.addComponent(buttonLayout);
buttonLayoutLayout.setComponentAlignment(buttonLayout,
Alignment.MIDDLE_CENTER);
buttonLayoutLayout.setSizeFull();
buttonLayoutLayout.setHeight("35");
save.setWidth("150");
resPanel.addComponent(buttonLayoutLayout);
save.addListener(new ClickListener() {
/**
*
*/
private static final long serialVersionUID = 1L;
public void buttonClick(ClickEvent event) {
if ((resName.toString().length() != 0)
&& (Integer.parseInt(list.getItem(list.getValue())
.getItemProperty("Type ID").toString()) != 0)) {
resource.setResourceTypeID(Integer.parseInt(list
.getItem(list.getValue())
.getItemProperty("Type ID").toString()));
resource.setActive(checb.booleanValue());
resource.setResourceName(resName.toString());
resource.setDescription(resDescription.toString());
try {
ResourceDAO resDao = df.getResourceDAO();
resDao.insertResource(resource);
for (int i = 0; i <= groupnumber; i++) {
if (groups.isSelected(i)) {
Group gr = new Group();
gr.setGroupID((Integer.parseInt(groups
.getItem(i).getItemProperty("Group ID")
.toString())));
gr.setGroupName(groups.getItem(i)
.getItemProperty("Group Name")
.toString());
df.getResourceDAO().addResourceToGroup(
resource, gr);
}
}
me.getApplication().getMainWindow()
.setContent(new HubPageUI(u));
} catch (ResourceNameExistsException e) {
e.printStackTrace();
me.getApplication().getMainWindow()
.showNotification("Database Error!");
} catch (DAOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
System.out.println("Ures!");
me.getApplication().getMainWindow()
.showNotification("Data error!");
}
}
});
editGroupRes.addListener(new ClickListener() {
/**
*
*/
private static final long serialVersionUID = -4241011703441499400L;
public void buttonClick(ClickEvent event) {
final Window w = new Window();
final TextField newGroup = new TextField();
Button saveGroup = new Button("Save");
w.addComponent(newGroup);
w.addComponent(saveGroup);
me.getApplication().getMainWindow().addWindow(w);
saveGroup.addListener(new ClickListener() {
/**
*
*/
private static final long serialVersionUID = -8351414499108265541L;
public void buttonClick(ClickEvent event) {
Group gr = new Group();
gr.setGroupName(newGroup.getValue().toString());
try {
df.getGroupDAO().insertGroup(gr);
} catch (GroupExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();