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

org.efaps.ui.wicket.components.RecentObjectLink Maven / Gradle / Ivy

Go to download

eFaps WebApp provides a web interface as the User Interface for eFaps which can be easily expanded and altered.

There is a newer version: 3.2.0
Show newest version
/*
 * Copyright 2003 - 2012 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Revision:        $Rev: 7589 $
 * Last Changed:    $Date: 2012-06-05 21:32:24 -0500 (Tue, 05 Jun 2012) $
 * Last Changed By: $Author: [email protected] $
 */


package org.efaps.ui.wicket.components;

import java.io.Serializable;
import java.io.StringReader;
import java.util.UUID;

import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.request.cycle.RequestCycle;
import org.efaps.admin.dbproperty.DBProperties;
import org.efaps.admin.ui.AbstractUserInterfaceObject.TargetMode;
import org.efaps.admin.ui.Menu;
import org.efaps.beans.ValueList;
import org.efaps.beans.valueparser.ParseException;
import org.efaps.beans.valueparser.ValueParser;
import org.efaps.db.Instance;
import org.efaps.db.PrintQuery;
import org.efaps.ui.wicket.models.objects.AbstractUIObject;
import org.efaps.ui.wicket.pages.contentcontainer.ContentContainerPage;
import org.efaps.ui.wicket.pages.error.ErrorPage;
import org.efaps.util.EFapsException;


/**
 * TODO comment!
 *
 * @author The eFaps Team
 * @version $Id: RecentObjectLink.java 7589 2012-06-06 02:32:24Z [email protected] $
 */
public class RecentObjectLink
    implements IRecent, Serializable
{
    /**
     * Needed for serialization.
     */
    private static final long serialVersionUID = 1L;
    /**
     * Instance of the Object thi slink belongs to.
     */
    private final Instance instance;

    /**
     * Label of this link.
     */

    private String label;
    /**
     * UUID of the menu.
     */
    private UUID menuUUID;

    /**
     * UUID of the selected command.
     */
    private UUID cmdUUID;

    /**
     * @param _uiObject     uiObject this Link belongs to
     * @throws EFapsException on error
     */
    public RecentObjectLink(final AbstractUIObject _uiObject)
        throws EFapsException
    {
        this.instance = _uiObject.getInstance();
        try {
            if (getInstance() != null && getInstance().isValid()) {
                final Menu menu = Menu.getTypeTreeMenu(getInstance().getType());
                this.menuUUID = menu.getUUID();
                this.label = DBProperties.getProperty(menu.getLabel());
                this.cmdUUID = _uiObject.getCommandUUID();

                final ValueParser parser = new ValueParser(new StringReader(getLabel()));
                final ValueList list = parser.ExpressionString();
                if (list.getExpressions().size() > 0) {
                    final PrintQuery print = new PrintQuery(getInstance());
                    list.makeSelect(print);
                    if (print.execute()) {
                        this.label = list.makeString(getInstance(), print, TargetMode.VIEW);
                    }
                }
            }
        } catch (final EFapsException e) {
            throw new RestartResponseException(new ErrorPage(e));
        } catch (final ParseException e) {
            throw new RestartResponseException(new ErrorPage(e));
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void open(final Component _openComponent)
        throws EFapsException
    {
        Page page;
        try {
            page = new ContentContainerPage(this.menuUUID, getInstance().getOid(), this.cmdUUID);
        } catch (final EFapsException e) {
            page = new ErrorPage(e);
        }
        RequestCycle.get().setResponsePage(page);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getLabel(final int _maxLength)
        throws EFapsException
    {
        String labelTmp = getLabel();
        if (labelTmp.length() > _maxLength) {
            labelTmp = labelTmp.substring(0, _maxLength - 3) + "...";
        }
        return labelTmp;
    }

    /**
     * Getter method for the instance variable {@link #label}.
     *
     * @return value of instance variable {@link #label}
     */
    protected String getLabel()
    {
        return this.label;
    }

    /**
     * Getter method for the instance variable {@link #instance}.
     *
     * @return value of instance variable {@link #instance}
     */
    protected Instance getInstance()
    {
        return this.instance;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy