mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-02-03 09:57:35 +02:00
parent
6ce35733e7
commit
23509db79f
7
bundles/com.e1c.v8codestyle.autosort.ui/.classpath
Normal file
7
bundles/com.e1c.v8codestyle.autosort.ui/.classpath
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
28
bundles/com.e1c.v8codestyle.autosort.ui/.project
Normal file
28
bundles/com.e1c.v8codestyle.autosort.ui/.project
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.e1c.v8codestyle.autosort.ui</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=11
|
23
bundles/com.e1c.v8codestyle.autosort.ui/META-INF/MANIFEST.MF
Normal file
23
bundles/com.e1c.v8codestyle.autosort.ui/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,23 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %pluginName
|
||||
Bundle-SymbolicName: com.e1c.v8codestyle.autosort.ui;singleton:=true
|
||||
Bundle-Version: 0.1.0.qualifier
|
||||
Bundle-Activator: com.e1c.v8codestyle.internal.autosort.ui.UiPlugin
|
||||
Bundle-Vendor: %providerName
|
||||
Require-Bundle: org.eclipse.ui;bundle-version="[3.118.0,4.0.0)",
|
||||
org.eclipse.core.runtime;bundle-version="[3.20.0,4.0.0)",
|
||||
org.eclipse.core.resources;bundle-version="[3.13.0,4.0.0)",
|
||||
org.eclipse.ui.forms;bundle-version="[3.11.0,4.0.0)",
|
||||
org.eclipse.emf.ecore;bundle-version="[2.23.0,3.0.0)"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Automatic-Module-Name: com.e1c.v8codestyle.autosort.ui
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Localization: plugin
|
||||
Import-Package: com._1c.g5.v8.dt.common;version="[6.0.0,7.0.0)",
|
||||
com._1c.g5.v8.dt.metadata.mdclass;version="[8.0.0,9.0.0)",
|
||||
com._1c.g5.wiring;version="[2.2.0,3.0.0)",
|
||||
com._1c.g5.wiring.binder;version="[1.1.0,2.0.0)",
|
||||
com.e1c.v8codestyle.autosort;version="[0.1.0,0.2.0)",
|
||||
com.google.common.base;version="[27.0.0,28.0.0)",
|
||||
com.google.inject;version="[1.3.0,2.0.0)"
|
19
bundles/com.e1c.v8codestyle.autosort.ui/build.properties
Normal file
19
bundles/com.e1c.v8codestyle.autosort.ui/build.properties
Normal file
@ -0,0 +1,19 @@
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = plugin.xml,\
|
||||
META-INF/,\
|
||||
.,\
|
||||
plugin.properties,\
|
||||
plugin_ru.properties
|
20
bundles/com.e1c.v8codestyle.autosort.ui/plugin.properties
Normal file
20
bundles/com.e1c.v8codestyle.autosort.ui/plugin.properties
Normal file
@ -0,0 +1,20 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
#Properties file for com.e1c.v8codestyle.autosort
|
||||
|
||||
pluginName = 1C:Code style V8 Auto Sort UI plugin
|
||||
|
||||
providerName = 1C-Soft LLC
|
||||
|
||||
propertypage.autosort.name = Auto sort
|
34
bundles/com.e1c.v8codestyle.autosort.ui/plugin.xml
Normal file
34
bundles/com.e1c.v8codestyle.autosort.ui/plugin.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<!--
|
||||
Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
|
||||
This program and the accompanying materials are made
|
||||
available under the terms of the Eclipse Public License 2.0
|
||||
which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0
|
||||
|
||||
Contributors:
|
||||
1C-Soft LLC - initial API and implementation
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.propertyPages">
|
||||
<page
|
||||
name="%propertypage.autosort.name"
|
||||
category="com._1c.g5.v8.dt.ui.V8Property"
|
||||
class="com.e1c.v8codestyle.internal.autosort.ui.UiExecutableExtensionFactory:com.e1c.v8codestyle.autosort.ui.properties.AutoSortPropertyPage"
|
||||
selectionFilter="single"
|
||||
id="com.e1c.v8codestyle.autosort.ui.properties.PropertyPage">
|
||||
<enabledWhen>
|
||||
<instanceof
|
||||
value="org.eclipse.core.resources.IProject">
|
||||
</instanceof>
|
||||
</enabledWhen>
|
||||
</page>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
20
bundles/com.e1c.v8codestyle.autosort.ui/plugin_ru.properties
Normal file
20
bundles/com.e1c.v8codestyle.autosort.ui/plugin_ru.properties
Normal file
@ -0,0 +1,20 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
|
||||
pluginName = 1С:Стандарты разработки V8 плагин Авто сортировки UI
|
||||
|
||||
propertypage.autosort.name = Авто сортировка
|
||||
|
||||
providerName = ООО "1С-Софт"
|
27
bundles/com.e1c.v8codestyle.autosort.ui/pom.xml
Normal file
27
bundles/com.e1c.v8codestyle.autosort.ui/pom.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
|
||||
This program and the accompanying materials are made
|
||||
available under the terms of the Eclipse Public License 2.0
|
||||
which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0
|
||||
|
||||
Contributors:
|
||||
1C-Soft LLC - initial API and implementation
|
||||
-->
|
||||
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.e1c.v8codestyle</groupId>
|
||||
<artifactId>bundles</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>com.e1c.v8codestyle.autosort.ui</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
</project>
|
@ -0,0 +1,501 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.autosort.ui.properties;
|
||||
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.SUBSYSTEM__SUBSYSTEMS;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.emf.ecore.EReference;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.layout.GridLayoutFactory;
|
||||
import org.eclipse.jface.preference.PreferencePage;
|
||||
import org.eclipse.jface.viewers.ArrayContentProvider;
|
||||
import org.eclipse.jface.viewers.BaseLabelProvider;
|
||||
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
||||
import org.eclipse.jface.viewers.ICheckStateProvider;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.layout.RowLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.ui.dialogs.PropertyPage;
|
||||
import org.eclipse.ui.forms.events.ExpansionAdapter;
|
||||
import org.eclipse.ui.forms.events.ExpansionEvent;
|
||||
import org.eclipse.ui.forms.widgets.ExpandableComposite;
|
||||
import org.eclipse.ui.forms.widgets.FormToolkit;
|
||||
import org.eclipse.ui.forms.widgets.Section;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
import org.osgi.service.prefs.Preferences;
|
||||
|
||||
import com._1c.g5.v8.dt.common.Functions;
|
||||
import com.e1c.v8codestyle.autosort.AutoSortPreferences;
|
||||
import com.e1c.v8codestyle.autosort.ISortService;
|
||||
import com.e1c.v8codestyle.autosort.ListConstants;
|
||||
import com.e1c.v8codestyle.internal.autosort.ui.UiPlugin;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class AutoSortPropertyPage
|
||||
extends PropertyPage
|
||||
{
|
||||
|
||||
private final ISortService sortService;
|
||||
|
||||
private FormToolkit toolkit;
|
||||
|
||||
private IEclipsePreferences prefs;
|
||||
|
||||
private Map<String, Button> buttons = new HashMap<>();
|
||||
|
||||
private Map<String, Boolean> topObjects = new HashMap<>();
|
||||
|
||||
private Button ascendingButton;
|
||||
|
||||
@Inject
|
||||
public AutoSortPropertyPage(ISortService sortService)
|
||||
{
|
||||
super();
|
||||
this.sortService = sortService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PreferencePage#createContents(Composite)
|
||||
*/
|
||||
@Override
|
||||
protected Control createContents(Composite parent)
|
||||
{
|
||||
|
||||
toolkit = new FormToolkit(parent.getDisplay());
|
||||
|
||||
prefs = AutoSortPreferences.getPreferences(getProject());
|
||||
|
||||
Composite composite = new Composite(parent, SWT.NONE);
|
||||
GridLayout layout = new GridLayout();
|
||||
composite.setLayout(layout);
|
||||
GridData data = new GridData(GridData.FILL);
|
||||
data.grabExcessHorizontalSpace = true;
|
||||
composite.setLayoutData(data);
|
||||
|
||||
addSortSection(composite);
|
||||
addSeparator(composite);
|
||||
addTopObjectsSection(composite);
|
||||
addSubordinateSection(composite);
|
||||
this.setMessage(Messages.AutoSortPropertyPage_Automatically_sort_medata_objects_on_edit);
|
||||
return composite;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose()
|
||||
{
|
||||
toolkit.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void performDefaults()
|
||||
{
|
||||
super.performDefaults();
|
||||
ascendingButton.setSelection(AutoSortPreferences.DEFAULT_SORT_ASCENDING);
|
||||
buttons.get(AutoSortPreferences.KEY_ALL_TOP).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_SUBORDINATE_OBJECTS).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_FORMS).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_TEMPLATES).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_COMMANDS).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_OPERATIONS).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_URL_TEMPLATES).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_METHODS).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_ATTRIBUTES).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_REGISTRY_RESOURCES).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
buttons.get(AutoSortPreferences.KEY_TABULAR_SECTIONS).setSelection(AutoSortPreferences.DEFAULT_SORT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performOk()
|
||||
{
|
||||
boolean needToSort = needToSort();
|
||||
|
||||
boolean ascending = ascendingButton.getSelection();
|
||||
if (ascending == AutoSortPreferences.DEFAULT_SORT_ASCENDING)
|
||||
{
|
||||
prefs.remove(AutoSortPreferences.KEY_ASCENDING);
|
||||
}
|
||||
else
|
||||
{
|
||||
prefs.putBoolean(AutoSortPreferences.KEY_ASCENDING, ascending);
|
||||
}
|
||||
|
||||
updateSortPreferences(prefs, AutoSortPreferences.KEY_ALL_TOP,
|
||||
buttons.get(AutoSortPreferences.KEY_ALL_TOP).getSelection());
|
||||
if (!buttons.get(AutoSortPreferences.KEY_ALL_TOP).getSelection())
|
||||
{
|
||||
Preferences node = prefs.node(AutoSortPreferences.KEY_TOP_NODE);
|
||||
for (Entry<String, Boolean> entry : topObjects.entrySet())
|
||||
{
|
||||
updateSortPreferences(node, entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
updateSortPreferences(prefs, AutoSortPreferences.KEY_SUBORDINATE_OBJECTS,
|
||||
buttons.get(AutoSortPreferences.KEY_SUBORDINATE_OBJECTS).getSelection());
|
||||
if (!buttons.get(AutoSortPreferences.KEY_SUBORDINATE_OBJECTS).getSelection())
|
||||
{
|
||||
Preferences node = prefs.node(AutoSortPreferences.KEY_SUBORDINATE_NODE);
|
||||
updateSortPreferences(node, AutoSortPreferences.KEY_FORMS,
|
||||
buttons.get(AutoSortPreferences.KEY_FORMS).getSelection());
|
||||
updateSortPreferences(node, AutoSortPreferences.KEY_TEMPLATES,
|
||||
buttons.get(AutoSortPreferences.KEY_TEMPLATES).getSelection());
|
||||
updateSortPreferences(node, AutoSortPreferences.KEY_COMMANDS,
|
||||
buttons.get(AutoSortPreferences.KEY_COMMANDS).getSelection());
|
||||
updateSortPreferences(node, AutoSortPreferences.KEY_OPERATIONS,
|
||||
buttons.get(AutoSortPreferences.KEY_OPERATIONS).getSelection());
|
||||
updateSortPreferences(node, AutoSortPreferences.KEY_URL_TEMPLATES,
|
||||
buttons.get(AutoSortPreferences.KEY_URL_TEMPLATES).getSelection());
|
||||
updateSortPreferences(node, AutoSortPreferences.KEY_METHODS,
|
||||
buttons.get(AutoSortPreferences.KEY_METHODS).getSelection());
|
||||
updateSortPreferences(node, AutoSortPreferences.KEY_ATTRIBUTES,
|
||||
buttons.get(AutoSortPreferences.KEY_ATTRIBUTES).getSelection());
|
||||
updateSortPreferences(node, AutoSortPreferences.KEY_REGISTRY_RESOURCES,
|
||||
buttons.get(AutoSortPreferences.KEY_REGISTRY_RESOURCES).getSelection());
|
||||
updateSortPreferences(node, AutoSortPreferences.KEY_TABULAR_SECTIONS,
|
||||
buttons.get(AutoSortPreferences.KEY_TABULAR_SECTIONS).getSelection());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (buttons.get(AutoSortPreferences.KEY_ALL_TOP).getSelection())
|
||||
{
|
||||
prefs.remove(AutoSortPreferences.KEY_TOP_NODE);
|
||||
if (prefs.nodeExists(AutoSortPreferences.KEY_TOP_NODE))
|
||||
prefs.node(AutoSortPreferences.KEY_TOP_NODE).removeNode();
|
||||
}
|
||||
if (buttons.get(AutoSortPreferences.KEY_SUBORDINATE_OBJECTS).getSelection())
|
||||
{
|
||||
prefs.remove(AutoSortPreferences.KEY_SUBORDINATE_NODE);
|
||||
if (prefs.nodeExists(AutoSortPreferences.KEY_SUBORDINATE_NODE))
|
||||
prefs.node(AutoSortPreferences.KEY_SUBORDINATE_NODE).removeNode();
|
||||
}
|
||||
prefs.flush();
|
||||
}
|
||||
catch (BackingStoreException e)
|
||||
{
|
||||
UiPlugin.logError(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (needToSort && MessageDialog.openQuestion(getShell(), Messages.AutoSortPropertyPage_Sort_question_title,
|
||||
Messages.AutoSortPropertyPage_Sort_question))
|
||||
{
|
||||
sortService.startSortAllMetadata(getProject());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean needToSort()
|
||||
{
|
||||
if (ascendingButton.getSelection() != prefs.getBoolean(AutoSortPreferences.KEY_ASCENDING,
|
||||
AutoSortPreferences.DEFAULT_SORT_ASCENDING)
|
||||
|| !prefs.getBoolean(AutoSortPreferences.KEY_ALL_TOP, AutoSortPreferences.DEFAULT_SORT)
|
||||
&& buttons.get(AutoSortPreferences.KEY_ALL_TOP).getSelection()
|
||||
|| !prefs.getBoolean(AutoSortPreferences.KEY_SUBORDINATE_OBJECTS, AutoSortPreferences.DEFAULT_SORT)
|
||||
&& buttons.get(AutoSortPreferences.KEY_SUBORDINATE_OBJECTS).getSelection())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private IProject getProject()
|
||||
{
|
||||
return (IProject)getElement();
|
||||
}
|
||||
|
||||
private void updateSortPreferences(Preferences node, String key, boolean value)
|
||||
{
|
||||
if (value == AutoSortPreferences.DEFAULT_SORT)
|
||||
{
|
||||
node.remove(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
node.putBoolean(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private Composite createDefaultComposite(Composite parent)
|
||||
{
|
||||
Composite composite = toolkit.createComposite(parent);
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 2;
|
||||
composite.setLayout(layout);
|
||||
|
||||
GridData data = new GridData();
|
||||
data.verticalAlignment = GridData.FILL;
|
||||
data.horizontalAlignment = GridData.FILL;
|
||||
composite.setLayoutData(data);
|
||||
|
||||
return composite;
|
||||
}
|
||||
|
||||
private Button createCheckbox(Composite parent, String label, String key, boolean isCheck)
|
||||
{
|
||||
final Button but = new Button(parent, SWT.CHECK);
|
||||
but.setData(key);
|
||||
but.setSelection(isCheck);
|
||||
but.pack();
|
||||
buttons.put(key, but);
|
||||
Label buttonLabel = new Label(parent, SWT.NONE);
|
||||
buttonLabel.setText(label);
|
||||
buttonLabel.addMouseListener(new MouseAdapter()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void mouseUp(MouseEvent e)
|
||||
{
|
||||
but.setSelection(!but.getSelection());
|
||||
}
|
||||
});
|
||||
buttonLabel.pack();
|
||||
return but;
|
||||
}
|
||||
|
||||
private void addSortSection(Composite parent)
|
||||
{
|
||||
Group sortGroup = new Group(parent, SWT.NONE);
|
||||
sortGroup.setLayout(new RowLayout(SWT.HORIZONTAL));
|
||||
toolkit.createLabel(sortGroup, Messages.AutoSortPropertyPage_Sort_direction);
|
||||
ascendingButton = toolkit.createButton(sortGroup, Messages.AutoSortPropertyPage_Ascending, SWT.RADIO);
|
||||
final Button descendingButton =
|
||||
toolkit.createButton(sortGroup, Messages.AutoSortPropertyPage_Descending, SWT.RADIO);
|
||||
descendingButton.setSelection(true);
|
||||
boolean ascending =
|
||||
prefs.getBoolean(AutoSortPreferences.KEY_ASCENDING, AutoSortPreferences.DEFAULT_SORT_ASCENDING);
|
||||
ascendingButton.setSelection(ascending);
|
||||
descendingButton.setSelection(!ascending);
|
||||
}
|
||||
|
||||
private void addSeparator(Composite parent)
|
||||
{
|
||||
Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
|
||||
GridData gridData = new GridData();
|
||||
gridData.horizontalAlignment = GridData.FILL;
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
separator.setLayoutData(gridData);
|
||||
}
|
||||
|
||||
private void addTopObjectsSection(Composite parent)
|
||||
{
|
||||
Composite composite = createDefaultComposite(parent);
|
||||
|
||||
final boolean check = prefs.getBoolean(AutoSortPreferences.KEY_ALL_TOP, AutoSortPreferences.DEFAULT_SORT);
|
||||
Button topCheckbox = createCheckbox(composite, Messages.AutoSortPropertyPage_All_top_metadata_objects,
|
||||
AutoSortPreferences.KEY_ALL_TOP, check);
|
||||
|
||||
Section section = toolkit.createSection(parent,
|
||||
Section.DESCRIPTION | ExpandableComposite.SHORT_TITLE_BAR | ExpandableComposite.TWISTIE
|
||||
| ExpandableComposite.CLIENT_INDENT | ExpandableComposite.TREE_NODE | ExpandableComposite.COMPACT);
|
||||
|
||||
section.setText(Messages.AutoSortPropertyPage_Select_top_objects);
|
||||
section.setDescription(Messages.AutoSortPropertyPage_Select_top_objects_description);
|
||||
final GridData collapsed = new GridData(SWT.FILL, SWT.FILL, true, false);
|
||||
final GridData expanded = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
section.setLayoutData(collapsed);
|
||||
Composite content = toolkit.createComposite(section);
|
||||
GridLayoutFactory.fillDefaults().applyTo(content);
|
||||
section.setClient(content);
|
||||
|
||||
CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList(content,
|
||||
SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
|
||||
section.addExpansionListener(new ExpansionAdapter()
|
||||
{
|
||||
@Override
|
||||
public void expansionStateChanged(ExpansionEvent e)
|
||||
{
|
||||
if (e.getState())
|
||||
{
|
||||
section.setLayoutData(expanded);
|
||||
}
|
||||
else
|
||||
{
|
||||
section.setLayoutData(collapsed);
|
||||
}
|
||||
}
|
||||
});
|
||||
Table table = viewer.getTable();
|
||||
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
viewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
viewer.setLabelProvider(new FeatureLabelProvider());
|
||||
viewer.setCheckStateProvider(new TopCheckStateProvider());
|
||||
viewer.addCheckStateListener(event -> {
|
||||
if (event.getElement() instanceof EReference)
|
||||
{
|
||||
topObjects.put(((EReference)event.getElement()).getName(), event.getChecked());
|
||||
}
|
||||
});
|
||||
topCheckbox.addSelectionListener(new SelectionAdapter()
|
||||
{
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e)
|
||||
{
|
||||
boolean check = topCheckbox.getSelection();
|
||||
for (Entry<String, Boolean> entry : topObjects.entrySet())
|
||||
{
|
||||
entry.setValue(check);
|
||||
}
|
||||
viewer.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
Preferences node = prefs.node(AutoSortPreferences.KEY_TOP_NODE);
|
||||
ListConstants.TOP_OPBJECT_LISTS.forEach(
|
||||
e -> topObjects.put(e.getName(), node.getBoolean(e.getName(), check || AutoSortPreferences.DEFAULT_SORT)));
|
||||
viewer.setInput(ListConstants.TOP_OPBJECT_LISTS.stream()
|
||||
.filter(e -> !e.equals(SUBSYSTEM__SUBSYSTEMS))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
}
|
||||
|
||||
private void addSubordinateSection(Composite parent)
|
||||
{
|
||||
Composite composite = createDefaultComposite(parent);
|
||||
|
||||
final boolean check =
|
||||
prefs.getBoolean(AutoSortPreferences.KEY_SUBORDINATE_OBJECTS, AutoSortPreferences.DEFAULT_SORT);
|
||||
final Button subordinateCheckbox = createCheckbox(composite,
|
||||
Messages.AutoSortPropertyPage_All_subordinate_objects, AutoSortPreferences.KEY_SUBORDINATE_OBJECTS, check);
|
||||
|
||||
Section section = toolkit.createSection(parent,
|
||||
Section.DESCRIPTION | ExpandableComposite.SHORT_TITLE_BAR | ExpandableComposite.TWISTIE
|
||||
| ExpandableComposite.CLIENT_INDENT | ExpandableComposite.TREE_NODE | ExpandableComposite.COMPACT);
|
||||
|
||||
section.setText(Messages.AutoSortPropertyPage_Select_subordinate_objects);
|
||||
section.setDescription(Messages.AutoSortPropertyPage_Select_subordinate_objects_description);
|
||||
Composite subContent = createDefaultComposite(section);
|
||||
section.setClient(subContent);
|
||||
|
||||
Preferences node = prefs.node(AutoSortPreferences.KEY_SUBORDINATE_NODE);
|
||||
|
||||
createCheckbox(subContent, Messages.AutoSortPropertyPage_Forms_of_object, AutoSortPreferences.KEY_FORMS,
|
||||
node.getBoolean(AutoSortPreferences.KEY_FORMS, check || AutoSortPreferences.DEFAULT_SORT));
|
||||
|
||||
createCheckbox(subContent, Messages.AutoSortPropertyPage_Templates_of_object, AutoSortPreferences.KEY_TEMPLATES,
|
||||
node.getBoolean(AutoSortPreferences.KEY_TEMPLATES, check || AutoSortPreferences.DEFAULT_SORT));
|
||||
|
||||
createCheckbox(subContent, Messages.AutoSortPropertyPage_Commands_of_object, AutoSortPreferences.KEY_COMMANDS,
|
||||
node.getBoolean(AutoSortPreferences.KEY_COMMANDS, check || AutoSortPreferences.DEFAULT_SORT));
|
||||
|
||||
createCheckbox(subContent, Messages.AutoSortPropertyPage_Operations_of_Web_service,
|
||||
AutoSortPreferences.KEY_OPERATIONS,
|
||||
node.getBoolean(AutoSortPreferences.KEY_OPERATIONS, check || AutoSortPreferences.DEFAULT_SORT));
|
||||
|
||||
createCheckbox(subContent, Messages.AutoSortPropertyPage_URL_templates_of_HTTP_service,
|
||||
AutoSortPreferences.KEY_URL_TEMPLATES,
|
||||
node.getBoolean(AutoSortPreferences.KEY_URL_TEMPLATES, check || AutoSortPreferences.DEFAULT_SORT));
|
||||
|
||||
createCheckbox(subContent, Messages.AutoSortPropertyPage_Methods_of_URL_template,
|
||||
AutoSortPreferences.KEY_METHODS,
|
||||
node.getBoolean(AutoSortPreferences.KEY_METHODS, check || AutoSortPreferences.DEFAULT_SORT));
|
||||
|
||||
createCheckbox(subContent, Messages.AutoSortPropertyPage_Attributes_of_object,
|
||||
AutoSortPreferences.KEY_ATTRIBUTES,
|
||||
node.getBoolean(AutoSortPreferences.KEY_ATTRIBUTES, check || AutoSortPreferences.DEFAULT_SORT));
|
||||
|
||||
createCheckbox(subContent, Messages.AutoSortPropertyPage_Tabular_sections_of_object,
|
||||
AutoSortPreferences.KEY_TABULAR_SECTIONS,
|
||||
node.getBoolean(AutoSortPreferences.KEY_TABULAR_SECTIONS, check || AutoSortPreferences.DEFAULT_SORT));
|
||||
|
||||
createCheckbox(subContent, Messages.AutoSortPropertyPage_Resources_of_registry,
|
||||
AutoSortPreferences.KEY_REGISTRY_RESOURCES,
|
||||
node.getBoolean(AutoSortPreferences.KEY_REGISTRY_RESOURCES, check || AutoSortPreferences.DEFAULT_SORT));
|
||||
|
||||
subordinateCheckbox.addSelectionListener(new SelectionAdapter()
|
||||
{
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e)
|
||||
{
|
||||
boolean check = subordinateCheckbox.getSelection();
|
||||
buttons.get(AutoSortPreferences.KEY_FORMS).setSelection(check);
|
||||
buttons.get(AutoSortPreferences.KEY_TEMPLATES).setSelection(check);
|
||||
buttons.get(AutoSortPreferences.KEY_COMMANDS).setSelection(check);
|
||||
buttons.get(AutoSortPreferences.KEY_OPERATIONS).setSelection(check);
|
||||
buttons.get(AutoSortPreferences.KEY_URL_TEMPLATES).setSelection(check);
|
||||
buttons.get(AutoSortPreferences.KEY_METHODS).setSelection(check);
|
||||
buttons.get(AutoSortPreferences.KEY_ATTRIBUTES).setSelection(check);
|
||||
buttons.get(AutoSortPreferences.KEY_REGISTRY_RESOURCES).setSelection(check);
|
||||
buttons.get(AutoSortPreferences.KEY_TABULAR_SECTIONS).setSelection(check);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static final class FeatureLabelProvider
|
||||
extends BaseLabelProvider
|
||||
implements ILabelProvider
|
||||
{
|
||||
|
||||
@Override
|
||||
public Image getImage(Object element)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Object element)
|
||||
{
|
||||
if (element instanceof EReference)
|
||||
{
|
||||
String label = Functions.featureToLabel().apply((EReference)element);
|
||||
if (label == null)
|
||||
{
|
||||
label = ((EReference)element).getName();
|
||||
}
|
||||
return label;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final class TopCheckStateProvider
|
||||
implements ICheckStateProvider
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean isChecked(Object element)
|
||||
{
|
||||
if (element instanceof EReference)
|
||||
return AutoSortPropertyPage.this.topObjects.getOrDefault(((EReference)element).getName(), false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGrayed(Object element)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.autosort.ui.properties;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* @author Dmitriy Marmyshev
|
||||
*
|
||||
*/
|
||||
final class Messages
|
||||
extends NLS
|
||||
{
|
||||
private static final String BUNDLE_NAME = "com.e1c.v8codestyle.autosort.ui.properties.messages"; //$NON-NLS-1$
|
||||
public static String AutoSortPropertyPage_All_subordinate_objects;
|
||||
public static String AutoSortPropertyPage_All_top_metadata_objects;
|
||||
public static String AutoSortPropertyPage_Ascending;
|
||||
public static String AutoSortPropertyPage_Attributes_of_object;
|
||||
public static String AutoSortPropertyPage_Automatically_sort_medata_objects_on_edit;
|
||||
public static String AutoSortPropertyPage_Commands_of_object;
|
||||
public static String AutoSortPropertyPage_Descending;
|
||||
public static String AutoSortPropertyPage_Forms_of_object;
|
||||
public static String AutoSortPropertyPage_Methods_of_URL_template;
|
||||
public static String AutoSortPropertyPage_Operations_of_Web_service;
|
||||
public static String AutoSortPropertyPage_Resources_of_registry;
|
||||
public static String AutoSortPropertyPage_Select_subordinate_objects;
|
||||
public static String AutoSortPropertyPage_Select_subordinate_objects_description;
|
||||
public static String AutoSortPropertyPage_Select_top_objects;
|
||||
public static String AutoSortPropertyPage_Select_top_objects_description;
|
||||
public static String AutoSortPropertyPage_Sort_direction;
|
||||
public static String AutoSortPropertyPage_Sort_question;
|
||||
public static String AutoSortPropertyPage_Sort_question_title;
|
||||
public static String AutoSortPropertyPage_Tabular_sections_of_object;
|
||||
public static String AutoSortPropertyPage_Templates_of_object;
|
||||
public static String AutoSortPropertyPage_URL_templates_of_HTTP_service;
|
||||
static
|
||||
{
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages()
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
AutoSortPropertyPage_All_subordinate_objects=All subordinate objects
|
||||
AutoSortPropertyPage_All_top_metadata_objects=All top metadata objects
|
||||
AutoSortPropertyPage_Ascending=Ascending
|
||||
AutoSortPropertyPage_Attributes_of_object=Attributes of object
|
||||
AutoSortPropertyPage_Automatically_sort_medata_objects_on_edit=Automatically sort medata objects on edit
|
||||
AutoSortPropertyPage_Commands_of_object=Commands of object
|
||||
AutoSortPropertyPage_Descending=Descending
|
||||
AutoSortPropertyPage_Forms_of_object=Forms of object
|
||||
AutoSortPropertyPage_Methods_of_URL_template=Methods of URL template
|
||||
AutoSortPropertyPage_Operations_of_Web_service=Operations of Web-service
|
||||
AutoSortPropertyPage_Resources_of_registry=Resources of registry
|
||||
AutoSortPropertyPage_Select_subordinate_objects=Select subordinate objects
|
||||
AutoSortPropertyPage_Select_subordinate_objects_description=Select subordinate Metadata objects to sort them automatically on edit. Registry dimensions should not sort automatically.
|
||||
AutoSortPropertyPage_Select_top_objects=Select top objects
|
||||
AutoSortPropertyPage_Select_top_objects_description=Select top Metadata objects to sort them automatically on edit. Common attributes and command groups should not sort automacitally on edit.
|
||||
AutoSortPropertyPage_Sort_direction=Sort direction:
|
||||
AutoSortPropertyPage_Sort_question=Sort settings has changed. Sort all objects?
|
||||
AutoSortPropertyPage_Sort_question_title=Settings has changed
|
||||
AutoSortPropertyPage_Tabular_sections_of_object=Tabular sections of object
|
||||
AutoSortPropertyPage_Templates_of_object=Templates of object
|
||||
AutoSortPropertyPage_URL_templates_of_HTTP_service=URL templates of HTTP service
|
@ -0,0 +1,56 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
|
||||
AutoSortPropertyPage_All_subordinate_objects = Все подчиненные объекты
|
||||
|
||||
AutoSortPropertyPage_All_top_metadata_objects = Все верхнеуровневые объекты метаданных
|
||||
|
||||
AutoSortPropertyPage_Ascending = По возрастанию
|
||||
|
||||
AutoSortPropertyPage_Attributes_of_object = Реквизиты объекта
|
||||
|
||||
AutoSortPropertyPage_Automatically_sort_medata_objects_on_edit = Автоматическая сортировка объектов метаданных при редактировании
|
||||
|
||||
AutoSortPropertyPage_Commands_of_object = Комманды объекта
|
||||
|
||||
AutoSortPropertyPage_Descending = По убыванию
|
||||
|
||||
AutoSortPropertyPage_Forms_of_object = Формы объекта
|
||||
|
||||
AutoSortPropertyPage_Methods_of_URL_template = Методы шаблона URL
|
||||
|
||||
AutoSortPropertyPage_Operations_of_Web_service = Операции Web-сервиса
|
||||
|
||||
AutoSortPropertyPage_Resources_of_registry = Ресурсы регистра
|
||||
|
||||
AutoSortPropertyPage_Select_subordinate_objects = Выберите подчиненные объекты
|
||||
|
||||
AutoSortPropertyPage_Select_subordinate_objects_description = Выберите подчиненные объекты метаданны для их автоматической сортивки при редактировании. Измерения регистра не должны сортироваться автоматически.
|
||||
|
||||
AutoSortPropertyPage_Select_top_objects = Выберите верхнеуровневые объекты
|
||||
|
||||
AutoSortPropertyPage_Select_top_objects_description = Выберите верхнеуровневые объекты метаданных для их автоматической сортировки при редактировании. Общие реквизиты и Группы команд не должны сортироваться автоматически.
|
||||
|
||||
AutoSortPropertyPage_Sort_direction = Направление сортировки:
|
||||
|
||||
AutoSortPropertyPage_Sort_question = Настройки сортировки изменились. Сортировать все объекты?
|
||||
|
||||
AutoSortPropertyPage_Sort_question_title = Настройки изменились
|
||||
|
||||
AutoSortPropertyPage_Tabular_sections_of_object = Табличные секции объекта
|
||||
|
||||
AutoSortPropertyPage_Templates_of_object = Макеты объекта
|
||||
|
||||
AutoSortPropertyPage_URL_templates_of_HTTP_service = Шаблоны URL HTTP-сервиса
|
@ -0,0 +1,40 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.autosort.ui;
|
||||
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
|
||||
import com._1c.g5.wiring.AbstractServiceAwareModule;
|
||||
import com.e1c.v8codestyle.autosort.ISortService;
|
||||
|
||||
/**
|
||||
* The external dependencies for AutoSort UI plugin
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
class ExternalDependenciesModule
|
||||
extends AbstractServiceAwareModule
|
||||
{
|
||||
|
||||
ExternalDependenciesModule(Plugin plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doConfigure()
|
||||
{
|
||||
bind(ISortService.class).toService();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.autosort.ui;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import com._1c.g5.wiring.AbstractGuiceAwareExecutableExtensionFactory;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Guice module aware executable extension factory for AutoSort UI plugin.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public class UiExecutableExtensionFactory
|
||||
extends AbstractGuiceAwareExecutableExtensionFactory
|
||||
{
|
||||
@Override
|
||||
protected Bundle getBundle()
|
||||
{
|
||||
return UiPlugin.getDefault().getBundle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Injector getInjector()
|
||||
{
|
||||
return UiPlugin.getDefault().getInjector();
|
||||
}
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.autosort.ui;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class UiPlugin
|
||||
extends AbstractUIPlugin
|
||||
{
|
||||
|
||||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "com.e1c.v8codestyle.autosort.ui"; //$NON-NLS-1$
|
||||
|
||||
// The shared instance
|
||||
private static UiPlugin plugin;
|
||||
|
||||
private volatile Injector injector;
|
||||
|
||||
/**
|
||||
* Writes a status to the plugin log.
|
||||
*
|
||||
* @param status status to log, cannot be <code>null</code>
|
||||
*/
|
||||
public static void log(IStatus status)
|
||||
{
|
||||
plugin.getLog().log(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a throwable to the plugin log as error status.
|
||||
*
|
||||
* @param throwable throwable, cannot be <code>null</code>
|
||||
*/
|
||||
public static void logError(Throwable throwable)
|
||||
{
|
||||
log(createErrorStatus(throwable.getMessage(), throwable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates error status by a given message and cause throwable.
|
||||
*
|
||||
* @param message status message, cannot be <code>null</code>
|
||||
* @param throwable throwable, can be <code>null</code> if not applicable
|
||||
* @return status created error status, never <code>null</code>
|
||||
*/
|
||||
public static IStatus createErrorStatus(String message, Throwable throwable)
|
||||
{
|
||||
return new Status(IStatus.ERROR, PLUGIN_ID, 0, message, throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates warning status by a given message.
|
||||
*
|
||||
* @param message status message, cannot be <code>null</code>
|
||||
* @return status created warning status, never <code>null</code>
|
||||
*/
|
||||
public static IStatus createWarningStatus(String message)
|
||||
{
|
||||
return new Status(IStatus.WARNING, PLUGIN_ID, 0, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates warning status by a given message and cause throwable.
|
||||
*
|
||||
* @param message status message, cannot be <code>null</code>
|
||||
* @param throwable throwable, can be <code>null</code> if not applicable
|
||||
* @return status created warning status, never <code>null</code>
|
||||
*/
|
||||
public static IStatus createWarningStatus(final String message, Exception throwable)
|
||||
{
|
||||
return new Status(IStatus.WARNING, PLUGIN_ID, 0, message, throwable);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception
|
||||
{
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception
|
||||
{
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
* @return the shared instance
|
||||
*/
|
||||
public static UiPlugin getDefault()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image descriptor for the image file at the given
|
||||
* plug-in relative path
|
||||
*
|
||||
* @param path the path
|
||||
* @return the image descriptor
|
||||
*/
|
||||
public static ImageDescriptor getImageDescriptor(String path)
|
||||
{
|
||||
return imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Guice injector of the plugin
|
||||
*
|
||||
* @return Guice injector of the plugin, never <code>null</code> if plugin is started
|
||||
*/
|
||||
/* package */ Injector getInjector()
|
||||
{
|
||||
Injector localInstance = injector;
|
||||
if (localInstance == null)
|
||||
{
|
||||
synchronized (UiPlugin.class)
|
||||
{
|
||||
localInstance = injector;
|
||||
if (localInstance == null)
|
||||
{
|
||||
localInstance = createInjector();
|
||||
injector = localInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return localInstance;
|
||||
}
|
||||
|
||||
private Injector createInjector()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Guice.createInjector(new ExternalDependenciesModule(this));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log(createErrorStatus("Failed to create injector for " //$NON-NLS-1$
|
||||
+ getBundle().getSymbolicName(), e));
|
||||
throw new RuntimeException("Failed to create injector for " //$NON-NLS-1$
|
||||
+ getBundle().getSymbolicName(), e);
|
||||
}
|
||||
}
|
||||
}
|
7
bundles/com.e1c.v8codestyle.autosort/.classpath
Normal file
7
bundles/com.e1c.v8codestyle.autosort/.classpath
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
28
bundles/com.e1c.v8codestyle.autosort/.project
Normal file
28
bundles/com.e1c.v8codestyle.autosort/.project
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.e1c.v8codestyle.autosort</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
@ -0,0 +1,7 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=11
|
38
bundles/com.e1c.v8codestyle.autosort/META-INF/MANIFEST.MF
Normal file
38
bundles/com.e1c.v8codestyle.autosort/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,38 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %pluginName
|
||||
Bundle-SymbolicName: com.e1c.v8codestyle.autosort;singleton:=true
|
||||
Bundle-Version: 0.1.0.qualifier
|
||||
Bundle-Activator: com.e1c.v8codestyle.internal.autosort.AutoSortPlugin
|
||||
Bundle-Vendor: %providerName
|
||||
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.13.0,4.0.0)",
|
||||
org.eclipse.emf.ecore;bundle-version="[2.12.0,3.0.0)",
|
||||
org.eclipse.core.resources;bundle-version="[3.12.0,4.0.0)",
|
||||
com._1c.g5.wiring;bundle-version="[2.0.0,3.0.0)",
|
||||
org.eclipse.emf.edit;bundle-version="[2.12.0,3.0.0)"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Automatic-Module-Name: com.e1c.v8codestyle.autosort
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-Localization: plugin
|
||||
Import-Package: com._1c.g5.v8.bm.common.collections;version="[3.0.0,4.0.0)",
|
||||
com._1c.g5.v8.bm.core;version="[7.0.0,8.0.0)",
|
||||
com._1c.g5.v8.bm.core.event;version="[2.0.0,3.0.0)",
|
||||
com._1c.g5.v8.bm.integration;version="[9.0.0,10.0.0)",
|
||||
com._1c.g5.v8.bm.integration.event;version="[1.0.0,2.0.0)",
|
||||
com._1c.g5.v8.dt.core.bm.launch;version="[3.0.0,4.0.0)",
|
||||
com._1c.g5.v8.dt.core.lifecycle;version="6.0.0",
|
||||
com._1c.g5.v8.dt.core.operations;version="[4.0.0,5.0.0)",
|
||||
com._1c.g5.v8.dt.core.platform;version="[10.0.0,11.0.0)",
|
||||
com._1c.g5.v8.dt.lifecycle;version="[3.0.0,4.0.0)",
|
||||
com._1c.g5.v8.dt.metadata.mdclass;version="[8.0.0,9.0.0)",
|
||||
com.google.common.base;version="[27.1.0,28.0.0)",
|
||||
com.google.inject;version="[1.3.0,2.0.0)",
|
||||
com.google.inject.binder;version="[1.3.0,2.0.0)"
|
||||
Export-Package: com.e1c.v8codestyle.autosort;version="0.1.0";
|
||||
uses:="org.eclipse.emf.ecore,
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.emf.common.util,
|
||||
org.eclipse.core.resources,
|
||||
org.eclipse.core.runtime.preferences,
|
||||
com._1c.g5.v8.bm.integration,
|
||||
com._1c.g5.v8.bm.core"
|
19
bundles/com.e1c.v8codestyle.autosort/build.properties
Normal file
19
bundles/com.e1c.v8codestyle.autosort/build.properties
Normal file
@ -0,0 +1,19 @@
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
plugin.xml,\
|
||||
plugin.properties,\
|
||||
plugin_ru.properties
|
13
bundles/com.e1c.v8codestyle.autosort/fragment_ru.properties
Normal file
13
bundles/com.e1c.v8codestyle.autosort/fragment_ru.properties
Normal file
@ -0,0 +1,13 @@
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
18
bundles/com.e1c.v8codestyle.autosort/plugin.properties
Normal file
18
bundles/com.e1c.v8codestyle.autosort/plugin.properties
Normal file
@ -0,0 +1,18 @@
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
#Properties file for com.e1c.v8codestyle.autosort
|
||||
|
||||
pluginName = 1C:Code style V8 Auto Sort plugin
|
||||
|
||||
providerName = 1C-Soft LLC
|
23
bundles/com.e1c.v8codestyle.autosort/plugin.xml
Normal file
23
bundles/com.e1c.v8codestyle.autosort/plugin.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<!--
|
||||
Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
|
||||
This program and the accompanying materials are made
|
||||
available under the terms of the Eclipse Public License 2.0
|
||||
which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0
|
||||
|
||||
Contributors:
|
||||
1C-Soft LLC - initial API and implementation
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
<extension
|
||||
point="com._1c.g5.wiring.serviceProvider">
|
||||
<bundle
|
||||
symbolicName="com.e1c.v8codestyle.autosort"></bundle>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
17
bundles/com.e1c.v8codestyle.autosort/plugin_ru.properties
Normal file
17
bundles/com.e1c.v8codestyle.autosort/plugin_ru.properties
Normal file
@ -0,0 +1,17 @@
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
|
||||
pluginName = 1С:Стандарты разработки V8 плагин Авто сортировки
|
||||
|
||||
providerName = ООО "1С-Софт"
|
27
bundles/com.e1c.v8codestyle.autosort/pom.xml
Normal file
27
bundles/com.e1c.v8codestyle.autosort/pom.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
|
||||
This program and the accompanying materials are made
|
||||
available under the terms of the Eclipse Public License 2.0
|
||||
which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0
|
||||
|
||||
Contributors:
|
||||
1C-Soft LLC - initial API and implementation
|
||||
-->
|
||||
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.e1c.v8codestyle</groupId>
|
||||
<artifactId>bundles</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>com.e1c.v8codestyle.autosort</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
</project>
|
@ -0,0 +1,177 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.autosort;
|
||||
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CATALOG__ATTRIBUTES;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CATALOG__COMMANDS;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CATALOG__FORMS;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CATALOG__TABULAR_SECTIONS;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CATALOG__TEMPLATES;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.HTTP_SERVICE__URL_TEMPLATES;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.INFORMATION_REGISTER__RESOURCES;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.URL_TEMPLATE__METHODS;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.WEB_SERVICE__OPERATIONS;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.emf.ecore.EReference;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
|
||||
import com.e1c.v8codestyle.internal.autosort.AutoSortPlugin;
|
||||
|
||||
/**
|
||||
* Public constants and utility method for sort preferences in the project.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public final class AutoSortPreferences
|
||||
{
|
||||
|
||||
public static final String KEY_ASCENDING = "sortAscending"; //$NON-NLS-1$
|
||||
|
||||
public static final String KEY_ALL_TOP = "topObjects"; //$NON-NLS-1$
|
||||
|
||||
public static final String KEY_TOP_NODE = "top"; //$NON-NLS-1$
|
||||
|
||||
public static final String KEY_SUBORDINATE_OBJECTS = "subordinateObjects"; //$NON-NLS-1$
|
||||
|
||||
public static final String KEY_SUBORDINATE_NODE = "subordinate"; //$NON-NLS-1$
|
||||
|
||||
public static final String KEY_FORMS = CATALOG__FORMS.getName();
|
||||
|
||||
public static final String KEY_TEMPLATES = CATALOG__TEMPLATES.getName();
|
||||
|
||||
public static final String KEY_COMMANDS = CATALOG__COMMANDS.getName();
|
||||
|
||||
public static final String KEY_OPERATIONS = WEB_SERVICE__OPERATIONS.getName();
|
||||
|
||||
public static final String KEY_URL_TEMPLATES = HTTP_SERVICE__URL_TEMPLATES.getName();
|
||||
|
||||
public static final String KEY_METHODS = URL_TEMPLATE__METHODS.getName();
|
||||
|
||||
public static final String KEY_ATTRIBUTES = CATALOG__ATTRIBUTES.getName();
|
||||
|
||||
public static final String KEY_REGISTRY_RESOURCES = INFORMATION_REGISTER__RESOURCES.getName();
|
||||
|
||||
public static final String KEY_TABULAR_SECTIONS = CATALOG__TABULAR_SECTIONS.getName();
|
||||
|
||||
public static final boolean DEFAULT_SORT_ASCENDING = true;
|
||||
|
||||
public static final boolean DEFAULT_SORT = false;
|
||||
|
||||
/**
|
||||
* Checks if the sort direction is ascending in the project.
|
||||
*
|
||||
* @param project the project to check, cannot be {@code null}.
|
||||
* @return true, if the sort is ascending, or return true as default if not set for project.
|
||||
*/
|
||||
public static boolean isSortAscending(IProject project)
|
||||
{
|
||||
IEclipsePreferences rootNode = getPreferences(project);
|
||||
return rootNode.getBoolean(KEY_ASCENDING, DEFAULT_SORT_ASCENDING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if need to sort all top object.
|
||||
*
|
||||
* @param project the project, cannot be {@code null}.
|
||||
* @return true, if need to sort all top object
|
||||
*/
|
||||
public static boolean isSortAllTop(IProject project)
|
||||
{
|
||||
IEclipsePreferences rootNode = getPreferences(project);
|
||||
return rootNode.getBoolean(KEY_ALL_TOP, DEFAULT_SORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if need to sort sub-ordinate objects of the top object.
|
||||
*
|
||||
* @param project the project, cannot be {@code null}.
|
||||
* @return true, if need to sort sub-ordinate objects
|
||||
*/
|
||||
public static boolean isSortSubOrdinateObjects(IProject project)
|
||||
{
|
||||
IEclipsePreferences rootNode = getPreferences(project);
|
||||
return rootNode.getBoolean(KEY_SUBORDINATE_OBJECTS, DEFAULT_SORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if it is allowed to sort the list reference in the project.
|
||||
*
|
||||
* @param project the project, cannot be {@code null}.
|
||||
* @param listRef the list reference, cannot be {@code null}.
|
||||
* @return true, if it is allowed to sort the list
|
||||
*/
|
||||
public static boolean isAllowedToSort(IProject project, EReference listRef)
|
||||
{
|
||||
if (ListConstants.TOP_OPBJECT_LISTS.contains(listRef))
|
||||
return isSortAllTop(project) || isSortTopList(project, listRef);
|
||||
|
||||
if (ListConstants.SUBORDINATE_OBJECT_LISTS.contains(listRef))
|
||||
return isSortSubOrdinateObjects(project) || isSortSubordinateList(project, listRef);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the preferences for the project.
|
||||
*
|
||||
* @param project the project, cannot be {@code null}.
|
||||
* @return the preferences for the project, cannot return {@code null}.
|
||||
*/
|
||||
public static IEclipsePreferences getPreferences(IProject project)
|
||||
{
|
||||
ProjectScope projectScope = new ProjectScope(project);
|
||||
IEclipsePreferences rootNode = projectScope.getNode(AutoSortPlugin.PLUGIN_ID);
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the project default values.
|
||||
*
|
||||
* @param project the project to setup default, cannot be {@code null}.
|
||||
*/
|
||||
public static void setupProjectDefault(IProject project)
|
||||
{
|
||||
IEclipsePreferences prefs = getPreferences(project);
|
||||
prefs.putBoolean(KEY_ALL_TOP, true);
|
||||
try
|
||||
{
|
||||
prefs.flush();
|
||||
}
|
||||
catch (BackingStoreException e)
|
||||
{
|
||||
AutoSortPlugin.logError(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSortTopList(IProject project, EReference listRef)
|
||||
{
|
||||
IEclipsePreferences rootNode = getPreferences(project);
|
||||
|
||||
return rootNode.node(KEY_TOP_NODE).getBoolean(listRef.getName(), DEFAULT_SORT);
|
||||
}
|
||||
|
||||
private static boolean isSortSubordinateList(IProject project, EReference listRef)
|
||||
{
|
||||
IEclipsePreferences rootNode = getPreferences(project);
|
||||
return rootNode.node(KEY_SUBORDINATE_NODE).getBoolean(listRef.getName(), DEFAULT_SORT);
|
||||
}
|
||||
|
||||
private AutoSortPreferences()
|
||||
{
|
||||
throw new IllegalAccessError("Utility class"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.e1c.v8codestyle.autosort;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
||||
import com._1c.g5.v8.bm.integration.IBmModel;
|
||||
import com._1c.g5.v8.dt.core.platform.IDtProject;
|
||||
|
||||
/**
|
||||
* The service allows to sort metadata object of the project.
|
||||
* Service register listener to {@link IBmModel} of each project and runs
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public interface ISortService
|
||||
{
|
||||
|
||||
/** The name of the service */
|
||||
String SERVICE_NAME = "SortService"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Sort all metadata object in the project.
|
||||
*
|
||||
* @param dtProject the DT project to sort, cannot be {@code null}.
|
||||
* @param monitor the status progress monitor, cannot be {@code null}.
|
||||
* @return the status of the sort operation, cannot be {@code null}.
|
||||
*/
|
||||
IStatus sortAllMetadata(IDtProject dtProject, IProgressMonitor monitor);
|
||||
|
||||
/**
|
||||
* Sort objects of the project.
|
||||
*
|
||||
* @param dtProject the DT project to sort, cannot be {@code null}.
|
||||
* @param items the sort items of object and it's collections that need to sort, cannot be {@code null}.
|
||||
* @param monitor the status progress monitor, cannot be {@code null}.
|
||||
* @return the status of the sort operation, cannot return {@code null}.
|
||||
*/
|
||||
IStatus sortObject(IDtProject dtProject, Collection<SortItem> items, IProgressMonitor monitor);
|
||||
|
||||
/**
|
||||
* Start a-synchronize job to sort all metadata objects of the project.
|
||||
*
|
||||
* @param project the project to start sort job, cannot be {@code null}.
|
||||
*/
|
||||
void startSortAllMetadata(IProject project);
|
||||
|
||||
/**
|
||||
* Start a-synchronize job to sort objects of the project.
|
||||
*
|
||||
* @param project the project to start sort job, cannot be {@code null}.
|
||||
* @param items the sort items of object and it's collections that need to sort, cannot be {@code null}.
|
||||
*/
|
||||
void startSortObject(IProject project, Collection<SortItem> items);
|
||||
}
|
@ -0,0 +1,176 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.autosort;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.emf.ecore.EReference;
|
||||
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals;
|
||||
|
||||
/**
|
||||
* The constants with lists that can be sorted in TOP or subordinate objects.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public final class ListConstants
|
||||
{
|
||||
|
||||
// @formatter:off
|
||||
public static final Set<EReference> TOP_OPBJECT_LISTS = Set.of(
|
||||
Literals.CONFIGURATION__LANGUAGES,
|
||||
Literals.CONFIGURATION__SUBSYSTEMS,
|
||||
Literals.SUBSYSTEM__SUBSYSTEMS,
|
||||
Literals.CONFIGURATION__STYLE_ITEMS,
|
||||
Literals.CONFIGURATION__STYLES,
|
||||
Literals.CONFIGURATION__COMMON_PICTURES,
|
||||
Literals.CONFIGURATION__INTERFACES,
|
||||
Literals.CONFIGURATION__SESSION_PARAMETERS,
|
||||
Literals.CONFIGURATION__ROLES,
|
||||
Literals.CONFIGURATION__COMMON_TEMPLATES,
|
||||
Literals.CONFIGURATION__FILTER_CRITERIA,
|
||||
Literals.CONFIGURATION__COMMON_MODULES,
|
||||
Literals.CONFIGURATION__EXCHANGE_PLANS,
|
||||
Literals.CONFIGURATION__XDTO_PACKAGES,
|
||||
Literals.CONFIGURATION__WEB_SERVICES,
|
||||
Literals.CONFIGURATION__HTTP_SERVICES,
|
||||
Literals.CONFIGURATION__WS_REFERENCES,
|
||||
Literals.CONFIGURATION__EVENT_SUBSCRIPTIONS,
|
||||
Literals.CONFIGURATION__SCHEDULED_JOBS,
|
||||
Literals.CONFIGURATION__SETTINGS_STORAGES,
|
||||
Literals.CONFIGURATION__FUNCTIONAL_OPTIONS,
|
||||
Literals.CONFIGURATION__FUNCTIONAL_OPTIONS_PARAMETERS,
|
||||
Literals.CONFIGURATION__DEFINED_TYPES,
|
||||
Literals.CONFIGURATION__COMMON_COMMANDS,
|
||||
Literals.CONFIGURATION__CONSTANTS,
|
||||
Literals.CONFIGURATION__COMMON_FORMS,
|
||||
Literals.CONFIGURATION__CATALOGS,
|
||||
Literals.CONFIGURATION__DOCUMENTS,
|
||||
Literals.CONFIGURATION__DOCUMENT_NUMERATORS,
|
||||
Literals.CONFIGURATION__SEQUENCES,
|
||||
Literals.CONFIGURATION__DOCUMENT_JOURNALS,
|
||||
Literals.CONFIGURATION__ENUMS,
|
||||
Literals.CONFIGURATION__REPORTS,
|
||||
Literals.CONFIGURATION__DATA_PROCESSORS,
|
||||
Literals.CONFIGURATION__INFORMATION_REGISTERS,
|
||||
Literals.CONFIGURATION__ACCUMULATION_REGISTERS,
|
||||
Literals.CONFIGURATION__CHARTS_OF_CHARACTERISTIC_TYPES,
|
||||
Literals.CONFIGURATION__CHARTS_OF_ACCOUNTS,
|
||||
Literals.CONFIGURATION__ACCOUNTING_REGISTERS,
|
||||
Literals.CONFIGURATION__CHARTS_OF_CALCULATION_TYPES,
|
||||
Literals.CONFIGURATION__CALCULATION_REGISTERS,
|
||||
Literals.CONFIGURATION__BUSINESS_PROCESSES,
|
||||
Literals.CONFIGURATION__TASKS,
|
||||
Literals.CONFIGURATION__EXTERNAL_DATA_SOURCES);
|
||||
// @formatter:on
|
||||
|
||||
// @formatter:off
|
||||
public static final Set<EReference> SUBORDINATE_OBJECT_LISTS = Set.of(
|
||||
Literals.CATALOG__FORMS,
|
||||
Literals.CATALOG__TEMPLATES,
|
||||
Literals.CATALOG__COMMANDS,
|
||||
Literals.DOCUMENT__FORMS,
|
||||
Literals.DOCUMENT__TEMPLATES,
|
||||
Literals.DOCUMENT__COMMANDS,
|
||||
Literals.DOCUMENT_JOURNAL__FORMS,
|
||||
Literals.DOCUMENT_JOURNAL__TEMPLATES,
|
||||
Literals.DOCUMENT_JOURNAL__COMMANDS,
|
||||
Literals.ENUM__FORMS,
|
||||
Literals.ENUM__TEMPLATES,
|
||||
Literals.ENUM__COMMANDS,
|
||||
Literals.REPORT__FORMS,
|
||||
Literals.REPORT__TEMPLATES,
|
||||
Literals.REPORT__COMMANDS,
|
||||
Literals.EXTERNAL_REPORT__FORMS,
|
||||
Literals.EXTERNAL_REPORT__TEMPLATES,
|
||||
Literals.DATA_PROCESSOR__FORMS,
|
||||
Literals.DATA_PROCESSOR__TEMPLATES,
|
||||
Literals.DATA_PROCESSOR__COMMANDS,
|
||||
Literals.EXTERNAL_DATA_PROCESSOR__FORMS,
|
||||
Literals.EXTERNAL_DATA_PROCESSOR__TEMPLATES,
|
||||
Literals.INFORMATION_REGISTER__FORMS,
|
||||
Literals.INFORMATION_REGISTER__TEMPLATES,
|
||||
Literals.INFORMATION_REGISTER__COMMANDS,
|
||||
Literals.ACCUMULATION_REGISTER__FORMS,
|
||||
Literals.ACCUMULATION_REGISTER__TEMPLATES,
|
||||
Literals.ACCUMULATION_REGISTER__COMMANDS,
|
||||
Literals.ACCOUNTING_REGISTER__FORMS,
|
||||
Literals.ACCOUNTING_REGISTER__TEMPLATES,
|
||||
Literals.ACCOUNTING_REGISTER__COMMANDS,
|
||||
Literals.CHART_OF_CHARACTERISTIC_TYPES__FORMS,
|
||||
Literals.CHART_OF_CHARACTERISTIC_TYPES__TEMPLATES,
|
||||
Literals.CHART_OF_CHARACTERISTIC_TYPES__COMMANDS,
|
||||
Literals.CHART_OF_ACCOUNTS__FORMS,
|
||||
Literals.CHART_OF_ACCOUNTS__TEMPLATES,
|
||||
Literals.CHART_OF_ACCOUNTS__COMMANDS,
|
||||
Literals.CHART_OF_CALCULATION_TYPES__FORMS,
|
||||
Literals.CHART_OF_CALCULATION_TYPES__TEMPLATES,
|
||||
Literals.CHART_OF_CALCULATION_TYPES__COMMANDS,
|
||||
Literals.EXCHANGE_PLAN__FORMS,
|
||||
Literals.EXCHANGE_PLAN__TEMPLATES,
|
||||
Literals.EXCHANGE_PLAN__COMMANDS,
|
||||
Literals.BUSINESS_PROCESS__FORMS,
|
||||
Literals.BUSINESS_PROCESS__TEMPLATES,
|
||||
Literals.BUSINESS_PROCESS__COMMANDS,
|
||||
Literals.TASK__FORMS,
|
||||
Literals.TASK__TEMPLATES,
|
||||
Literals.TASK__COMMANDS,
|
||||
Literals.SETTINGS_STORAGE__FORMS,
|
||||
Literals.SETTINGS_STORAGE__TEMPLATES,
|
||||
Literals.WEB_SERVICE__OPERATIONS,
|
||||
Literals.HTTP_SERVICE__URL_TEMPLATES,
|
||||
Literals.URL_TEMPLATE__METHODS,
|
||||
Literals.FILTER_CRITERION__FORMS,
|
||||
Literals.FILTER_CRITERION__COMMANDS,
|
||||
Literals.DB_OBJECT_TABULAR_SECTION__ATTRIBUTES,
|
||||
Literals.CATALOG__ATTRIBUTES,
|
||||
Literals.DOCUMENT__ATTRIBUTES,
|
||||
Literals.CHART_OF_CHARACTERISTIC_TYPES__ATTRIBUTES,
|
||||
Literals.INFORMATION_REGISTER__ATTRIBUTES,
|
||||
Literals.EXCHANGE_PLAN__ATTRIBUTES,
|
||||
Literals.REPORT__ATTRIBUTES,
|
||||
Literals.REPORT_TABULAR_SECTION__ATTRIBUTES,
|
||||
Literals.EXTERNAL_REPORT__ATTRIBUTES,
|
||||
Literals.DATA_PROCESSOR__ATTRIBUTES,
|
||||
Literals.DATA_PROCESSOR_TABULAR_SECTION__ATTRIBUTES,
|
||||
Literals.EXTERNAL_DATA_PROCESSOR__ATTRIBUTES,
|
||||
Literals.ACCUMULATION_REGISTER__ATTRIBUTES,
|
||||
Literals.BUSINESS_PROCESS__ATTRIBUTES,
|
||||
Literals.TASK__ATTRIBUTES,
|
||||
Literals.CHART_OF_ACCOUNTS__ATTRIBUTES,
|
||||
Literals.CHART_OF_CALCULATION_TYPES__ATTRIBUTES,
|
||||
Literals.ACCOUNTING_REGISTER__ATTRIBUTES,
|
||||
Literals.CALCULATION_REGISTER__ATTRIBUTES,
|
||||
Literals.CATALOG__TABULAR_SECTIONS,
|
||||
Literals.DOCUMENT__TABULAR_SECTIONS,
|
||||
Literals.CHART_OF_CHARACTERISTIC_TYPES__TABULAR_SECTIONS,
|
||||
Literals.EXCHANGE_PLAN__TABULAR_SECTIONS,
|
||||
Literals.REPORT__TABULAR_SECTIONS,
|
||||
Literals.EXTERNAL_REPORT__TABULAR_SECTIONS,
|
||||
Literals.DATA_PROCESSOR__TABULAR_SECTIONS,
|
||||
Literals.EXTERNAL_DATA_PROCESSOR__TABULAR_SECTIONS,
|
||||
Literals.BUSINESS_PROCESS__TABULAR_SECTIONS,
|
||||
Literals.TASK__TABULAR_SECTIONS,
|
||||
Literals.CHART_OF_ACCOUNTS__TABULAR_SECTIONS,
|
||||
Literals.CHART_OF_CALCULATION_TYPES__TABULAR_SECTIONS,
|
||||
Literals.INFORMATION_REGISTER__RESOURCES,
|
||||
Literals.ACCUMULATION_REGISTER__RESOURCES,
|
||||
Literals.ACCOUNTING_REGISTER__RESOURCES);
|
||||
// @formatter:on
|
||||
|
||||
private ListConstants()
|
||||
{
|
||||
throw new IllegalAccessError();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.autosort;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.MdObject;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
/**
|
||||
* The comparator for {@link MdObject} to compare them by name.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public class MdObjectByNameComparator
|
||||
implements Comparator<EObject>
|
||||
{
|
||||
|
||||
private final boolean ascending;
|
||||
|
||||
/**
|
||||
* Instantiates a new metadata object comparator by name.
|
||||
*
|
||||
* @param ascending the ascending
|
||||
*/
|
||||
public MdObjectByNameComparator(boolean ascending)
|
||||
{
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(EObject first, EObject second)
|
||||
{
|
||||
if (first instanceof MdObject && second instanceof MdObject)
|
||||
{
|
||||
String firstName = Strings.nullToEmpty(((MdObject)first).getName());
|
||||
String secondName = Strings.nullToEmpty(((MdObject)second).getName());
|
||||
return this.ascending ? firstName.compareToIgnoreCase(secondName)
|
||||
: secondName.compareToIgnoreCase(firstName);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.autosort;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EReference;
|
||||
|
||||
import com._1c.g5.v8.bm.core.IBmObject;
|
||||
|
||||
/**
|
||||
* The Sort item represents FQN (fully qualified name) of the object and it's list reference that need to sort with
|
||||
* given sorter.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public final class SortItem
|
||||
{
|
||||
private final EReference listRef;
|
||||
|
||||
private final String fqn;
|
||||
|
||||
private final Comparator<EObject> sorter;
|
||||
|
||||
private final int hashCode;
|
||||
|
||||
/**
|
||||
* Instantiates a new sort item.
|
||||
*
|
||||
* @param fqn the FQN to sort, cannot be {@code null}.
|
||||
* @param listRef the list reference, cannot be {@code null}.
|
||||
* @param sorter the sorter, cannot be {@code null}.
|
||||
*/
|
||||
public SortItem(String fqn, EReference listRef, Comparator<EObject> sorter)
|
||||
{
|
||||
super();
|
||||
this.fqn = fqn;
|
||||
this.listRef = listRef;
|
||||
this.sorter = sorter;
|
||||
this.hashCode = Objects.hash(fqn, listRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the FQN (fully qualified name) of the {@link IBmObject} to sort it's list
|
||||
*
|
||||
* @return the FQN, cannot return {@code null}.
|
||||
*/
|
||||
public String getFqn()
|
||||
{
|
||||
return fqn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list reference to sort objects.
|
||||
*
|
||||
* @return the list reference to sort objects, cannot return {@code null}.
|
||||
*/
|
||||
public EReference getListRef()
|
||||
{
|
||||
return listRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sorter for the list.
|
||||
*
|
||||
* @return the sorter, cannot return {@code null}.
|
||||
*/
|
||||
public Comparator<EObject> getSorter()
|
||||
{
|
||||
return sorter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
SortItem other = (SortItem)obj;
|
||||
return Objects.equals(fqn, other.fqn) && Objects.equals(listRef, other.listRef);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,196 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.autosort;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import com._1c.g5.wiring.InjectorAwareServiceRegistrator;
|
||||
import com._1c.g5.wiring.ServiceInitialization;
|
||||
import com.e1c.v8codestyle.autosort.ISortService;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* The Class AutoSortPlugin.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*
|
||||
*/
|
||||
public class AutoSortPlugin
|
||||
extends Plugin
|
||||
{
|
||||
|
||||
public static final String PLUGIN_ID = "com.e1c.v8codestyle.autosort"; //$NON-NLS-1$
|
||||
|
||||
private static AutoSortPlugin plugin;
|
||||
|
||||
private InjectorAwareServiceRegistrator registrator;
|
||||
|
||||
private volatile Injector injector;
|
||||
|
||||
private static BundleContext context;
|
||||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
* @return the shared instance
|
||||
*/
|
||||
public static AutoSortPlugin getDefault()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a status to the plugin log.
|
||||
*
|
||||
* @param status status to log, cannot be <code>null</code>
|
||||
*/
|
||||
public static void log(IStatus status)
|
||||
{
|
||||
plugin.getLog().log(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a throwable to the plugin log as error status.
|
||||
*
|
||||
* @param throwable throwable, cannot be <code>null</code>
|
||||
*/
|
||||
public static void logError(Throwable throwable)
|
||||
{
|
||||
log(createErrorStatus(throwable.getMessage(), throwable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates error status by a given message and cause throwable.
|
||||
*
|
||||
* @param message status message, cannot be <code>null</code>
|
||||
* @param throwable throwable, can be <code>null</code> if not applicable
|
||||
* @return status created error status, never <code>null</code>
|
||||
*/
|
||||
public static IStatus createErrorStatus(String message, Throwable throwable)
|
||||
{
|
||||
return new Status(IStatus.ERROR, PLUGIN_ID, 0, message, throwable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates warning status by a given message.
|
||||
*
|
||||
* @param message status message, cannot be <code>null</code>
|
||||
* @return status created warning status, never <code>null</code>
|
||||
*/
|
||||
public static IStatus createWarningStatus(String message)
|
||||
{
|
||||
return new Status(IStatus.WARNING, PLUGIN_ID, 0, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates warning status by a given message and cause throwable.
|
||||
*
|
||||
* @param message status message, cannot be <code>null</code>
|
||||
* @param throwable throwable, can be <code>null</code> if not applicable
|
||||
* @return status created warning status, never <code>null</code>
|
||||
*/
|
||||
public static IStatus createWarningStatus(final String message, Exception throwable)
|
||||
{
|
||||
return new Status(IStatus.WARNING, PLUGIN_ID, 0, message, throwable);
|
||||
}
|
||||
|
||||
static BundleContext getContext()
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
@Override
|
||||
public void start(BundleContext bundleContext) throws Exception
|
||||
{
|
||||
|
||||
super.start(bundleContext);
|
||||
|
||||
AutoSortPlugin.context = bundleContext;
|
||||
plugin = this;
|
||||
|
||||
registrator = new InjectorAwareServiceRegistrator(context, this::getInjector);
|
||||
ServiceInitialization.schedule(() -> {
|
||||
try
|
||||
{
|
||||
registrator.service(ISortService.class).registerInjected();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logError(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
@Override
|
||||
public void stop(BundleContext bundleContext) throws Exception
|
||||
{
|
||||
|
||||
injector = null;
|
||||
plugin = null;
|
||||
super.stop(bundleContext);
|
||||
|
||||
AutoSortPlugin.context = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Guice injector of the plugin
|
||||
*
|
||||
* @return Guice injector of the plugin, never <code>null</code> if plugin is started
|
||||
*/
|
||||
/* package */ Injector getInjector()
|
||||
{
|
||||
Injector localInstance = injector;
|
||||
if (localInstance == null)
|
||||
{
|
||||
synchronized (AutoSortPlugin.class)
|
||||
{
|
||||
localInstance = injector;
|
||||
if (localInstance == null)
|
||||
{
|
||||
localInstance = createInjector();
|
||||
injector = localInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return localInstance;
|
||||
}
|
||||
|
||||
private Injector createInjector()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Guice.createInjector(new ServiceModule(), new ExternalDependenciesModule(this));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log(createErrorStatus("Failed to create injector for " //$NON-NLS-1$
|
||||
+ getBundle().getSymbolicName(), e));
|
||||
throw new RuntimeException("Failed to create injector for " //$NON-NLS-1$
|
||||
+ getBundle().getSymbolicName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.autosort;
|
||||
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
import com._1c.g5.wiring.AbstractGuiceAwareExecutableExtensionFactory;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Guice module aware executable extension factory for AutoSort plugin.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public class ExecutableExtensionFactory
|
||||
extends AbstractGuiceAwareExecutableExtensionFactory
|
||||
{
|
||||
@Override
|
||||
protected Bundle getBundle()
|
||||
{
|
||||
return AutoSortPlugin.getDefault().getBundle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Injector getInjector()
|
||||
{
|
||||
return AutoSortPlugin.getDefault().getInjector();
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.autosort;
|
||||
|
||||
import org.eclipse.core.runtime.Plugin;
|
||||
|
||||
import com._1c.g5.v8.dt.core.platform.IBmModelManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IConfigurationProvider;
|
||||
import com._1c.g5.v8.dt.core.platform.IDtProjectManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IWorkspaceOrchestrator;
|
||||
import com._1c.g5.wiring.AbstractServiceAwareModule;
|
||||
|
||||
/**
|
||||
* The external dependencies for AutoSort plugin
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
class ExternalDependenciesModule
|
||||
extends AbstractServiceAwareModule
|
||||
{
|
||||
|
||||
ExternalDependenciesModule(Plugin plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doConfigure()
|
||||
{
|
||||
// V8 DT
|
||||
bind(IDtProjectManager.class).toService();
|
||||
bind(IBmModelManager.class).toService();
|
||||
bind(IConfigurationProvider.class).toService();
|
||||
bind(IWorkspaceOrchestrator.class).toService();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.e1c.v8codestyle.internal.autosort;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
/**
|
||||
* @author Dmitriy Marmyshev
|
||||
*
|
||||
*/
|
||||
final class Messages
|
||||
extends NLS
|
||||
{
|
||||
private static final String BUNDLE_NAME = "com.e1c.v8codestyle.internal.autosort.messages"; //$NON-NLS-1$
|
||||
public static String SortJob_Sort_metadata_objects__0;
|
||||
public static String SortService_Read_all_objects_to_sort;
|
||||
static
|
||||
{
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
|
||||
}
|
||||
|
||||
private Messages()
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.autosort;
|
||||
|
||||
import com.e1c.v8codestyle.autosort.ISortService;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* @author Dmitriy Marmyshev
|
||||
*
|
||||
*/
|
||||
public class ServiceModule
|
||||
extends AbstractModule
|
||||
{
|
||||
|
||||
@Override
|
||||
protected void configure()
|
||||
{
|
||||
bind(ISortService.class).to(SortService.class).in(Singleton.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.autosort;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EReference;
|
||||
import org.eclipse.emf.edit.command.ChangeCommand;
|
||||
|
||||
import com._1c.g5.v8.bm.core.IBmTransaction;
|
||||
import com._1c.g5.v8.bm.integration.AbstractBmTask;
|
||||
import com._1c.g5.v8.bm.integration.IBmModel;
|
||||
import com.e1c.v8codestyle.autosort.SortItem;
|
||||
|
||||
/**
|
||||
* The task to sort BM objects.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*
|
||||
* @see IBmModel
|
||||
* @see SortItem
|
||||
*/
|
||||
public class SortBmTask
|
||||
extends AbstractBmTask<Void>
|
||||
{
|
||||
|
||||
private final Collection<SortItem> items;
|
||||
|
||||
/**
|
||||
* Instantiates a new sort BM task.
|
||||
*
|
||||
* <br>
|
||||
* <b>WARNING!</b> the collection of items must be immutable or unmodifiable for callers.
|
||||
*
|
||||
* @param items the unmodifiable collection of items to sort, cannot be {@code null}.
|
||||
*/
|
||||
public SortBmTask(final Collection<SortItem> items)
|
||||
{
|
||||
super("Sort Md objects"); //$NON-NLS-1$
|
||||
this.items = new ArrayList<>(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void execute(IBmTransaction transaction, IProgressMonitor monitor)
|
||||
{
|
||||
for (SortItem item : items)
|
||||
{
|
||||
if (monitor.isCanceled())
|
||||
return null;
|
||||
|
||||
if (!item.getListRef().isMany())
|
||||
continue;
|
||||
|
||||
EObject parent = transaction.getTopObjectByFqn(item.getFqn());
|
||||
if (parent != null)
|
||||
{
|
||||
Object value = parent.eGet(item.getListRef());
|
||||
if (!(value instanceof List))
|
||||
continue;
|
||||
|
||||
List<?> elements = (List<?>)value;
|
||||
if (elements.size() < 2)
|
||||
continue;
|
||||
|
||||
SortCommand command = new SortCommand(parent, item.getListRef(), item.getSorter());
|
||||
if (command.canExecute())
|
||||
command.execute();
|
||||
command.dispose();
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final class SortCommand
|
||||
extends ChangeCommand
|
||||
{
|
||||
|
||||
private final EList<EObject> list;
|
||||
|
||||
private final Comparator<EObject> sorter;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private SortCommand(EObject parent, EReference listFeature, Comparator<EObject> sorter)
|
||||
{
|
||||
super(parent);
|
||||
Assert.isNotNull(parent);
|
||||
Assert.isTrue(listFeature.isMany());
|
||||
this.list = (EList<EObject>)parent.eGet(listFeature);
|
||||
this.sorter = sorter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute()
|
||||
{
|
||||
ArrayList<EObject> sorted = new ArrayList<>(list);
|
||||
Collections.sort(sorted, this.sorter);
|
||||
for (int i = 0; i < sorted.size(); i++)
|
||||
{
|
||||
EObject element = sorted.get(i);
|
||||
int oldIndex = list.indexOf(element);
|
||||
int newIndex = sorted.indexOf(element);
|
||||
if (oldIndex != -1 && newIndex != -1 && oldIndex != newIndex)
|
||||
{
|
||||
list.move(newIndex, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.internal.autosort;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
import com._1c.g5.v8.dt.core.operations.ProjectPipelineJob;
|
||||
import com._1c.g5.v8.dt.core.platform.IDtProject;
|
||||
import com._1c.g5.v8.dt.core.platform.IWorkspaceOrchestrator;
|
||||
import com.e1c.v8codestyle.autosort.ISortService;
|
||||
import com.e1c.v8codestyle.autosort.SortItem;
|
||||
|
||||
/**
|
||||
* The Eclipse platform job to sort the project.
|
||||
* This job allows to append the {@link Queue} of small {@link SortItem sort tasks} while it is running.
|
||||
* Callers should call {@link #schedule()} each time after append the job to make sure that this job will
|
||||
* complete the sort tasks.
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*
|
||||
* @see ISortService
|
||||
* @see SortItem
|
||||
*/
|
||||
public class SortJob
|
||||
extends Job
|
||||
{
|
||||
|
||||
private final BlockingQueue<SortItem> queue = new LinkedBlockingQueue<>();
|
||||
|
||||
private final IDtProject dtProject;
|
||||
|
||||
private final IWorkspaceOrchestrator workspaceOrchestrator;
|
||||
|
||||
private final ISortService sortService;
|
||||
|
||||
/**
|
||||
* Instantiates a new sort job.
|
||||
*
|
||||
* @param dtProject the DT project, cannot be {@link null}.
|
||||
* @param sortService the sort service, cannot be {@link null}.
|
||||
* @param workspaceOrchestrator the workspace orchestrator, cannot be {@link null}.
|
||||
*/
|
||||
public SortJob(IDtProject dtProject, ISortService sortService, IWorkspaceOrchestrator workspaceOrchestrator)
|
||||
{
|
||||
super(MessageFormat.format(Messages.SortJob_Sort_metadata_objects__0, dtProject.getName()));
|
||||
this.dtProject = dtProject;
|
||||
this.sortService = sortService;
|
||||
this.workspaceOrchestrator = workspaceOrchestrator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor)
|
||||
{
|
||||
if (dtProject.getWorkspaceProject() == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
Object handler = workspaceOrchestrator.beginBackgroundOperation("Sort-MD-objects", //$NON-NLS-1$
|
||||
Arrays.asList(dtProject), ProjectPipelineJob.BUILD);
|
||||
|
||||
try
|
||||
{
|
||||
while (!queue.isEmpty() && !monitor.isCanceled())
|
||||
{
|
||||
execute(monitor);
|
||||
}
|
||||
if (monitor.isCanceled())
|
||||
queue.clear();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (monitor.isCanceled())
|
||||
{
|
||||
workspaceOrchestrator.cancelOperation(handler);
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
else
|
||||
{
|
||||
workspaceOrchestrator.endOperation(handler);
|
||||
}
|
||||
}
|
||||
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the queue of sort items.
|
||||
*
|
||||
* @return the queue, cannot be {@link null}.
|
||||
*/
|
||||
public Queue<SortItem> getQueue()
|
||||
{
|
||||
return queue;
|
||||
}
|
||||
|
||||
private void execute(IProgressMonitor monitor)
|
||||
{
|
||||
List<SortItem> items = new ArrayList<>();
|
||||
SortItem item = null;
|
||||
while ((item = queue.poll()) != null && !monitor.isCanceled())
|
||||
{
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
if (!monitor.isCanceled() && !items.isEmpty())
|
||||
{
|
||||
sortService.sortObject(dtProject, items, monitor);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,491 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.e1c.v8codestyle.internal.autosort;
|
||||
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION;
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.MD_OBJECT;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.emf.common.notify.Notification;
|
||||
import org.eclipse.emf.common.util.EList;
|
||||
import org.eclipse.emf.ecore.EClass;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.EReference;
|
||||
import org.eclipse.emf.ecore.EStructuralFeature;
|
||||
|
||||
import com._1c.g5.v8.bm.common.collections.IBmLongMap;
|
||||
import com._1c.g5.v8.bm.core.IBmObject;
|
||||
import com._1c.g5.v8.bm.core.IBmTransaction;
|
||||
import com._1c.g5.v8.bm.core.event.BmChangeEvent;
|
||||
import com._1c.g5.v8.bm.core.event.BmEvent;
|
||||
import com._1c.g5.v8.bm.integration.AbstractBmTask;
|
||||
import com._1c.g5.v8.bm.integration.IBmModel;
|
||||
import com._1c.g5.v8.bm.integration.event.BmEventFilter;
|
||||
import com._1c.g5.v8.bm.integration.event.IBmAsyncEventListener;
|
||||
import com._1c.g5.v8.dt.core.lifecycle.ProjectContext;
|
||||
import com._1c.g5.v8.dt.core.lifecycle.ProjectStartType;
|
||||
import com._1c.g5.v8.dt.core.platform.IBmModelManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IConfigurationProvider;
|
||||
import com._1c.g5.v8.dt.core.platform.IDtProject;
|
||||
import com._1c.g5.v8.dt.core.platform.IDtProjectManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IWorkspaceOrchestrator;
|
||||
import com._1c.g5.v8.dt.lifecycle.LifecycleParticipant;
|
||||
import com._1c.g5.v8.dt.lifecycle.LifecyclePhase;
|
||||
import com._1c.g5.v8.dt.lifecycle.LifecycleService;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.Configuration;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.MdObject;
|
||||
import com.e1c.v8codestyle.autosort.AutoSortPreferences;
|
||||
import com.e1c.v8codestyle.autosort.ISortService;
|
||||
import com.e1c.v8codestyle.autosort.MdObjectByNameComparator;
|
||||
import com.e1c.v8codestyle.autosort.SortItem;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
/**
|
||||
* @author Dmitriy Marmyshev
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
@LifecycleService(name = ISortService.SERVICE_NAME)
|
||||
public class SortService
|
||||
implements ISortService
|
||||
{
|
||||
|
||||
private static final long JOB_DELAY = 500;
|
||||
|
||||
protected static final String CONFIGURATION_FQN = CONFIGURATION.getName();
|
||||
|
||||
private final IDtProjectManager dtProjectManager;
|
||||
|
||||
private final IBmModelManager modelManager;
|
||||
|
||||
private final IConfigurationProvider configurationProvider;
|
||||
|
||||
private final IWorkspaceOrchestrator workspaceOrchestrator;
|
||||
|
||||
private final BmEventFilter filter = BmEventFilter.eClassChangeFilter(MdClassPackage.Literals.MD_OBJECT);
|
||||
|
||||
private final Map<IProject, IBmAsyncEventListener> projectListeners = new ConcurrentHashMap<>();
|
||||
private final Map<IProject, SortJob> jobs = new ConcurrentHashMap<>();
|
||||
|
||||
@Inject
|
||||
public SortService(IDtProjectManager dtProjectManager, IBmModelManager modelManager,
|
||||
IConfigurationProvider configurationProvider, IWorkspaceOrchestrator workspaceOrchestrator)
|
||||
{
|
||||
this.dtProjectManager = dtProjectManager;
|
||||
this.modelManager = modelManager;
|
||||
this.configurationProvider = configurationProvider;
|
||||
this.workspaceOrchestrator = workspaceOrchestrator;
|
||||
}
|
||||
|
||||
@LifecycleParticipant(phase = LifecyclePhase.RESOURCE_LOADING,
|
||||
dependsOn = { IBmModelManager.SERVICE_NAME, IDtProjectManager.SERVICE_NAME })
|
||||
public void init(ProjectContext projectContext)
|
||||
{
|
||||
|
||||
IDtProject dtProject = projectContext.getProject();
|
||||
IProject project = dtProject.getWorkspaceProject();
|
||||
|
||||
if (project != null)
|
||||
{
|
||||
ProjectStartType startType = projectContext.getStartType();
|
||||
if (startType.equals(ProjectStartType.NEW_PROJECT))
|
||||
{
|
||||
// setup project to sort top by default
|
||||
AutoSortPreferences.setupProjectDefault(project);
|
||||
}
|
||||
|
||||
// register BM listener to track changes
|
||||
IBmModel model = modelManager.getModel(project);
|
||||
if (model != null)
|
||||
{
|
||||
IBmAsyncEventListener listener = projectListeners.computeIfAbsent(project, MdObjectChangeListener::new);
|
||||
model.addAsyncEventListener(listener, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@LifecycleParticipant(phase = LifecyclePhase.RESOURCE_UNLOADING)
|
||||
public void dispose(ProjectContext lifecycleContext)
|
||||
{
|
||||
IDtProject dtProject = lifecycleContext.getProject();
|
||||
IProject project = dtProject.getWorkspaceProject();
|
||||
|
||||
if (project != null)
|
||||
{
|
||||
// remove BM listener
|
||||
IBmModel model = modelManager.getModel(dtProject);
|
||||
if (model != null)
|
||||
{
|
||||
IBmAsyncEventListener listener = projectListeners.get(project);
|
||||
if (listener != null)
|
||||
model.removeAsyncEventListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus sortAllMetadata(IDtProject dtProject, IProgressMonitor monitor)
|
||||
{
|
||||
IBmModel model = modelManager.getModel(dtProject);
|
||||
if (model == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
IProject project = dtProject.getWorkspaceProject();
|
||||
Collection<SortItem> items = readAllObjectsToSort(model, project, monitor);
|
||||
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
if (project != null)
|
||||
{
|
||||
SortJob job = jobs.get(project);
|
||||
if (job != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
job.join(0, monitor);
|
||||
}
|
||||
catch (OperationCanceledException e)
|
||||
{
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
AutoSortPlugin.logError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sortObject(dtProject, items, monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStatus sortObject(IDtProject dtProject, Collection<SortItem> items, IProgressMonitor monitor)
|
||||
{
|
||||
IBmModel model = modelManager.getModel(dtProject);
|
||||
if (model == null || model.isDisposed())
|
||||
return Status.OK_STATUS;
|
||||
|
||||
if (monitor.isCanceled() || items == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
if (items.isEmpty())
|
||||
return Status.OK_STATUS;
|
||||
|
||||
model.getGlobalContext().execute(new SortBmTask(items));
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSortAllMetadata(IProject project)
|
||||
{
|
||||
Job job = Job.create(Messages.SortService_Read_all_objects_to_sort, monitor -> {
|
||||
|
||||
IBmModel model = modelManager.getModel(project);
|
||||
if (model == null)
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
Collection<SortItem> items = readAllObjectsToSort(model, project, monitor);
|
||||
|
||||
if (monitor.isCanceled())
|
||||
return Status.CANCEL_STATUS;
|
||||
|
||||
startSortObject(project, items);
|
||||
return Status.OK_STATUS;
|
||||
});
|
||||
job.schedule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSortObject(IProject project, Collection<SortItem> items)
|
||||
{
|
||||
IDtProject dtProject = dtProjectManager.getDtProject(project);
|
||||
if (dtProject == null || items.isEmpty())
|
||||
return;
|
||||
|
||||
SortJob job = jobs.computeIfAbsent(project, p -> new SortJob(dtProject, this, workspaceOrchestrator));
|
||||
job.getQueue().addAll(items);
|
||||
job.schedule(JOB_DELAY);
|
||||
}
|
||||
|
||||
private Collection<SortItem> readAllObjectsToSort(IBmModel model, IProject project, IProgressMonitor monitor)
|
||||
{
|
||||
return model.executeReadonlyTask(new ReadSortObjects(project, monitor), true);
|
||||
}
|
||||
|
||||
private Comparator<EObject> createProjectSorter(IProject project)
|
||||
{
|
||||
final Comparator<EObject> sorter;
|
||||
if (project == null)
|
||||
{
|
||||
sorter = new MdObjectByNameComparator(AutoSortPreferences.DEFAULT_SORT_ASCENDING);
|
||||
}
|
||||
else
|
||||
{
|
||||
sorter = new MdObjectByNameComparator(AutoSortPreferences.isSortAscending(project));
|
||||
}
|
||||
return sorter;
|
||||
}
|
||||
|
||||
private final class MdObjectChangeListener
|
||||
implements IBmAsyncEventListener
|
||||
{
|
||||
|
||||
private final IProject project;
|
||||
|
||||
private MdObjectChangeListener(IProject project)
|
||||
{
|
||||
Assert.isNotNull(project);
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleAsyncEvent(BmEvent event)
|
||||
{
|
||||
IBmLongMap<BmChangeEvent> change = event.getChangeEvents();
|
||||
if (change == null)
|
||||
return;
|
||||
|
||||
Map<String, Set<EReference>> changedItems = new HashMap<>();
|
||||
|
||||
for (BmChangeEvent changeEvent : change.values())
|
||||
{
|
||||
if (changeEvent.getObject() instanceof IBmObject && ((IBmObject)changeEvent.getObject()).bmIsTop()
|
||||
&& ((IBmObject)changeEvent.getObject()).bmGetFqn() != null)
|
||||
{
|
||||
Map<EStructuralFeature, List<Notification>> notifications = changeEvent.getNotifications();
|
||||
for (Entry<EStructuralFeature, List<Notification>> entry : notifications.entrySet())
|
||||
{
|
||||
if (entry.getKey() instanceof EReference
|
||||
&& AutoSortPreferences.isAllowedToSort(project, (EReference)entry.getKey()))
|
||||
{
|
||||
collectChangesOfList(changedItems, (EReference)entry.getKey(), entry.getValue());
|
||||
}
|
||||
else if (entry.getKey().equals(MdClassPackage.Literals.MD_OBJECT__NAME))
|
||||
{
|
||||
collectChangedOfNames(changedItems, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
processChanges(changedItems);
|
||||
}
|
||||
|
||||
private void collectChangesOfList(Map<String, Set<EReference>> changedItems, EReference listRef,
|
||||
List<Notification> notifications)
|
||||
{
|
||||
for (Notification notification : notifications)
|
||||
{
|
||||
if (notification.getEventType() == Notification.ADD)
|
||||
{
|
||||
Object notifier = notification.getNotifier();
|
||||
Object value = notification.getNewValue();
|
||||
if (notifier instanceof IBmObject && value instanceof MdObject)
|
||||
{
|
||||
changedItems.computeIfAbsent(((IBmObject)notifier).bmGetFqn(), k -> new HashSet<>())
|
||||
.add(listRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void collectChangedOfNames(Map<String, Set<EReference>> changedItems, List<Notification> notifications)
|
||||
{
|
||||
for (Notification notification : notifications)
|
||||
{
|
||||
if (notification.getEventType() == Notification.SET
|
||||
&& !(notification.getNotifier() instanceof Configuration))
|
||||
{
|
||||
Object notifier = notification.getNotifier();
|
||||
Object value = notification.getNewValue();
|
||||
if (notifier instanceof MdObject && value instanceof String)
|
||||
{
|
||||
MdObject mdObject = (MdObject)notifier;
|
||||
EObject parent = mdObject.eContainer();
|
||||
EReference listRef = (EReference)mdObject.eContainingFeature();
|
||||
if (parent == null && ((IBmObject)mdObject).bmIsTop())
|
||||
{
|
||||
parent = configurationProvider.getConfiguration(mdObject);
|
||||
listRef = getConfigurationFeature(mdObject);
|
||||
}
|
||||
if (!(parent instanceof IBmObject) || listRef == null
|
||||
|| !AutoSortPreferences.isAllowedToSort(project, listRef))
|
||||
continue;
|
||||
|
||||
changedItems.computeIfAbsent(((IBmObject)parent).bmGetFqn(), k -> new HashSet<>()).add(listRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processChanges(Map<String, Set<EReference>> changedItems)
|
||||
{
|
||||
if (!changedItems.isEmpty())
|
||||
{
|
||||
List<SortItem> items = new ArrayList<>();
|
||||
|
||||
Comparator<EObject> sorter = new MdObjectByNameComparator(AutoSortPreferences.isSortAscending(project));
|
||||
|
||||
for (Entry<String, Set<EReference>> entry : changedItems.entrySet())
|
||||
{
|
||||
for (EReference lisRef : entry.getValue())
|
||||
{
|
||||
SortItem item = new SortItem(entry.getKey(), lisRef, sorter);
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
if (!items.isEmpty())
|
||||
startSortObject(project, items);
|
||||
}
|
||||
}
|
||||
|
||||
private EReference getConfigurationFeature(MdObject mdObject)
|
||||
{
|
||||
for (EReference feature : CONFIGURATION.getEAllReferences())
|
||||
{
|
||||
if (!feature.isMany() || feature.equals(MdClassPackage.Literals.CONFIGURATION__CONTENT)
|
||||
|| !feature.getEType().isInstance(mdObject))
|
||||
continue;
|
||||
return feature;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ReadSortObjects
|
||||
extends AbstractBmTask<Collection<SortItem>>
|
||||
{
|
||||
|
||||
private final IProject project;
|
||||
|
||||
private final IProgressMonitor monitor;
|
||||
|
||||
private final Comparator<EObject> sorter;
|
||||
|
||||
protected ReadSortObjects(IProject project, IProgressMonitor monitor)
|
||||
{
|
||||
super("Read collections to sort"); //$NON-NLS-1$
|
||||
this.project = project;
|
||||
this.monitor = monitor;
|
||||
sorter = createProjectSorter(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<SortItem> execute(IBmTransaction transaction, IProgressMonitor m)
|
||||
{
|
||||
Collection<SortItem> result = new ArrayList<>();
|
||||
|
||||
appendByConfiguration(result, transaction, m);
|
||||
|
||||
if (project != null && AutoSortPreferences.isSortSubOrdinateObjects(project)
|
||||
|| project == null && AutoSortPreferences.DEFAULT_SORT)
|
||||
{
|
||||
if (monitor.isCanceled() || m.isCanceled())
|
||||
return result;
|
||||
|
||||
Iterable<EClass> eClassIterator = transaction.getTopObjectEClasses();
|
||||
Map<EClass, List<EReference>> sortListRefs = getSubordinateListsToSort(eClassIterator, project);
|
||||
|
||||
appendSubordinateObjects(result, sortListRefs, transaction, m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void appendSubordinateObjects(Collection<SortItem> result, Map<EClass, List<EReference>> sortListRefs,
|
||||
IBmTransaction transaction, IProgressMonitor m)
|
||||
{
|
||||
for (Entry<EClass, List<EReference>> entry : sortListRefs.entrySet())
|
||||
{
|
||||
for (Iterator<IBmObject> iterator = transaction.getTopObjectIterator(entry.getKey()); iterator
|
||||
.hasNext();)
|
||||
{
|
||||
if (monitor.isCanceled() || m.isCanceled())
|
||||
return;
|
||||
|
||||
IBmObject object = iterator.next();
|
||||
String fqn = object.bmGetFqn();
|
||||
entry.getValue().forEach(ref -> result.add(new SortItem(fqn, ref, sorter)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<EClass, List<EReference>> getSubordinateListsToSort(Iterable<EClass> eClassIterator,
|
||||
IProject project)
|
||||
{
|
||||
Map<EClass, List<EReference>> sortListRefs = new HashMap<>();
|
||||
for (EClass topObjectEClass : eClassIterator)
|
||||
{
|
||||
if (topObjectEClass.equals(CONFIGURATION) || !MD_OBJECT.isSuperTypeOf(topObjectEClass))
|
||||
continue;
|
||||
|
||||
for (EReference feature : topObjectEClass.getEAllReferences())
|
||||
{
|
||||
if (!feature.isMany() || project != null && !AutoSortPreferences.isAllowedToSort(project, feature)
|
||||
|| project == null && !AutoSortPreferences.DEFAULT_SORT)
|
||||
continue;
|
||||
|
||||
sortListRefs.computeIfAbsent(topObjectEClass, e -> new ArrayList<>()).add(feature);
|
||||
}
|
||||
}
|
||||
return sortListRefs;
|
||||
}
|
||||
|
||||
private void appendByConfiguration(Collection<SortItem> result, IBmTransaction transaction, IProgressMonitor m)
|
||||
{
|
||||
EObject top = transaction.getTopObjectByFqn(CONFIGURATION_FQN);
|
||||
if (top != null)
|
||||
{
|
||||
for (EReference feature : CONFIGURATION.getEAllReferences())
|
||||
{
|
||||
if (monitor.isCanceled() || m.isCanceled())
|
||||
return;
|
||||
|
||||
if (!feature.isMany() || feature.equals(MdClassPackage.Literals.CONFIGURATION__CONTENT)
|
||||
|| project != null && !AutoSortPreferences.isAllowedToSort(project, feature)
|
||||
|| project == null && !AutoSortPreferences.DEFAULT_SORT)
|
||||
continue;
|
||||
EList<?> collection = (EList<?>)top.eGet(feature, false);
|
||||
if (collection.size() > 1)
|
||||
result.add(new SortItem(CONFIGURATION_FQN, feature, sorter));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
SortJob_Sort_metadata_objects__0=Sort metadata objects: {0}
|
||||
SortService_Read_all_objects_to_sort=Read all objects to sort
|
@ -0,0 +1,16 @@
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
|
||||
|
||||
SortJob_Sort_metadata_objects__0 = Сортировка объектов метаданных: {0}
|
||||
SortService_Read_all_objects_to_sort = Чтение всех объектов для сортировки
|
@ -25,6 +25,8 @@
|
||||
<modules>
|
||||
<module>com.e1c.v8codestyle</module>
|
||||
<module>com.e1c.v8codestyle.md</module>
|
||||
<module>com.e1c.v8codestyle.autosort</module>
|
||||
<module>com.e1c.v8codestyle.autosort.ui</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
|
@ -46,4 +46,25 @@
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="com.e1c.v8codestyle.autosort"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="com.e1c.v8codestyle.autosort.ui"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
<plugin
|
||||
id="com.e1c.v8codestyle.docs"
|
||||
download-size="0"
|
||||
install-size="0"
|
||||
version="0.0.0"
|
||||
unpack="false"/>
|
||||
|
||||
</feature>
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
<!-- EDT -->
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="slicer" includeSource="true" type="InstallableUnit">
|
||||
<repository location="https://edt.1c.ru/downloads/releases/experimental/validation"/>
|
||||
<repository location="https://edt.1c.ru/downloads/releases/ruby/2021.2/"/>
|
||||
<unit id="com._1c.g5.aef.feature.feature.group" version="0.0.0"/>
|
||||
<unit id="com._1c.g5.commons.feature.group" version="0.0.0"/>
|
||||
<unit id="com._1c.g5.edt.license.feature.group" version="0.0.0"/>
|
||||
|
7
tests/com.e1c.v8codestyle.autosort.itests/.classpath
Normal file
7
tests/com.e1c.v8codestyle.autosort.itests/.classpath
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
28
tests/com.e1c.v8codestyle.autosort.itests/.project
Normal file
28
tests/com.e1c.v8codestyle.autosort.itests/.project
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.e1c.v8codestyle.autosort.itests</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
@ -0,0 +1,10 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||
org.eclipse.jdt.core.compiler.compliance=11
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=11
|
@ -0,0 +1,13 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %pluginName
|
||||
Bundle-SymbolicName: com.e1c.v8codestyle.autosort.itests;singleton:=true
|
||||
Bundle-Version: 0.1.0.qualifier
|
||||
Bundle-Vendor: %providerName
|
||||
Fragment-Host: com.e1c.v8codestyle.autosort;bundle-version="[0.1.0,0.2.0)"
|
||||
Automatic-Module-Name: com.e1c.v8codestyle.autosort.itests
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-11
|
||||
Bundle-Localization: fragment
|
||||
Import-Package: com._1c.g5.v8.dt.testing;version="[3.1.0,4.0.0)",
|
||||
org.junit;version="[4.13.0,5.0.0)",
|
||||
org.junit.runner;version="[4.13.0,5.0.0)"
|
18
tests/com.e1c.v8codestyle.autosort.itests/build.properties
Normal file
18
tests/com.e1c.v8codestyle.autosort.itests/build.properties
Normal file
@ -0,0 +1,18 @@
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
fragment.properties,\
|
||||
workspace/
|
@ -0,0 +1,15 @@
|
||||
###############################################################################
|
||||
# Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
#
|
||||
# This program and the accompanying materials are made
|
||||
# available under the terms of the Eclipse Public License 2.0
|
||||
# which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
#
|
||||
# SPDX-License-Identifier: EPL-2.0
|
||||
#
|
||||
# Contributors:
|
||||
# 1C-Soft LLC - initial API and implementation
|
||||
###############################################################################
|
||||
#Properties file for com.e1c.v8codestyle.autosort.itests
|
||||
providerName = 1C-Soft LLC
|
||||
pluginName = 1C:Code style V8 Auto Sort Integration test plugin
|
27
tests/com.e1c.v8codestyle.autosort.itests/pom.xml
Normal file
27
tests/com.e1c.v8codestyle.autosort.itests/pom.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
|
||||
This program and the accompanying materials are made
|
||||
available under the terms of the Eclipse Public License 2.0
|
||||
which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
|
||||
SPDX-License-Identifier: EPL-2.0
|
||||
|
||||
Contributors:
|
||||
1C-Soft LLC - initial API and implementation
|
||||
-->
|
||||
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.e1c.v8codestyle</groupId>
|
||||
<artifactId>tests</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>com.e1c.v8codestyle.autosort.itests</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>eclipse-test-plugin</packaging>
|
||||
</project>
|
@ -0,0 +1,44 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.autosort.itests;
|
||||
|
||||
import com._1c.g5.v8.dt.core.platform.IBmModelManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IDtProjectManager;
|
||||
import com._1c.g5.wiring.AbstractServiceAwareModule;
|
||||
import com.e1c.v8codestyle.autosort.ISortService;
|
||||
import com.e1c.v8codestyle.internal.autosort.AutoSortPlugin;
|
||||
|
||||
/**
|
||||
* The external dependencies for AutoSort Integration tests plugin
|
||||
*
|
||||
* @author Dmitriy Marmyshev
|
||||
*/
|
||||
public class ExternalDependenciesModule
|
||||
extends AbstractServiceAwareModule
|
||||
{
|
||||
|
||||
public ExternalDependenciesModule()
|
||||
{
|
||||
super(AutoSortPlugin.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doConfigure()
|
||||
{
|
||||
// V8 DT
|
||||
bind(ISortService.class).toService();
|
||||
bind(IBmModelManager.class).toService();
|
||||
bind(IDtProjectManager.class).toService();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2021, 1C-Soft LLC and others.
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*
|
||||
* Contributors:
|
||||
* 1C-Soft LLC - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.e1c.v8codestyle.autosort.itests;
|
||||
|
||||
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com._1c.g5.v8.bm.core.IBmObject;
|
||||
import com._1c.g5.v8.bm.core.IBmTransaction;
|
||||
import com._1c.g5.v8.bm.integration.AbstractBmTask;
|
||||
import com._1c.g5.v8.bm.integration.IBmModel;
|
||||
import com._1c.g5.v8.dt.core.platform.IBmModelManager;
|
||||
import com._1c.g5.v8.dt.core.platform.IDtProject;
|
||||
import com._1c.g5.v8.dt.core.platform.IDtProjectManager;
|
||||
import com._1c.g5.v8.dt.metadata.mdclass.Configuration;
|
||||
import com._1c.g5.v8.dt.testing.GuiceModules;
|
||||
import com._1c.g5.v8.dt.testing.JUnitGuiceRunner;
|
||||
import com._1c.g5.v8.dt.testing.TestingWorkspace;
|
||||
import com.e1c.v8codestyle.autosort.AutoSortPreferences;
|
||||
import com.e1c.v8codestyle.autosort.ISortService;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* Tests for {@link ISortService}
|
||||
*/
|
||||
@RunWith(value = JUnitGuiceRunner.class)
|
||||
@GuiceModules(modules = { ExternalDependenciesModule.class })
|
||||
public class SortServiceTest
|
||||
{
|
||||
|
||||
private static final String PROJECT_NAME = "Sort";
|
||||
|
||||
@Rule
|
||||
public TestingWorkspace testingWorkspace = new TestingWorkspace(true, true);
|
||||
|
||||
@Inject
|
||||
private ISortService sortService;
|
||||
|
||||
@Inject
|
||||
public IDtProjectManager dtProjectManager;
|
||||
|
||||
@Inject
|
||||
public IBmModelManager bmModelManager;
|
||||
|
||||
@Test
|
||||
public void testSortOff() throws Exception
|
||||
{
|
||||
IProject project = testingWorkspace.setUpProject(PROJECT_NAME, getClass());
|
||||
assertNotNull(project);
|
||||
IDtProject dtProject = dtProjectManager.getDtProject(project);
|
||||
assertNotNull(dtProject);
|
||||
|
||||
IStatus status = sortService.sortAllMetadata(dtProject, new NullProgressMonitor());
|
||||
assertTrue(status.isOK());
|
||||
IBmObject object = getTopObjectByFqn(CONFIGURATION.getName(), dtProject);
|
||||
assertTrue(object instanceof Configuration);
|
||||
|
||||
Configuration configuration = (Configuration)object;
|
||||
assertFalse(configuration.getCommonModules().isEmpty());
|
||||
|
||||
assertEquals("ГМодуль", configuration.getCommonModules().get(0).getName());
|
||||
assertEquals("БМодуль", configuration.getCommonModules().get(1).getName());
|
||||
assertEquals("ОбщийМодуль", configuration.getCommonModules().get(2).getName());
|
||||
assertEquals("АМодуль", configuration.getCommonModules().get(3).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortSortTop() throws Exception
|
||||
{
|
||||
IProject project = testingWorkspace.setUpProject(PROJECT_NAME, getClass());
|
||||
assertNotNull(project);
|
||||
IDtProject dtProject = dtProjectManager.getDtProject(project);
|
||||
assertNotNull(dtProject);
|
||||
|
||||
IEclipsePreferences prefs = AutoSortPreferences.getPreferences(project);
|
||||
prefs.putBoolean(AutoSortPreferences.KEY_ALL_TOP, true);
|
||||
prefs.flush();
|
||||
|
||||
IStatus status = sortService.sortAllMetadata(dtProject, new NullProgressMonitor());
|
||||
assertTrue(status.isOK());
|
||||
IBmObject object = getTopObjectByFqn(CONFIGURATION.getName(), dtProject);
|
||||
assertTrue(object instanceof Configuration);
|
||||
|
||||
Configuration configuration = (Configuration)object;
|
||||
assertFalse(configuration.getCommonModules().isEmpty());
|
||||
|
||||
assertEquals("АМодуль", configuration.getCommonModules().get(0).getName());
|
||||
assertEquals("БМодуль", configuration.getCommonModules().get(1).getName());
|
||||
assertEquals("ГМодуль", configuration.getCommonModules().get(2).getName());
|
||||
assertEquals("ОбщийМодуль", configuration.getCommonModules().get(3).getName());
|
||||
}
|
||||
|
||||
protected IBmObject getTopObjectByFqn(final String fqn, IDtProject dtProject)
|
||||
{
|
||||
IBmModel model = this.bmModelManager.getModel(dtProject);
|
||||
return model.executeReadonlyTask(new AbstractBmTask<IBmObject>("GetObject")
|
||||
{
|
||||
|
||||
@Override
|
||||
public IBmObject execute(IBmTransaction transaction, IProgressMonitor progressMonitor)
|
||||
{
|
||||
return transaction.getTopObjectByFqn(fqn);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Sort</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
<nature>com._1c.g5.v8.dt.core.V8ConfigurationNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
Runtime-Version: 8.3.19
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="bfcde769-ba07-48bd-9026-64d301bb8077">
|
||||
<name>АМодуль</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>А модуль</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
<clientOrdinaryApplication>true</clientOrdinaryApplication>
|
||||
</mdclass:CommonModule>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="9e98f1c5-d74b-49b1-b58f-693663cff48f">
|
||||
<name>БМодуль</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Б модуль</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
<clientOrdinaryApplication>true</clientOrdinaryApplication>
|
||||
</mdclass:CommonModule>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="6f1efee7-e03b-4d91-bff1-85eb8165135d">
|
||||
<name>ГМодуль</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Г модуль</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
<clientOrdinaryApplication>true</clientOrdinaryApplication>
|
||||
</mdclass:CommonModule>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:CommonModule xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="db7e9dab-45c7-4f13-b973-2b8ded05e637">
|
||||
<name>ОбщийМодуль</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Общий модуль</value>
|
||||
</synonym>
|
||||
<server>true</server>
|
||||
<externalConnection>true</externalConnection>
|
||||
<clientOrdinaryApplication>true</clientOrdinaryApplication>
|
||||
</mdclass:CommonModule>
|
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>
|
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mdclass:Configuration xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="a184d5b1-2676-4279-9856-c55fd29ca9ca">
|
||||
<name>Sort</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>Sort</value>
|
||||
</synonym>
|
||||
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="df9bdbaa-4937-46b7-b6da-16bf6d75c9d1"/>
|
||||
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="bc43d33b-00f7-4793-be2f-9e51c85991d3"/>
|
||||
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="78aa4961-ac81-4c60-8c07-3cbdf05aac80"/>
|
||||
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="5daae9a6-f62c-497e-8570-73588ef03584"/>
|
||||
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="0a0e32e7-affa-4380-8a39-8901603ded2d"/>
|
||||
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="6d58e02d-4f3e-4c18-bce9-ad488925a114"/>
|
||||
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="bcebccb3-b730-41ad-bf55-6d2bc4023eca"/>
|
||||
<configurationExtensionCompatibilityMode>8.3.19</configurationExtensionCompatibilityMode>
|
||||
<defaultRunMode>ManagedApplication</defaultRunMode>
|
||||
<usePurposes>PersonalComputer</usePurposes>
|
||||
<usedMobileApplicationFunctionalities>
|
||||
<functionality>
|
||||
<use>true</use>
|
||||
</functionality>
|
||||
<functionality>
|
||||
<functionality>OSBackup</functionality>
|
||||
<use>true</use>
|
||||
</functionality>
|
||||
</usedMobileApplicationFunctionalities>
|
||||
<defaultLanguage>Language.English</defaultLanguage>
|
||||
<dataLockControlMode>Managed</dataLockControlMode>
|
||||
<objectAutonumerationMode>NotAutoFree</objectAutonumerationMode>
|
||||
<modalityUseMode>DontUse</modalityUseMode>
|
||||
<synchronousPlatformExtensionAndAddInCallUseMode>DontUse</synchronousPlatformExtensionAndAddInCallUseMode>
|
||||
<compatibilityMode>8.3.19</compatibilityMode>
|
||||
<languages uuid="58e06e29-5b1c-4bea-9358-f9cd51169821">
|
||||
<name>English</name>
|
||||
<synonym>
|
||||
<key>en</key>
|
||||
<value>English</value>
|
||||
</synonym>
|
||||
<languageCode>en</languageCode>
|
||||
</languages>
|
||||
<commonModules>CommonModule.ГМодуль</commonModules>
|
||||
<commonModules>CommonModule.БМодуль</commonModules>
|
||||
<commonModules>CommonModule.ОбщийМодуль</commonModules>
|
||||
<commonModules>CommonModule.АМодуль</commonModules>
|
||||
</mdclass:Configuration>
|
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>
|
@ -25,6 +25,7 @@
|
||||
|
||||
<modules>
|
||||
<module>com.e1c.v8codestyle.md.itests</module>
|
||||
<module>com.e1c.v8codestyle.autosort.itests</module>
|
||||
</modules>
|
||||
|
||||
<profiles>
|
||||
|
Loading…
x
Reference in New Issue
Block a user