Commit 3fd8d5b6 authored by Adam Knapp's avatar Adam Knapp
Browse files

Refactoring enum HoverContentType


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent 95081691
......@@ -63,8 +63,8 @@ import org.eclipse.titan.designer.editors.ProposalCollector;
import org.eclipse.titan.designer.editors.Stylers;
import org.eclipse.titan.designer.editors.T3Doc;
import org.eclipse.titan.designer.editors.actions.DeclarationCollector;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.titan.designer.editors.ttcn3editor.TTCN3CodeSkeletons;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer;
......@@ -1535,7 +1535,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
}
}
}
hoverContent.addContent(ContentType.Info);
hoverContent.addContent(HoverContentType.INFO);
return hoverContent;
}
......
......@@ -50,8 +50,8 @@ import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.editors.ProposalCollector;
import org.eclipse.titan.designer.editors.T3Doc;
import org.eclipse.titan.designer.editors.actions.DeclarationCollector;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer;
import org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser;
......@@ -564,7 +564,7 @@ public final class Def_Type extends Definition {
body.addClassMembers(assignment, hoverContent, dc);
}
}
hoverContent.addContent(ContentType.Info);
hoverContent.addContent(HoverContentType.INFO);
return hoverContent;
}
}
......@@ -46,8 +46,8 @@ import org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.editors.ProposalCollector;
import org.eclipse.titan.designer.editors.actions.DeclarationCollector;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.ttcn3parser.IIdentifierReparser;
import org.eclipse.titan.designer.parsers.ttcn3parser.IdentifierReparser;
......@@ -563,7 +563,7 @@ public final class Def_Var extends Definition {
dc.addDescsContent(hoverContent);
dc.addAuthorsContent(hoverContent);
}
hoverContent.addContent(ContentType.Info);
hoverContent.addContent(HoverContentType.INFO);
return hoverContent;
}
}
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.designer.AST.TTCN3.definitions;
import org.eclipse.titan.designer.AST.Assignment;
......
......@@ -11,11 +11,8 @@ import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.preferences.PreferenceConstantValues;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
......@@ -26,9 +23,6 @@ import org.eclipse.ui.IEditorPart;
* */
public class SwitchHoverWindowContentAction extends AbstractHandler implements IEditorActionDelegate {
private static final String COMMAND_ID = "org.eclipse.titan.designer.editors.SwitchHoverWindowContentAction";
private static final String[] HOVER_WINDOW_CONTENT_TYPE = new String[] {
PreferenceConstantValues.HOVER_WINDOW_CONTENT_COMMENT, PreferenceConstantValues.HOVER_WINDOW_CONTENT_PEEK
};
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
......@@ -56,18 +50,18 @@ public class SwitchHoverWindowContentAction extends AbstractHandler implements I
}
private void switchHoverWindowContent() {
final IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
final String hoverWindowContent = prefStore.getString(PreferenceConstants.HOVER_WINDOW_CONTENT);
final HoverContentType storedType = HoverContentType.loadAsProperty();
final HoverContentType[] hoverContentTypes = HoverContentType.asArray();
int i = 0;
for (; i < HOVER_WINDOW_CONTENT_TYPE.length; i++) {
if (hoverWindowContent.equals(HOVER_WINDOW_CONTENT_TYPE[i])) {
for (; i < hoverContentTypes.length; i++) {
if (storedType == hoverContentTypes[i]) {
i++;
break;
}
}
if (i == HOVER_WINDOW_CONTENT_TYPE.length) {
if (i == hoverContentTypes.length) {
i = 0;
}
prefStore.setValue(PreferenceConstants.HOVER_WINDOW_CONTENT, HOVER_WINDOW_CONTENT_TYPE[i]);
HoverContentType.storeAsProperty(hoverContentTypes[i]);
}
}
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
package org.eclipse.titan.designer.editors.controls;
import java.util.Locale;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
/**
* @author Adam Knapp
* */
public enum HoverContentType {
INFO, SOURCE;
public static HoverContentType[] asArray() {
return new HoverContentType[] { INFO, SOURCE };
}
/**
* This works like {@link #valueOf(String)} except it is case
* insensitive. This and {@link #toString()} should be kept
* consistent.
*/
public static HoverContentType createInstance(final String str) {
return HoverContentType.valueOf(str.toUpperCase());
}
public static HoverContentType getDefault() {
return INFO;
}
public static String[][] getDisplayNamesAndValues() {
return new String[][] { { "code comment and info", INFO.toString() },
{ "code peek", SOURCE.toString() } };
}
public static void storeAsProperty(final HoverContentType type) {
Activator.getDefault().getPreferenceStore().setValue(PreferenceConstants.HOVER_WINDOW_CONTENT, type.toString());
}
public static HoverContentType loadAsProperty() {
final String storedType = Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.HOVER_WINDOW_CONTENT);
return storedType.isEmpty() ? getDefault() : createInstance(storedType);
}
@Override
public String toString() {
return name().toLowerCase(Locale.ENGLISH);
}
}
......@@ -16,7 +16,6 @@ import org.eclipse.titan.designer.AST.Location;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.declarationsearch.Declaration;
import org.eclipse.titan.designer.editors.ColorManager;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.titan.designer.editors.ttcn3editor.CodeScanner;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
......@@ -80,7 +79,7 @@ public class PeekSource {
public static void addStyledSource(String source, Ttcn3HoverContent content) {
if (source == null) {
content.addContent(ContentType.Source, source, null);
content.addContent(HoverContentType.SOURCE, source, null);
return;
}
......@@ -151,6 +150,6 @@ public class PeekSource {
ranges.add(range);
}
content.addContent(ContentType.Source, source, ranges);;
content.addContent(HoverContentType.SOURCE, source, ranges);;
}
}
......@@ -24,7 +24,6 @@ import org.eclipse.swt.graphics.Color;
* @author Miklos Magyari
*/
public class Ttcn3HoverContent {
public enum ContentType { Info, Source };
private class ContentEntry {
String text;
......@@ -39,21 +38,21 @@ public class Ttcn3HoverContent {
private StringBuilder sb = new StringBuilder();
private List<StyleRange> styles = new ArrayList<StyleRange>();
private Map<ContentType, ContentEntry> map = new HashMap<ContentType, ContentEntry>();
private Map<HoverContentType, ContentEntry> map = new HashMap<HoverContentType, ContentEntry>();
public void addContent(ContentType type, String text, List<StyleRange> range) {
public void addContent(HoverContentType type, String text, List<StyleRange> range) {
final ContentEntry mapentry = new ContentEntry(text, range);
map.put(type, mapentry);
}
public void addContent(ContentType type) {
public void addContent(HoverContentType type) {
final ContentEntry mapentry = new ContentEntry(sb.toString(), styles);
map.put(type, mapentry);
styles.clear();
sb.setLength(0);
}
public boolean hasText(ContentType type) {
public boolean hasText(HoverContentType type) {
final ContentEntry mapentry = map.get(type);
if (mapentry == null) {
return false;
......@@ -64,7 +63,7 @@ public class Ttcn3HoverContent {
return true;
}
public String getText(ContentType type) {
public String getText(HoverContentType type) {
final ContentEntry mapentry = map.get(type);
if (mapentry == null) {
return null;
......@@ -72,7 +71,7 @@ public class Ttcn3HoverContent {
return mapentry.text;
}
public List<StyleRange> getRanges(ContentType type) {
public List<StyleRange> getRanges(HoverContentType type) {
final ContentEntry mapentry = map.get(type);
if (mapentry == null) {
return null;
......
......@@ -16,10 +16,7 @@ import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.editors.actions.SwitchHoverWindowContentAction;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.keys.IBindingService;
......@@ -35,8 +32,7 @@ public class Ttcn3HoverInfoControl extends AbstractInformationControl implements
private Ttcn3HoverContent content;
private Shell fShell;
private boolean isRich;
private ContentType actualType =
Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.HOVER_WINDOW_CONTENT).equals("comment") ? ContentType.Info : ContentType.Source;
private HoverContentType actualType = HoverContentType.loadAsProperty();
public Ttcn3HoverInfoControl(Shell parentShell, String string) {
super(parentShell, string);
......
......@@ -27,7 +27,6 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchPart;
......@@ -112,8 +111,8 @@ public class Ttcn3SourceViewControl implements IInformationControl, IInformation
public void setInformation(String information) {
Ttcn3HoverContent content = new Ttcn3HoverContent();
PeekSource.addStyledSource(information, content);
viewer.setText(content.getText(ContentType.Source));
for (StyleRange range : content.getRanges(ContentType.Source)) {
viewer.setText(content.getText(HoverContentType.SOURCE));
for (StyleRange range : content.getRanges(HoverContentType.SOURCE)) {
viewer.setStyleRange(range);
}
......
......@@ -38,13 +38,12 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.definitions.IHoverContent;
import org.eclipse.titan.designer.AST.TTCN3.types.ClassTypeBody;
import org.eclipse.titan.designer.AST.TTCN3.types.Class_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type;
import org.eclipse.titan.designer.editors.BaseTextHover;
import org.eclipse.titan.designer.editors.IReferenceParser;
import org.eclipse.titan.designer.editors.Stylers;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.editors.controls.PeekSource;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverContent.ContentType;
import org.eclipse.titan.designer.editors.controls.Ttcn3HoverInfoControl;
import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
import org.eclipse.titan.designer.parsers.GlobalParser;
......@@ -132,7 +131,7 @@ public final class TextHover extends BaseTextHover implements ITextHoverExtensio
if (info == null) {
info = new Ttcn3HoverContent();
info.addContent(ContentType.Info, tooltip.toString(), styles);
info.addContent(HoverContentType.INFO, tooltip.toString(), styles);
}
PeekSource.addStyledSource(PeekSource.getPeekSource(editor, file, assignment.getDeclaration()), info);
......
......@@ -292,11 +292,6 @@ public final class PreferenceConstantValues {
public static final String BEFORE_BUILD_CLEAR_CONSOLE = "Clear";
public static final String BEFORE_BUILD_PRINT_CONSOLE_DELIMITERS = "Print delimiter";
// Content of hover window
public static final String HOVER_WINDOW_CONTENT_COMMENT = "comment";
public static final String HOVER_WINDOW_CONTENT_PEEK = "peek";
/** private constructor to disable instantiation */
private PreferenceConstantValues() {
//Do nothing
......
......@@ -17,6 +17,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.GeneralConstants;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.osgi.service.prefs.Preferences;
import org.eclipse.swt.graphics.RGB;
......@@ -65,7 +66,7 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
preferenceStore.setDefault(PreferenceConstants.CONTENTASSISTANT_PROPOSAL_SORTING, PreferenceConstantValues.SORT_BY_RELEVANCE);
preferenceStore.setDefault(PreferenceConstants.CONTENTASSISTANT_AUTO_ACTIVATION, true);
preferenceStore.setDefault(PreferenceConstants.CONTENTASSISTANT_AUTO_ACTIVATION_DELAY, 100);
preferenceStore.setDefault(PreferenceConstants.HOVER_WINDOW_CONTENT, PreferenceConstantValues.HOVER_WINDOW_CONTENT_COMMENT);
preferenceStore.setDefault(PreferenceConstants.HOVER_WINDOW_CONTENT, HoverContentType.getDefault().toString());
// export
preferenceStore.setDefault(PreferenceConstants.EXPORT_EXCLUDE_WORKING_DIRECTORY_CONTENTS, true);
......
......@@ -22,6 +22,7 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.titan.common.logging.ErrorReporter;
import org.eclipse.titan.designer.Activator;
import org.eclipse.titan.designer.editors.controls.HoverContentType;
import org.eclipse.titan.designer.preferences.PreferenceConstantValues;
import org.eclipse.titan.designer.preferences.PreferenceConstants;
import org.eclipse.titan.designer.productUtilities.ProductConstants;
......@@ -37,10 +38,6 @@ public final class ContentAssistPage extends FieldEditorPreferencePage implement
{ PreferenceConstantValues.SORT_BY_RELEVANCE, PreferenceConstantValues.SORT_BY_RELEVANCE },
{ PreferenceConstantValues.SORT_ALPHABETICALLY, PreferenceConstantValues.SORT_ALPHABETICALLY } };
private static final String[][] HOVER_OPTIONS = new String[][] {
{ "code comment", PreferenceConstantValues.HOVER_WINDOW_CONTENT_COMMENT },
{ "code peek", PreferenceConstantValues.HOVER_WINDOW_CONTENT_PEEK } };
private Composite pageComposite;
private Group insertionGroup;
......@@ -147,7 +144,7 @@ public final class ContentAssistPage extends FieldEditorPreferencePage implement
hoverWindowContentComposite.setLayoutData(gridData);
hoverWindowContentCombo = new ComboFieldEditor(PreferenceConstants.HOVER_WINDOW_CONTENT,
"Hover window content:", HOVER_OPTIONS, hoverWindowContentComposite);
"Hover window content:", HoverContentType.getDisplayNamesAndValues(), hoverWindowContentComposite);
final Label text2 = hoverWindowContentCombo.getLabelControl(hoverWindowContentComposite);
text2.setToolTipText("What do you want to see as hover tooltip");
addField(hoverWindowContentCombo);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment