All Downloads are FREE. Search and download functionalities are using the official Maven repository.

at.spardat.xma.page.StatusBar Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

package at.spardat.xma.page;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import at.spardat.xma.component.*;

/**
 * This class implements the status bar of a DialogPage.
 * The status bar consists of an Icon indicating the severity of the message
 * and a read-only text field showing the message.
 * 
 * @author s2877
 */
public class StatusBar extends Composite {
    ComponentClient component;
    Label icon;
    Text message;
    
    /**
     * Constructor for StatusBar. Initializes the Control and its Widgets.
     * @param parent the parent composite
     * @param style sorry only SWT.NONE supported
     */
    public StatusBar(Composite parent, int style) {
        super(parent, SWT.BORDER);
        
        PageClient page = (PageClient) parent.getData();
        while (page==null && parent!=null) {
            parent = parent.getParent();
            page = (PageClient) parent.getData();
        }
        if(page!=null) {
            component = page.getComponent();
        }
            
        setLayout(new FormLayout());
        icon = new Label(this,SWT.NONE);
        message = new Text(this,SWT.READ_ONLY);
        
        FormData data = new FormData();
        data.left = new FormAttachment(0, 0);
        data.top = new FormAttachment(message, 0, SWT.CENTER);
        icon.setLayoutData(data);
            //images originally from eclipse\plugins\org.eclipse.ui_2.0.2\workbench.jar
//        icon.setImage(component.getImage("at/spardat/xma/page/message_empty.gif"));
        
        data = new FormData();
        data.left = new FormAttachment(icon, 0, SWT.DEFAULT);
        data.right = new FormAttachment(100, 0);
        data.top = new FormAttachment(0, 0);
        message.setLayoutData(data);        

//        // wird benoetigt wenn die Statusline ihre Images selbst verwalten soll.
//        addDisposeListener(new DisposeListener() {
//            public void widgetDisposed(DisposeEvent e) {
//                dispose Images 
//            }
//        });

    }

    /**
     * Displays a message as information.
     * Displays the Info-Icon in front of the text.
     * 
     * @param text the message to display
     */
    public void setInfo(String text) {
        if(component!=null) {
            icon.setImage(component.getImage("at/spardat/xma/page/message_info.gif"));
        }
        message.setText(text);
        layout(true);
    }    

    /**
     * Displays a message as warning.
     * Displays the Warning-Icon in front of the text.
     * 
     * @param text the message to display
     */
    public void setWarning(String text) {
        if(component!=null) {
            icon.setImage(component.getImage("at/spardat/xma/page/message_warning.gif"));
        }
        message.setText(text);
        layout(true);
    }    

    /**
     * Displays a message as error.
     * Displays the Error-Icon in front of the text.
     * 
     * @param text the message to display
     */
    public void setError(String text) {
        if(component!=null) {
            icon.setImage(component.getImage("at/spardat/xma/page/message_error.gif"));
        }
        message.setText(text);
        layout(true);
    }    

    /**
     * Clears the StatusBar. No Icon or Message is displayed.
     */
    public void clear() {
//        icon.setImage(component.getImage("at/spardat/xma/page/message_empty.gif"));
        icon.setImage(null);
        message.setText("");
        layout(true);
    }

    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy