Example usage for com.vaadin.server ClassResource ClassResource

List of usage examples for com.vaadin.server ClassResource ClassResource

Introduction

In this page you can find the example usage for com.vaadin.server ClassResource ClassResource.

Prototype

public ClassResource(Class<?> associatedClass, String resourceName) 

Source Link

Document

Creates a new application resource instance.

Usage

From source file:annis.gui.controlpanel.QueryPanel.java

License:Apache License

public QueryPanel(final AnnisUI ui) {
    super(4, 5);//from w ww. j ava  2  s.  c  o  m
    this.ui = ui;

    this.lastPublicStatus = "Welcome to ANNIS! " + "A tutorial is available on the right side.";

    this.state = ui.getQueryState();

    setSpacing(true);
    setMargin(false);

    setRowExpandRatio(0, 1.0f);
    setColumnExpandRatio(0, 0.0f);
    setColumnExpandRatio(1, 0.1f);
    setColumnExpandRatio(2, 0.0f);
    setColumnExpandRatio(3, 0.0f);

    txtQuery = new AqlCodeEditor();
    txtQuery.setPropertyDataSource(state.getAql());
    txtQuery.setInputPrompt("Please enter AQL query");
    txtQuery.addStyleName("query");
    if (ui.getInstanceFont() == null) {
        txtQuery.addStyleName("default-query-font");
        txtQuery.setTextareaStyle("default-query-font");
    } else {
        txtQuery.addStyleName(Helper.CORPUS_FONT);
        txtQuery.setTextareaStyle(Helper.CORPUS_FONT);
    }

    txtQuery.addStyleName("keyboardInput");
    txtQuery.setWidth("100%");
    txtQuery.setHeight(15f, Unit.EM);
    txtQuery.setTextChangeTimeout(500);

    final VirtualKeyboardCodeEditor virtualKeyboard;
    if (ui.getInstanceConfig().getKeyboardLayout() == null) {
        virtualKeyboard = null;
    } else {
        virtualKeyboard = new VirtualKeyboardCodeEditor();
        virtualKeyboard.setKeyboardLayout(ui.getInstanceConfig().getKeyboardLayout());
        virtualKeyboard.extend(txtQuery);
    }

    txtStatus = new TextArea();
    txtStatus.setValue(this.lastPublicStatus);
    txtStatus.setWidth("100%");
    txtStatus.setHeight(4.0f, Unit.EM);
    txtStatus.addStyleName("border-layout");
    txtStatus.setReadOnly(true);

    piCount = new ProgressBar();
    piCount.setIndeterminate(true);
    piCount.setEnabled(false);
    piCount.setVisible(false);

    btShowResult = new Button("Search");
    btShowResult.setIcon(FontAwesome.SEARCH);
    btShowResult.setWidth("100%");
    btShowResult.addClickListener(new ShowResultClickListener());
    btShowResult.setDescription("<strong>Show Result</strong><br />Ctrl + Enter");
    btShowResult.setClickShortcut(KeyCode.ENTER, ModifierKey.CTRL);
    btShowResult.setDisableOnClick(true);

    VerticalLayout historyListLayout = new VerticalLayout();
    historyListLayout.setSizeUndefined();

    lstHistory = new ListSelect();
    lstHistory.setWidth("200px");
    lstHistory.setNullSelectionAllowed(false);
    lstHistory.setValue(null);
    lstHistory.addValueChangeListener((ValueChangeListener) this);
    lstHistory.setImmediate(true);
    lstHistory.setContainerDataSource(historyContainer);
    lstHistory.setItemCaptionPropertyId("query");
    lstHistory.addStyleName(Helper.CORPUS_FONT);

    Button btShowMoreHistory = new Button("Show more details", new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            if (historyWindow == null) {
                historyWindow = new Window("History");
                historyWindow.setModal(false);
                historyWindow.setWidth("400px");
                historyWindow.setHeight("250px");
            }
            historyWindow.setContent(new HistoryPanel(state.getHistory(), ui.getQueryController()));

            if (UI.getCurrent().getWindows().contains(historyWindow)) {
                historyWindow.bringToFront();
            } else {
                UI.getCurrent().addWindow(historyWindow);
            }
        }
    });
    btShowMoreHistory.setWidth("100%");

    historyListLayout.addComponent(lstHistory);
    historyListLayout.addComponent(btShowMoreHistory);

    historyListLayout.setExpandRatio(lstHistory, 1.0f);
    historyListLayout.setExpandRatio(btShowMoreHistory, 0.0f);

    btHistory = new PopupButton("History");
    btHistory.setContent(historyListLayout);
    btHistory.setDescription("<strong>Show History</strong><br />"
            + "Either use the short overview (arrow down) or click on the button " + "for the extended view.");

    Button btShowKeyboard = null;
    if (virtualKeyboard != null) {
        btShowKeyboard = new Button();
        btShowKeyboard.setWidth("100%");
        btShowKeyboard.setDescription("Click to show a virtual keyboard");
        btShowKeyboard.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
        btShowKeyboard.addStyleName(ValoTheme.BUTTON_SMALL);
        btShowKeyboard.setIcon(new ClassResource(VirtualKeyboardCodeEditor.class, "keyboard.png"));
        btShowKeyboard.addClickListener(new ShowKeyboardClickListener(virtualKeyboard));
    }

    Button btShowQueryBuilder = new Button("Query<br />Builder");
    btShowQueryBuilder.setHtmlContentAllowed(true);
    btShowQueryBuilder.addStyleName(ValoTheme.BUTTON_SMALL);
    btShowQueryBuilder.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_TOP);
    btShowQueryBuilder.setIcon(new ThemeResource("images/tango-icons/32x32/document-properties.png"));
    btShowQueryBuilder.addClickListener(new ShowQueryBuilderClickListener(ui));

    VerticalLayout moreActionsLayout = new VerticalLayout();
    moreActionsLayout.setWidth("250px");
    btMoreActions = new PopupButton("More");
    btMoreActions.setContent(moreActionsLayout);

    //    btShowResultNewTab = new Button("Search (open in new tab)");
    //    btShowResultNewTab.setWidth("100%");
    //    btShowResultNewTab.addClickListener(new ShowResultInNewTabClickListener());
    //    btShowResultNewTab.setDescription("<strong>Show Result and open result in new tab</strong><br />Ctrl + Shift + Enter");
    //    btShowResultNewTab.setDisableOnClick(true);
    //    btShowResultNewTab.setClickShortcut(KeyCode.ENTER, ModifierKey.CTRL, ModifierKey.SHIFT);
    //    moreActionsLayout.addComponent(btShowResultNewTab);

    Button btShowExport = new Button("Export", new ShowExportClickListener(ui));
    btShowExport.setIcon(FontAwesome.DOWNLOAD);
    btShowExport.setWidth("100%");
    moreActionsLayout.addComponent(btShowExport);

    Button btShowFrequency = new Button("Frequency Analysis", new ShowFrequencyClickListener(ui));
    btShowFrequency.setIcon(FontAwesome.BAR_CHART_O);
    btShowFrequency.setWidth("100%");
    moreActionsLayout.addComponent(btShowFrequency);

    /*
     * We use the grid layout for a better rendering efficiency, but this comes
     * with the cost of some complexity when defining the positions of the
     * elements in the layout.
     * 
     * This grid hopefully helps a little bit in understanding the "magic"
     * numbers better.
     * 
     * Q: Query text field
     * QB: Button to toggle query builder // TODO
     * KEY: Button to show virtual keyboard
     * SEA: "Search" button
     * MOR: "More actions" button 
     * HIST: "History" button
     * STAT: Text field with the real status
     * PROG: indefinite progress bar (spinning circle)
     * 
     *   \  0  |  1  |  2  |  3  
     * --+-----+---+---+---+-----
     * 0 |  Q  |  Q  |  Q  | QB 
     * --+-----+-----+-----+-----
     * 1 |  Q  |  Q  |  Q  | KEY 
     * --+-----+-----+-----+-----
     * 2 | SEA | MOR | HIST|     
     * --+-----+-----+-----+-----
     * 3 | STAT| STAT| STAT| PROG
     */
    addComponent(txtQuery, 0, 0, 2, 1);
    addComponent(txtStatus, 0, 3, 2, 3);
    addComponent(btShowResult, 0, 2);
    addComponent(btMoreActions, 1, 2);
    addComponent(btHistory, 2, 2);
    addComponent(piCount, 3, 3);
    addComponent(btShowQueryBuilder, 3, 0);
    if (btShowKeyboard != null) {
        addComponent(btShowKeyboard, 3, 1);
    }

    // alignment
    setRowExpandRatio(0, 0.0f);
    setRowExpandRatio(1, 1.0f);
    setColumnExpandRatio(0, 1.0f);
    setColumnExpandRatio(1, 0.0f);
    setColumnExpandRatio(2, 0.0f);
    setColumnExpandRatio(3, 0.0f);

    //setComponentAlignment(btShowQueryBuilder, Alignment.BOTTOM_CENTER);
}

