Skip to content

Commit

Permalink
updated localization for upload panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Feb 20, 2014
1 parent 95b0f09 commit 04d4aa2
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 73 deletions.
Expand Up @@ -16,8 +16,6 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<wicket:panel>
<div wicket:id="feedback" class="messagePanel"/>

<div class="col-xs-8">
<input wicket:id="fileInput" type="file"/>
</div>
Expand Down
Expand Up @@ -15,83 +15,99 @@
*/
package com.evolveum.midpoint.web.component.input;

import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.prism.InputPanel;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;

/**
* @author shood
* */
public class UploadPanel<T> extends InputPanel {
* @author shood
* @author lazyman
*/
public class UploadPanel extends InputPanel {

private static final Trace LOGGER = TraceManager.getTrace(UploadPanel.class);

private static final String ID_BUTTON_UPLOAD = "upload";
private static final String ID_BUTTON_DELETE = "remove";
private static final String ID_INPUT_FILE = "fileInput";
private static final String ID_FEEDBACK = "feedback";

public UploadPanel(String id){
public UploadPanel(String id) {
super(id);
initLayout();
}

private void initLayout(){

final FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK);
feedback.setOutputMarkupId(true);
add(feedback);

private void initLayout() {
FileUploadField fileUpload = new FileUploadField(ID_INPUT_FILE);
add(fileUpload);

add(new AjaxSubmitButton(ID_BUTTON_UPLOAD) {

@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form){
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
uploadFilePerformed(target);
}

@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
target.add(getFeedbackPanel());
uploadFileFailed(target);
}
});

add(new AjaxSubmitButton(ID_BUTTON_DELETE) {

@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form){
removePhotoPerformed(target);
}

@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
target.add(getFeedbackPanel());
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
removeFilePerformed(target);
}
});
}

