Skip to content

Commit

Permalink
Merge branch 'feature/589_dpu_template_config_reuse' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	db/mysql/rdbms/updates/1.4.0-update.sql
  • Loading branch information
skodapetr committed Nov 13, 2014
2 parents df96990 + cccd292 commit beec69c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public boolean preAction(Node node,
@SuppressWarnings("unchecked")
DPUConfigurable configurable = (DPUConfigurable) dpuInstance;
try {
configurable.configure(dpu.getRawConf());
String conf = dpu.isUseTemplateConfig() ? dpu.getTemplate().getRawConf() : dpu.getRawConf();
configurable.configure(conf);

LOG.debug("DPU {} has been configured.", dpu.getName());
} catch (DPUConfigException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cz.cuni.mff.xrg.odcs.commons.app.dpu;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
Expand All @@ -25,6 +26,9 @@ public class DPUInstanceRecord extends DPURecord {
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "dpu_id")
private DPUTemplateRecord template;

@Column(name = "use_template_config")
private boolean useTemplateConfig;

/**
* Empty constructor because of JPA.
Expand All @@ -43,6 +47,7 @@ public DPUInstanceRecord() {
public DPUInstanceRecord(DPUInstanceRecord dpuInstance) {
super(dpuInstance);
template = dpuInstance.getTemplate();
this.useTemplateConfig = false;
}

/**
Expand All @@ -52,6 +57,7 @@ public DPUInstanceRecord(DPUInstanceRecord dpuInstance) {
*/
public DPUInstanceRecord(String name) {
super(name);
this.useTemplateConfig = false;
}

/**
Expand All @@ -64,6 +70,7 @@ public DPUInstanceRecord(DPUTemplateRecord template) {
super(template);
// and set out variables
this.template = template;
this.useTemplateConfig = false;
}

/**
Expand All @@ -80,6 +87,22 @@ public DPUTemplateRecord getTemplate() {
public void setTemplate(DPUTemplateRecord template) {
this.template = template;
}

/**
*
* @return true if dpu should use template configuration, false if dpu should use instance configuration
*/
public boolean isUseTemplateConfig() {
return useTemplateConfig;
}

/**
*
* @param useTemplateConfig true if dpu should use template configuration, false if dpu should use instance configuration
*/
public void setUseTemplateConfig(boolean useTemplateConfig) {
this.useTemplateConfig = useTemplateConfig;
}

@Override
public DPUType getType() {
Expand All @@ -102,5 +125,4 @@ public void loadInstance(ModuleFacade moduleFacade) throws ModuleException {
public String getJarPath() {
return template.getJarPath();
}

}
1 change: 1 addition & 0 deletions db/mysql/rdbms/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CREATE TABLE `dpu_instance`
`config_valid` SMALLINT,
-- DPUInstaceRecord
`dpu_id` INTEGER,
`use_template_config` SMALLINT NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE INDEX `ix_DPU_INSTANCE_dpu_id` ON `dpu_instance` (`dpu_id`);
Expand Down
2 changes: 1 addition & 1 deletion db/mysql/rdbms/updates/1.4.0-update.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ ALTER TABLE logging ENGINE = innodb;
DELETE FROM `properties` WHERE `key` = 'UV.Core.version';
INSERT INTO `properties` SET `value` = '001.004.000', `key` = 'UV.Core.version';
DELETE FROM `properties` WHERE `key` = 'UV.Plugin-DevEnv.version';
INSERT INTO `properties` SET `value` = '001.000.001', `key` = 'UV.Plugin-DevEnv.version';
INSERT INTO `properties` SET `value` = '001.000.001', `key` = 'UV.Plugin-DevEnv.version';
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.slf4j.LoggerFactory;

import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.Validator;
import com.vaadin.shared.ui.MarginInfo;
Expand Down Expand Up @@ -42,6 +43,10 @@ public class DPUGeneralDetail extends CustomComponent {

private final CheckBox useUserDescription;

private final CheckBox useTemplateConfiguration;

private final Label useTemplateConfigurationLabel;

/**
* True if the dialog content is read only.
*/
Expand All @@ -52,11 +57,11 @@ public class DPUGeneralDetail extends CustomComponent {
*/
private ValueChangeListener valueChangeListener = null;

public DPUGeneralDetail() {
public DPUGeneralDetail(final DPUConfigHolder instanceConfig) {
setWidth("100%");
setHeight("-1px");
// create subcomponents
GridLayout mainLayout = new GridLayout(2, 4);
GridLayout mainLayout = new GridLayout(2, 5);
mainLayout.setWidth("100%");
mainLayout.setSpacing(true);
mainLayout.setMargin(new MarginInfo(false, false, true, false));
Expand Down Expand Up @@ -94,13 +99,29 @@ public DPUGeneralDetail() {
mainLayout.addComponent(new Label("Use custom description"), 0, 3);
useUserDescription = new CheckBox();
useUserDescription.addValueChangeListener(new ValueChangeListener() {
private static final long serialVersionUID = 1L;

@Override
public void valueChange(Property.ValueChangeEvent event) {
final boolean useUserDesc = useUserDescription.getValue();
dpuDescription.setEnabled(useUserDesc);
}
});
mainLayout.addComponent(useUserDescription, 1, 3);

useTemplateConfigurationLabel = new Label("Use template configuration");
mainLayout.addComponent(useTemplateConfigurationLabel, 0, 4);
useTemplateConfiguration = new CheckBox();
useTemplateConfiguration.addValueChangeListener(new ValueChangeListener() {
private static final long serialVersionUID = 1L;

@Override
public void valueChange(ValueChangeEvent event) {
boolean isUseTemplConf = (boolean) event.getProperty().getValue();
instanceConfig.setEnabled(!isUseTemplConf);
}
});
mainLayout.addComponent(useTemplateConfiguration, 1, 4);

// expand column with the text boxes
mainLayout.setColumnExpandRatio(1, 1.0f);
Expand Down Expand Up @@ -156,10 +177,17 @@ public void loadFromDPU(DPURecord dpu, boolean readOnly) {

dpuTemplateName.setVisible(true);
dpuTemplateNameLabel.setVisible(true);

useTemplateConfiguration.setValue(instance.isUseTemplateConfig());
useTemplateConfiguration.setVisible(true);
useTemplateConfigurationLabel.setVisible(true);

} else {
dpuTemplateName.setVisible(false);
dpuTemplateNameLabel.setVisible(false);

useTemplateConfiguration.setVisible(false);
useTemplateConfigurationLabel.setVisible(false);
}

if (dpu.isUseDPUDescription()) {
Expand Down Expand Up @@ -199,6 +227,11 @@ public void saveToDPU(DPURecord dpu, DPURecordWrap wrap) {
}
dpu.setUseDPUDescription(true);
}

if (dpu instanceof DPUInstanceRecord) {
DPUInstanceRecord instance = (DPUInstanceRecord) dpu;
instance.setUseTemplateConfig(useTemplateConfiguration.getValue());
}

// if (userDescription.isEmpty()) {
// // get configuration from dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
Expand Down Expand Up @@ -57,6 +58,8 @@ public class DPUDetail extends Window {
private Button btnSaveAndCommit;

private Button btnCancel;

private Button btnCopyFromTemplate;

private boolean result;

Expand All @@ -82,12 +85,12 @@ public DPUDetail(DPUFacade dpuFacade) {
* Construct page layout.
*/
private void build() {
// the DPU general info
generalDetail = new DPUGeneralDetail();

// panel for DPU detail dialog
configHolder = new DPUConfigHolder();

// the DPU general info
generalDetail = new DPUGeneralDetail(configHolder);

HorizontalLayout buttonBar = buildFooter();

VerticalLayout mainLayout = new VerticalLayout();
Expand Down Expand Up @@ -127,14 +130,37 @@ public HorizontalLayout buildFooter() {
btnCancel = new Button("Cancel");
btnCancel.setWidth("90px");
buttonBar.addComponent(btnCancel);

btnCopyFromTemplate = new Button("Copy from template");
btnCopyFromTemplate.setWidth("160px");
buttonBar.addComponent(btnCopyFromTemplate);
buttonBar.setExpandRatio(btnCopyFromTemplate, 1.0f);
buttonBar.setComponentAlignment(btnCopyFromTemplate, Alignment.MIDDLE_RIGHT);

btnCopyFromTemplate.addClickListener(new Button.ClickListener() {
private static final long serialVersionUID = 1L;

@Override
public void buttonClick(ClickEvent event) {
DPUInstanceRecord instance = dpuInstance.getDPUInstanceRecord();
String oldConf = instance.getRawConf();
// set template conf to reload gui
instance.setRawConf(instance.getTemplate().getRawConf());
reloadConfDialog();
// change it back
instance.setRawConf(oldConf);
}
});

btnSaveAsNew = new Button("Save as DPU template");
btnSaveAsNew.setWidth("160px");
buttonBar.addComponent(btnSaveAsNew);
buttonBar.setExpandRatio(btnSaveAsNew, 1.0f);
// buttonBar.setExpandRatio(btnSaveAsNew, 1.0f);
buttonBar.setComponentAlignment(btnSaveAsNew, Alignment.MIDDLE_RIGHT);

btnSaveAndCommit.addClickListener(new Button.ClickListener() {
private static final long serialVersionUID = 1L;

@Override
public void buttonClick(Button.ClickEvent event) {
if (saveDPUInstance()) {
Expand Down Expand Up @@ -188,6 +214,10 @@ public void showDpuDetail(DPUInstanceRecord dpu, boolean readOnly) {
btnSaveAndCommit.setEnabled(!readOnly);
btnSaveAsNew.setEnabled(!readOnly);

reloadConfDialog();
}

private void reloadConfDialog() {
Component confDialog = null;
try {
confDialog = dpuInstance.getDialog();
Expand Down

0 comments on commit beec69c

Please sign in to comment.