From source file:annis.gui.flatquerybuilder.ReducingStringComparator.java

License:Apache License

private void readMappings() {
    ALLOGRAPHS = new HashMap<>();
    ClassResource cr = new ClassResource(ReducingStringComparator.class, MAPPING_FILE);
    try {/*from   w  w w. j a  v  a 2s  . co  m*/
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document mappingD = db.parse(cr.getStream().getStream());

        NodeList mappings = mappingD.getElementsByTagName("mapping");
        for (int i = 0; i < mappings.getLength(); i++) {
            Element mapping = (Element) mappings.item(i);
            String mappingName = mapping.getAttribute("name");
            HashMap mappingMap = initAlphabet();
            NodeList variants = mapping.getElementsByTagName("variant");
            for (int j = 0; j < variants.getLength(); j++) {
                Element var = (Element) variants.item(j);
                char varvalue = var.getAttribute("value").charAt(0);
                Element character = (Element) var.getParentNode();
                char charactervalue = character.getAttribute("value").charAt(0);
                mappingMap.put(varvalue, charactervalue);
            }
            ALLOGRAPHS.put(mappingName, mappingMap);
        }

    } catch (SAXException e) {
        e = null;
        Notification.show(READING_ERROR_MESSAGE);
    } catch (IOException e) {
        e = null;
        Notification.show(READING_ERROR_MESSAGE);
    } catch (ParserConfigurationException e) {
        e = null;
        Notification.show(READING_ERROR_MESSAGE);
    }

}