@Override
public FormComponent getBaseFormComponent(){
public FormComponent getBaseFormComponent() {
return (FormComponent) get(ID_INPUT_FILE);
}

public FileUpload getFileUpload(){
private FileUpload getFileUpload() {
FileUploadField file = (FileUploadField) get(ID_INPUT_FILE);
final FileUpload uploadedFile = file.getFileUpload();
return file.getFileUpload();
}

return uploadedFile;
public void uploadFilePerformed(AjaxRequestTarget target) {
Component input = get(ID_INPUT_FILE);
try {
FileUpload uploadedFile = getFileUpload();
updateValue(uploadedFile.getBytes());
LOGGER.trace("Upload file success.");
input.success(getString("UploadPanel.message.uploadSuccess"));
} catch (Exception e) {
LOGGER.trace("Upload file error.", e);
input.error(getString("UploadPanel.message.uploadError") + " " + e.getMessage());
}
}

public FeedbackPanel getFeedbackPanel(){
return (FeedbackPanel)get(ID_FEEDBACK);
public void removeFilePerformed(AjaxRequestTarget target) {
Component input = get(ID_INPUT_FILE);
try {
updateValue(null);
LOGGER.trace("Remove file success.");
input.success(getString("UploadPanel.message.removeSuccess"));
} catch (Exception e) {
LOGGER.trace("Remove file error.", e);
input.error(getString("UploadPanel.message.removeError") + " " + e.getMessage());
}
}

public void uploadFilePerformed(AjaxRequestTarget target){}
public void removePhotoPerformed(AjaxRequestTarget target){}
public void uploadFileFailed(AjaxRequestTarget target) {
LOGGER.trace("Upload file validation failed.");
}

public void updateValue(byte[] file) {
}
}
Expand Up @@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
UploadPanel.message.help=Choose Xml file for import.
UploadPanel.upload.tooltip=Upload Photo
UploadPanel.delete.tooltip=Remove Photo
UploadPanel.message.help=Choose file for import.
UploadPanel.upload.tooltip=Upload file
UploadPanel.delete.tooltip=Remove file
UploadPanel.message.uploadSuccess=File upload was successful. Continue with editing and press 'Save' when done.
UploadPanel.message.uploadError=File upload failed. Try again please.
UploadPanel.message.removeSuccess=File was removed.
UploadPanel.message.removeError=File was not removed.
Expand Up @@ -28,11 +28,6 @@
</div>
</div>
<div class="row">
<!--<div>-->
<!--<img wicket:id="helpButton"/>-->

<!--<div wicket:id="helpContent"/>-->
<!--</div>-->
<span wicket:id="feedback" class="text-danger"/>
</div>
</wicket:panel>
Expand Down
Expand Up @@ -66,6 +66,8 @@
*/
public class PrismValuePanel extends Panel {

private static final String ID_FEEDBACK = "feedback";

private IModel<ValueWrapper> model;

public PrismValuePanel(String id, IModel<ValueWrapper> model, IModel<String> label, Form form) {
Expand All @@ -78,20 +80,10 @@ public PrismValuePanel(String id, IModel<ValueWrapper> model, IModel<String> lab

private void initLayout(IModel<String> label, Form form) {
//feedback
FeedbackPanel feedback = new FeedbackPanel("feedback");
FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK);
feedback.setOutputMarkupId(true);
add(feedback);

// //helpButton
// Image helpButtonImage = new Image("helpButton", new Model<String>("InfoSmall.png"));
// helpButtonImage.setOutputMarkupId(true);
// add(helpButtonImage);
//
// //helpContent
// Label labelHelpContent = new Label("helpContent", createHelpModel());
// labelHelpContent.setMarkupId("content_" + helpButtonImage.getMarkupId());
// add(labelHelpContent);

//input
InputPanel input = createInputComponent("input", label, form);
initAccessBehaviour(input);
Expand Down Expand Up @@ -368,7 +360,7 @@ private InputPanel createTypedInputComponent(String id) {
} else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(model, baseExpression));
} else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
panel = new TextPanel<String>(id, new PropertyModel<String>(model, baseExpression + ".orig"), String.class);
panel = new TextPanel<>(id, new PropertyModel<String>(model, baseExpression + ".orig"), String.class);

PrismPropertyDefinition def = property.getDefinition();
if (ObjectType.F_NAME.equals(def.getName()) || UserType.F_FULL_NAME.equals(def.getName())) {
Expand All @@ -378,28 +370,27 @@ private InputPanel createTypedInputComponent(String id) {
panel = new UploadPanel(id){

@Override
public void uploadFilePerformed(AjaxRequestTarget target){
try{
FileUpload uploadedFile = getFileUpload();
model.getObject().getValue().setValue(uploadedFile.getBytes());
success("Image upload was successful. Continue with editing and press 'Save' when done.");
target.add();
} catch (Exception e){
error("Image upload was not successful. Try again please.");
target.add(getFeedbackPanel());
}
public void updateValue(byte[] file) {
model.getObject().getValue().setValue(file);
}

@Override
public void uploadFilePerformed(AjaxRequestTarget target) {
super.uploadFilePerformed(target);
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
}

@Override
public void removeFilePerformed(AjaxRequestTarget target) {
super.removeFilePerformed(target);
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
}

@Override
public void removePhotoPerformed(AjaxRequestTarget target){
try{
model.getObject().getValue().setValue(null);
success("Image removal was successful.");
target.add(getFeedbackPanel());
} catch (Exception e){
error("Image removal was not successful.");
target.add(getFeedbackPanel());
}
public void uploadFileFailed(AjaxRequestTarget target) {
super.uploadFileFailed(target);
target.add(PrismValuePanel.this.get(ID_FEEDBACK));
target.add(((PageBase) getPage()).getFeedbackPanel());
}
};

Expand All @@ -408,8 +399,7 @@ public void removePhotoPerformed(AjaxRequestTarget target){
if (type != null && type.isPrimitive()) {
type = ClassUtils.primitiveToWrapper(type);
}
panel = new TextPanel<String>(id, new PropertyModel<String>(model, baseExpression),
type);
panel = new TextPanel<>(id, new PropertyModel<String>(model, baseExpression), type);
}

return panel;
Expand Down

0 comments on commit 04d4aa2

Please sign in to comment.