Package jease.cms.web.content.editor

Source Code of jease.cms.web.content.editor.LinkEditor

/*
    Copyright (C) 2011 maik.jablonski@jease.org

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package jease.cms.web.content.editor;

import jease.cmf.service.Nodes;
import jease.cmf.web.node.browser.NodeBrowserWindow;
import jease.cms.domain.Link;
import jfix.util.I18N;
import jfix.zk.ActionListener;
import jfix.zk.Button;
import jfix.zk.Images;
import jfix.zk.Linkbutton;
import jfix.zk.Row;
import jfix.zk.Textfield;
import jfix.zk.WebBrowser;

import org.zkoss.zk.ui.event.Event;

public class LinkEditor extends ContentEditor<Link> {

  Textfield url = new Textfield();
  Linkbutton link = new Linkbutton();
  Button browse = new Button(I18N.get("Browser"), Images.UserHome);

  public LinkEditor() {
    link.setTooltiptext(I18N.get("Open"));
    link.setImage(Images.InternetWebBrowser);
    link.setWidth("24px");
    link.addClickListener(new ActionListener() {
      public void actionPerformed(Event event) {
        if (!url.isEmpty()) {
          getRoot().appendChild(new WebBrowser(url.getText()));
        }
      }
    });
    browse.addClickListener(new ActionListener() {
      public void actionPerformed(Event event) {
        browsePerformed();
      }
    });
  }

  public void init() {
    add(I18N.get("Url"), new Row(url, link));
    add("", browse);

  }

  public void load() {
    url.setText(getNode().getUrl());
  }

  public void save() {
    getNode().setUrl(url.getText());
  }

  public void validate() {
    validate(url.isEmpty(), I18N.get("Url_is_required"));
  }

  private void browsePerformed() {
    String path = url.getValue();
    if (path.startsWith("./~")) {
      path = path.substring(3);
    }
    final NodeBrowserWindow nodeBrowserWindow = new NodeBrowserWindow(
        Nodes.getByPath(path));
    nodeBrowserWindow.setTitle(I18N.get("Browser"));
    nodeBrowserWindow.addCloseListener(new ActionListener() {
      public void actionPerformed(Event event) {
        if (nodeBrowserWindow.getSelectedNode() != null) {
          url.setText("./~"
              + nodeBrowserWindow.getSelectedNode().getPath());
        }
      }
    });
    getRoot().appendChild(nodeBrowserWindow);
  }
}
TOP

Related Classes of jease.cms.web.content.editor.LinkEditor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.