From source file:annis.libgui.AnnisBaseUI.java

License:Apache License

protected final void initLogging() {
    try {//from  ww w . ja v  a2s. c  o m

        List<File> logbackFiles = getAllConfigLocations("gui-logback.xml");

        InputStream inStream = null;
        if (!logbackFiles.isEmpty()) {
            try {
                inStream = new FileInputStream(logbackFiles.get(logbackFiles.size() - 1));
            } catch (FileNotFoundException ex) {
                // well no logging no error...
            }
        }
        if (inStream == null) {
            ClassResource res = new ClassResource(AnnisBaseUI.class, "logback.xml");
            inStream = res.getStream().getStream();
        }

        if (inStream != null) {
            LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
            JoranConfigurator jc = new JoranConfigurator();
            jc.setContext(context);
            context.reset();

            context.putProperty("webappHome", VaadinService.getCurrent().getBaseDirectory().getAbsolutePath());

            // load config file
            jc.doConfigure(inStream);
        }
    } catch (JoranException ex) {
        log.error("init logging failed", ex);
    }

}

From source file:com.peergreen.demo.weconsole.RefreshTask.java

License:Apache License

protected void updateAllTree() {
    // get all devices
    List<DeviceInfo> devices = getAllDevices();
    System.out.println("found devices length = " + devices.size());

    // First, create devices
    for (DeviceInfo device : devices) {
        System.out.println("found device" + device.getModel());
        final DeviceNode deviceNode = new DeviceNode(device);
        // Not/Found
        if (container.getItem(deviceNode) == null) {
            tree.getUI().access(new Runnable() {

                @Override//from w  ww .j a  va2s  . c o  m
                public void run() {
                    Item item = container.addItem(deviceNode);
                    item.getItemProperty(ENTRY_NAME).setValue(deviceNode.getName());
                    item.getItemProperty(ICON).setValue(new ClassResource(RefreshTask.class, "/device.png"));
                    tree.setChildrenAllowed(deviceNode, true);
                }
            });

        }

        // Update device by adding sensors
        updateDevice(deviceNode);

    }

}

From source file:com.peergreen.demo.weconsole.RefreshTask.java

License:Apache License

protected void updateDevice(DeviceNode deviceNode) {
    // get all sensors
    List<SensorInfo> sensors = getAllSensorsForDevice(deviceNode.getDeviceInfo());

    // First, create sensor if not yet available
    for (SensorInfo sensor : sensors) {
        final SensorNode sensorNode = new SensorNode(deviceNode, sensor);
        // Not/Found
        if (container.getItem(sensorNode) == null) {
            tree.getUI().access(new Runnable() {

                @Override/*from www. ja va2s .c  o m*/
                public void run() {
                    Item item = container.addItem(sensorNode);
                    item.getItemProperty(ENTRY_NAME).setValue(sensorNode.getName());
                    item.getItemProperty(ICON).setValue(new ClassResource(RefreshTask.class, "/sensor.png"));

                    tree.setChildrenAllowed(sensorNode, true);
                    tree.setParent(sensorNode, sensorNode.getParent());
                }
            });
        }

        // Update device by adding sensors
        updateSensor(deviceNode, sensorNode);

    }
}

