Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    LinkItem not disabled in print preview

    I am having issue with getting the link item to be disabled in print preview window, even though I am disabling it via code.

    In this code example, we have a textitem and linkitem in a form and they are enabled in the form, however they need to be disabled in print preview.

    I am using the 3.0 nightly as of 6th March 2012 along with GWT 2.3 jars.

    Sample code is attached. Any assistance is grately appreciated.

    Code:
    public class GwtProject implements EntryPoint {
    
    	public void onModuleLoad() {
    
    		final VLayout layout = new VLayout();
    
    		final DynamicForm form = new DynamicForm();
    		form.setHeight(100);
    		form.setWidth(100);
    
    		final TextItem textItem = new TextItem();
    		textItem.setTitle("Name");
    
    		final LinkItem link = new LinkItem("dummylink");
    		link.setShowTitle(false);
    		link.setLinkTitle("this link should be disabled in print preview");
    		link.setValue("http://www.google.com");
    
    		form.setFields(textItem, link);
    		layout.addMember(form);
    
    		final IButton printPreviewButton = new IButton("Print Preview");
    		layout.addMember(printPreviewButton);
    
    		printPreviewButton.addClickHandler(new ClickHandler() {
    
    			@Override
    			public void onClick(final ClickEvent event) {
    
    				disableOrEnableCanvas(layout, true);
    				final PrintPreviewCallback callback = new PrintPreviewCallback() {
    					@Override
    					public void execute(final PrintCanvas printCanvas, final PrintWindow printWindow) {
    						disableOrEnableCanvas(layout, false);
    					}
    				};
    				showPrintPreview("Print Preview", callback, layout);
    			}
    		});
    
    		layout.draw();
    	}
    
    	public static void showPrintPreview(final String title, final PrintPreviewCallback callback, final Canvas component, final Canvas... others) {
    
    		//		final Canvas newCanvas = new Canvas("newCanvas");
    		//		for (final Canvas c : component.getChildren()) {
    		//			if (c instanceof DynamicForm) {
    		//				final FormItem[] formItems = ((DynamicForm) c).getFields();
    		//				for (final FormItem f : formItems) {
    		//					if (f instanceof LinkItem) {
    		//						continue;
    		//					}
    		//					//					System.out.println("1");
    		//					newCanvas.addChild(c);
    		//				}
    		//			} else {
    		//				newCanvas.addChild(c);
    		//			}
    		//		}
    
    		final List<Canvas> components = new ArrayList<Canvas>();
    		Window printWindow = new Window();
    		components.add(component);
    		//		components.add(newCanvas);
    
    		printWindow = new ModalWindow().getPrintPreviewWindow(750, 250);
    		printWindow.disable();
    
    		for (final Canvas canvas : others) {
    			canvas.disable();
    			components.add(canvas);
    		}
    
    		Canvas.showPrintPreview(components.toArray(new Canvas[components.size()]), null, title, callback, printWindow, "");
    	}
    
    	public static void disableOrEnableCanvas(final Layout layout, final boolean disableFormFields) {
    
    		final Canvas[] canvasArray = layout.getMembers();
    		for (final Canvas member : canvasArray) {
    			disableForm(member, disableFormFields);
    		}
    	}
    
    	public static void disableForm(final Canvas canvas, final boolean disableFormFields) {
    
    		if (canvas instanceof Layout) {
    			disableOrEnableCanvas((Layout) canvas, disableFormFields);
    
    		} else if (canvas instanceof DynamicForm) {
    			for (final FormItem field : ((DynamicForm) canvas).getFields()) {
    
    				if (field instanceof RadioGroupItem) {
    					((RadioGroupItem) field).setDisabled(disableFormFields);
    				}
    
    				if (field instanceof TextItem) {
    					System.out.println("TextItem:" + field.getTitle());
    					final TextItem txtItem = (TextItem) field;
    					txtItem.setDisabled(disableFormFields);
    				}
    				if (field instanceof LinkItem) {
    					final LinkItem linkItem = (LinkItem) field;
    					System.out.println("Link:" + linkItem.getTitle() + "=((DynamicForm) canvas)=" + ((DynamicForm) canvas).getID());
    					if (disableFormFields) {
    						((LinkItem) field).setDisabled(disableFormFields);
    						linkItem.setAttribute("readOnly", disableFormFields);
    						System.out.println("link disabled....");
    						linkItem.disable();
    					} else {
    						linkItem.enable();
    						System.out.println("link enabled....");
    					}
    				} else {
    					field.disable();
    					field.setAttribute("readOnly", disableFormFields);
    				}
    			}
    		}
    	}
    
    	class HelpCanvas extends Canvas {
    		private final String contents = "<b>Severity 1</b> - Critical problem<br>System is unavailable in production or " + "is corrupting data, and the error severely impacts the user's operations." + "<br><br><b>Severity 2</b> - Major problem<br>An important function of the system " + "is not available in production, and the user's operations are restricted." + "<br><br><b>Severity 3</b> - Minor problem<br>Inability to use a function of the " + "system occurs, but it does not seriously affect the user's operations.";
    
    		public HelpCanvas(final String id) {
    			setID(id);
    			setPadding(10);
    			setOverflow(Overflow.AUTO);
    			setContents(contents);
    		}
    	}
    
    }

    #2
    We've made a change to the code-base to address this directly in 3.0p and 3.1d branches. Please try the next nightly build (March 22 or greater) and let us know if this continues to be an issue

    Regards
    Isomorphic Software

    Comment


      #3
      Thanks the 3/22 nightly fixes this issue, thanks!

      Comment

      Working...
      X