Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bundles/org.openhab.core.io.rest.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>org.openhab.core.persistence</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.sitemap</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.core.bundles</groupId>
<artifactId>org.openhab.core.config.discovery</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.List;

import org.openhab.core.sitemap.dto.SitemapDTO;
import org.openhab.core.thing.dto.ThingDTO;

import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -23,6 +24,7 @@
* in a file format (items, things, ...).
*
* @author Laurent Garnier - Initial contribution
* @author Mark Herwege - Add sitemaps
*/
@Schema(name = "FileFormat")
public class FileFormatDTO {
Expand All @@ -31,4 +33,6 @@ public class FileFormatDTO {
public List<FileFormatItemDTO> items;
@Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
public List<ThingDTO> things;
@Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
public List<SitemapDTO> sitemaps;
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@
*/
package org.openhab.core.io.rest.sitemap.internal;

import org.openhab.core.sitemap.dto.AbstractSitemapDTO;

import io.swagger.v3.oas.annotations.media.Schema;

/**
* This is a data transfer object that is used to serialize sitemaps.
*
*
* @author Kai Kreuzer - Initial contribution
* @author Chris Jackson - Initial contribution
* @author Mark Herwege - Moved to abstract class and extend
*/
@Schema(name = "Sitemap")
public class SitemapDTO {

public String name;
public String icon;
public String label;
public class SitemapDTO extends AbstractSitemapDTO {

public String link;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public class SitemapResource

private static final long TIMEOUT_IN_MS = 30000;

private final ScheduledExecutorService scheduler = ThreadPoolManager
.getScheduledPool(ThreadPoolManager.THREAD_POOL_NAME_COMMON);

private SseBroadcaster<SseSinkInfo> broadcaster;

@Context
Expand All @@ -192,9 +195,6 @@ public class SitemapResource

private final WeakValueConcurrentHashMap<String, SseSinkInfo> knownSubscriptions = new WeakValueConcurrentHashMap<>();

private final ScheduledExecutorService scheduler = ThreadPoolManager
.getScheduledPool(ThreadPoolManager.THREAD_POOL_NAME_COMMON);

private @Nullable ScheduledFuture<?> cleanSubscriptionsJob;
private Set<BlockingStateChangeListener> stateChangeListeners = new CopyOnWriteArraySet<>();

Expand Down Expand Up @@ -620,22 +620,22 @@ private PageDTO createPageBean(String sitemapName, @Nullable String title, @Null
}
}
if (widget instanceof Switch switchWidget) {
for (Mapping mapping : switchWidget.getMappings()) {
bean.mappings = switchWidget.getMappings().stream().map(mapping -> {
MappingDTO mappingBean = new MappingDTO();
mappingBean.command = mapping.getCmd();
mappingBean.releaseCommand = mapping.getReleaseCmd();
mappingBean.label = mapping.getLabel();
mappingBean.icon = mapping.getIcon();
bean.mappings.add(mappingBean);
}
return mappingBean;
}).toList();
}
if (widget instanceof Selection selectionWidget) {
for (Mapping mapping : selectionWidget.getMappings()) {
bean.mappings = selectionWidget.getMappings().stream().map(mapping -> {
MappingDTO mappingBean = new MappingDTO();
mappingBean.command = mapping.getCmd();
mappingBean.label = mapping.getLabel();
bean.mappings.add(mappingBean);
}
return mappingBean;
}).toList();
}
if (widget instanceof Input inputWidget) {
bean.inputHint = inputWidget.getInputHint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
*/
package org.openhab.core.io.rest.sitemap.internal;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.openhab.core.io.rest.core.item.EnrichedItemDTO;
import org.openhab.core.sitemap.dto.AbstractWidgetDTO;

import io.swagger.v3.oas.annotations.media.Schema;

Expand All @@ -31,56 +31,22 @@
* @author Danny Baumann - New field labelSource
* @author Laurent Garnier - Remove field columns
* @author Laurent Garnier - New fields row, column, command, releaseCommand and stateless for Button element
* @author Mark Herwege - Extends abstract widget DTO
*/
@Schema(name = "Widget")
public class WidgetDTO {
public class WidgetDTO extends AbstractWidgetDTO {

public String widgetId;
public String type;
public String name;
public boolean visibility;

public String label;
public String labelSource;
public String icon;
/**
* staticIcon is a boolean indicating if the widget state must be ignored when requesting the icon.
* It is set to true when the widget has either the staticIcon property set or the icon property set
* with conditional rules.
*/
public Boolean staticIcon;

public String labelcolor;
public String valuecolor;
public String iconcolor;

public String pattern;
public String unit;

// widget-specific attributes
public final List<MappingDTO> mappings = new ArrayList<>();
public Boolean switchSupport;
public Boolean releaseOnly;
public Integer refresh;
public Integer height;
public BigDecimal minValue;
public BigDecimal maxValue;
public BigDecimal step;
public String inputHint;
public String url;
public String encoding;
public String service;
public String period;
public String yAxisDecimalPattern;
public String interpolation;
public Boolean legend;
public Boolean forceAsItem;
public Integer row;
public Integer column;
public String command;
public String releaseCommand;
public Boolean stateless;
public String state;

public EnrichedItemDTO item;
public PageDTO linkedPage;

Expand Down
1 change: 1 addition & 0 deletions bundles/org.openhab.core.model.sitemap/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Import-Package: org.apache.log4j,\
org.openhab.core.items.dto,\
org.openhab.core.model.core,\
org.openhab.core.sitemap, \
org.openhab.core.sitemap.fileconverter, \
org.openhab.core.sitemap.registry, \
org.eclipse.xtext.xbase.lib,\
org.osgi.framework,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import org.eclipse.xtext.conversion.IValueConverterService
import org.eclipse.xtext.linking.lazy.LazyURIEncoder
import com.google.inject.Binder
import com.google.inject.name.Names
import org.eclipse.xtext.formatting.IIndentationInformation
import org.openhab.core.model.sitemap.formatting.SitemapIndentationInformation
import org.eclipse.xtext.formatting.IFormatter
import org.openhab.core.model.sitemap.formatting.SitemapFormatter

/**
* Use this class to register components to be used at runtime / without the Equinox extension registry.
Expand All @@ -30,6 +34,15 @@ class SitemapRuntimeModule extends org.openhab.core.model.sitemap.AbstractSitema
return SitemapConverters
}

override Class<? extends IFormatter> bindIFormatter() {
return SitemapFormatter
}

override void configure(Binder binder) {
super.configure(binder)
binder.bind(IIndentationInformation).to(SitemapIndentationInformation)
}

override void configureUseIndexFragmentsForLazyLinking(Binder binder) {
binder.bind(Boolean.TYPE).annotatedWith(Names.named(LazyURIEncoder.USE_INDEXED_FRAGMENTS_BINDING)).toInstance(
Boolean.FALSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ package org.openhab.core.model.sitemap
import org.eclipse.emf.ecore.EPackage
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.resource.IResourceServiceProvider
import com.google.inject.Injector

/**
* Initialization support for running Xtext languages
* without equinox extension registry
*/
class SitemapStandaloneSetup extends SitemapStandaloneSetupGenerated {
def static void doSetup() {
new SitemapStandaloneSetup().createInjectorAndDoEMFRegistration()
}

static Injector injector;

def static Injector doSetup() {
if (injector === null) {
injector = new SitemapStandaloneSetup().createInjectorAndDoEMFRegistration();
}
return injector;
}
def static void unregister() {
EPackage.Registry.INSTANCE.remove("https://openhab.org/model/Sitemap");
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().remove("sitemap");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ package org.openhab.core.model.sitemap.formatting

import org.eclipse.xtext.formatting.impl.AbstractDeclarativeFormatter
import org.eclipse.xtext.formatting.impl.FormattingConfig
import org.openhab.core.model.sitemap.services.SitemapGrammarAccess
import com.google.inject.Inject
import org.openhab.core.model.sitemap.sitemap.ModelWidget

// import com.google.inject.Inject;
// import org.openhab.core.model.services.SitemapGrammarAccess

Expand All @@ -30,13 +34,58 @@ import org.eclipse.xtext.formatting.impl.FormattingConfig
*/
class SitemapFormatter extends AbstractDeclarativeFormatter {

// @Inject extension SitemapGrammarAccess

override protected void configureFormatting(FormattingConfig c) {
// It's usually a good idea to activate the following three statements.
// They will add and preserve newlines around comments
// c.setLinewrap(0, 1, 2).before(SL_COMMENTRule)
// c.setLinewrap(0, 1, 2).before(ML_COMMENTRule)
// c.setLinewrap(0, 1, 1).after(ML_COMMENTRule)
}
@Inject extension SitemapGrammarAccess

override protected void configureFormatting(FormattingConfig c) {
c.wrappedLineIndentation = 4
c.autoLinewrap = 200

c.setLinewrap(1, 1, 2).before(modelWidgetRule)

c.setIndentationIncrement.after("{")
c.setLinewrap().before("}")
c.setIndentationDecrement.before("}")
c.setLinewrap().after("}")

c.setNoSpace().withinKeywordPairs("<", ">")
c.setNoSpace().withinKeywordPairs("(", ")")
c.setNoSpace().withinKeywordPairs("[", "]")

c.setNoSpace().after("item=", "label=", "icon=", "staticIcon=")
c.setNoSpace().after("url=", "refresh=", "encoding=", "service=", "period=", "legend=", "forceasitem=", "yAxisDecimalPattern=", "interpolation=", "height=")
c.setNoSpace().after("minValue=", "maxValue=", "step=", "inputHint=", "row=", "column=", "click=", "release=")
c.setNoSpace().after("labelcolor=", "valuecolor=", "iconcolor=", "visibility=", "mappings=", "buttons=")

c.setNoSpace().before(",")
c.setNoSpace().around(":", "=")

c.setLinewrap(0, 1, 2).before(SL_COMMENTRule)
c.setLinewrap(0, 1, 2).before(ML_COMMENTRule)
c.setLinewrap(0, 1, 1).after(ML_COMMENTRule)
}

def withinKeywordPairs(FormattingConfig.NoSpaceLocator locator, String leftKW, String rightKW) {
for (pair : findKeywordPairs(leftKW, rightKW)) {
locator.after(pair.first)
locator.before(pair.second)
}
}

def around(FormattingConfig.ElementLocator locator, String ... listKW) {
for (keyword : findKeywords(listKW)) {
locator.around(keyword)
}
}

def after(FormattingConfig.ElementLocator locator, String ... listKW) {
for (keyword : findKeywords(listKW)) {
locator.after(keyword)
}
}

def before(FormattingConfig.ElementLocator locator, String ... listKW) {
for (keyword : findKeywords(listKW)) {
locator.before(keyword)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2010-2026 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.core.model.sitemap.formatting;

import org.eclipse.xtext.formatting.IIndentationInformation;

public class SitemapIndentationInformation implements IIndentationInformation {
@Override
public String getIndentString() {
return " "; // 2 spaces
}
}
Loading
Loading