From source file:com.peergreen.demo.weconsole.RefreshTask.java

License:Apache License

protected void updateSensor(DeviceNode deviceNode, SensorNode sensorNode) {
    // get all sensors
    List<ChannelInfo> channels = getAllChannelsForSensor(deviceNode.getDeviceInfo(),
            sensorNode.getSensorInfo());

    // First, create sensor if not yet available
    for (ChannelInfo channel : channels) {
        final ChannelNode channelNode = new ChannelNode(sensorNode, channel);
        // Not/Found
        if (container.getItem(channelNode) == null) {
            tree.getUI().access(new Runnable() {

                @Override//from ww  w  .j a  v a 2 s . c om
                public void run() {
                    Item item = container.addItem(channelNode);
                    item.getItemProperty(ENTRY_NAME).setValue(channelNode.getName());
                    item.getItemProperty(ICON).setValue(new ClassResource(RefreshTask.class, "/channel.png"));
                    tree.setChildrenAllowed(channelNode, false);
                    tree.setParent(channelNode, channelNode.getParent());
                }
            });
        }
    }
}

From source file:com.peergreen.webconsole.scope.deployment.internal.container.AbstractDeployableContainer.java

License:Open Source License

protected Resource getResource(DeployableEntry deployableEntry) {
    if (!deployableEntry.isDeployable()) {
        return new ClassResource(getClass(), "/images/16x16/directory-icon.png");
    } else {// w w  w.  jav  a2s . c  o m
        String name = deployableEntry.getName();
        String extension = name.contains(".") ? name.substring(name.lastIndexOf('.')) : "";
        switch (extension) {
        case XML_EXTENSION:
            return new ClassResource(getClass(), "/images/16x16/xml-icon.png");
        case JAR_EXTENSION:
            return new ClassResource(getClass(), "/images/16x16/jar-icon.png");
        case WAR_EXTENSION:
            return new ClassResource(getClass(), "/images/16x16/war-icon.png");
        default:
            return new ClassResource(getClass(), "/images/16x16/file-icon.png");
        }
    }
}

From source file:com.peergreen.webconsole.scope.deployment.internal.deployable.DeployablePanel.java

License:Open Source License

@PostConstruct
public void init() {

    setSizeFull();//w w w  . ja  v a  2  s.  c  o m

    VerticalLayout mainContent = new VerticalLayout();
    mainContent.setSpacing(true);
    mainContent.setMargin(true);
    mainContent.setStyleName("deployable-style");
    mainContent.setSizeFull();

    HorizontalLayout header = new HorizontalLayout();
    header.setWidth("100%");
    Button openManager = new Button("Edit repositories");
    openManager.addStyleName("link");
    openManager.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (tabSheet.getTab(manager) == null) {
                tabSheet.addTab(manager, "Manager",
                        new ClassResource(getClass(), "/images/22x22/configuration.png"), containers.size())
                        .setClosable(true);
            }
            tabSheet.setSelectedTab(manager);
        }
    });
    header.addComponent(openManager);
    header.setComponentAlignment(openManager, Alignment.MIDDLE_RIGHT);
    mainContent.addComponent(header);

    tabSheet.setSizeFull();
    mainContent.addComponent(tabSheet);
    mainContent.setExpandRatio(tabSheet, 1.5f);

    DragAndDropWrapper mainContentWrapper = new DragAndDropWrapper(mainContent);
    mainContentWrapper.setDropHandler(new DeploymentDropHandler(deploymentViewManager, this, notifierService));
    mainContentWrapper.setSizeFull();

    setContent(mainContentWrapper);
}

From source file:com.peergreen.webconsole.scope.deployment.internal.deployable.DeployablePanel.java

License:Open Source License

@Link("directory")
public void addDirectoryView(DeployableContainer directoryView, Dictionary properties) {
    this.directoryView = directoryView;
    int position = 0;
    tabSheet.addTab(directoryView.getView(), getDeployableCaption(properties),
            new ClassResource(getClass(), "/images/22x22/directory.png"), position);
    containers.add(directoryView.getView());
}

From source file:com.peergreen.webconsole.scope.deployment.internal.deployable.DeployablePanel.java

License:Open Source License

@Link("maven")
public void addMavenView(DeployableContainer mavenView, Dictionary properties) {
    this.mavenView = mavenView;
    int position = (containers.size() >= 1) ? 1 : containers.size();
    tabSheet.addTab(mavenView.getView(), getDeployableCaption(properties),
            new ClassResource(getClass(), "/images/22x22/maven.png"), position);
    containers.add(mavenView.getView());
}