Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael Istria2016-10-21 16:13:47 +0000
committerMickael Istria2016-11-29 11:33:48 +0000
commit942e3d85fd1cd3fcdae0fdb83a11a89a79e74d71 (patch)
treee3833ddef0d7bec240bc8a0cac7c16ebf579a00e
parent9bc9eabfe497649569713f08b1cece21c7f98ecd (diff)
downloadeclipse.platform.ui-I20161129-2000.tar.gz
eclipse.platform.ui-I20161129-2000.tar.xz
eclipse.platform.ui-I20161129-2000.zip
Bug 98230 - UI to add/remove content-typesI20161129-2000
Bug: 98230 Change-Id: Id0b29ca7219725c83d98c505de83bbe4e832386e Signed-off-by: Mickael Istria <mistria@redhat.com>
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java10
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java127
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/NewContentTypeDialog.java97
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties12
4 files changed, 243 insertions, 3 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java
index 482c9327439..af02a2ea56b 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java
@@ -899,6 +899,16 @@ public class WorkbenchMessages extends NLS {
public static String ContentTypes_editDialog_messageHeader;
public static String ContentTypes_editDialog_message;
public static String ContentTypes_editDialog_label;
+ public static String ContentTypes_addRootContentTypeButton;
+ public static String ContentTypes_addChildContentTypeButton;
+ public static String ContentTypes_removeContentTypeButton;
+ public static String ContentTypes_newContentTypeDialog_title;
+ public static String ContentTypes_newContentTypeDialog_descritption;
+ public static String ContentTypes_newContentTypeDialog_nameLabel;
+ public static String ContentTypes_newContentTypeDialog_defaultNameNoParent;
+ public static String ContentTypes_newContentTypeDialog_defaultNameWithParent;
+ public static String ContentTypes_newContentTypeDialog_invalidContentTypeName;
+ public static String ContentTypes_failedAtEditingContentTypes;
public static String Edit;
// =========================================================================
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java
index 436e64a958c..8a32333cc32 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/ContentTypesPreferencePage.java
@@ -21,6 +21,8 @@ import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -29,6 +31,7 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
@@ -42,6 +45,13 @@ import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.PaletteData;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -89,6 +99,10 @@ public class ContentTypesPreferencePage extends PreferencePage implements
private IWorkbench workbench;
+ private Button removeContentTypeButton;
+
+ private Button addChildContentTypeButton;
+
private class Spec {
String name;
@@ -191,11 +205,52 @@ public class ContentTypesPreferencePage extends PreferencePage implements
}
private class ContentTypesLabelProvider extends LabelProvider {
+ private Image silhouette;
+
+ public ContentTypesLabelProvider() {
+ this.silhouette = createImage(getFont(), "\uD83D\uDC64"); //$NON-NLS-1$
+ }
+
+ private Image createImage(Font font, String s) {
+ TextLayout textLayout = new TextLayout(font.getDevice());
+ textLayout.setText(s);
+ textLayout.setFont(font);
+ Rectangle bounds = textLayout.getBounds();
+ PaletteData palette = new PaletteData(0xFF, 0xFF00, 0xFF0000);
+ ImageData imageData = new ImageData(bounds.width, bounds.height, 32, palette);
+ imageData.transparentPixel = palette
+ .getPixel(font.getDevice().getSystemColor(SWT.COLOR_TRANSPARENT).getRGB());
+ for (int column = 0; column < imageData.width; column++) {
+ for (int line = 0; line < imageData.height; line++) {
+ imageData.setPixel(column, line, imageData.transparentPixel);
+ }
+ }
+ Image image = new Image(font.getDevice(), imageData);
+ GC gc = new GC(image);
+ textLayout.draw(gc, 0, 0);
+ return image;
+ }
+
@Override
public String getText(Object element) {
IContentType contentType = (IContentType) element;
return contentType.getName();
}
+
+ @Override
+ public Image getImage(Object element) {
+ IContentType contentType = (IContentType) element;
+ if (contentType.isUserDefined()) {
+ return this.silhouette;
+ }
+ return super.getImage(element);
+ }
+
+ @Override
+ public void dispose() {
+ this.silhouette.dispose();
+ super.dispose();
+ }
}
private class ContentTypesContentProvider implements ITreeContentProvider {
@@ -567,7 +622,6 @@ public class ContentTypesPreferencePage extends PreferencePage implements
contentTypesViewer.setComparator(new ViewerComparator());
contentTypesViewer.setInput(Platform.getContentTypeManager());
GridData data = new GridData(GridData.FILL_BOTH);
- data.horizontalSpan = 2;
contentTypesViewer.getControl().setLayoutData(data);
contentTypesViewer
@@ -593,9 +647,80 @@ public class ContentTypesPreferencePage extends PreferencePage implements
charsetField.setEnabled(contentType != null);
addButton.setEnabled(contentType != null);
setButton.setEnabled(false);
+
+ addChildContentTypeButton.setEnabled(contentType != null);
+ removeContentTypeButton.setEnabled(contentType != null && contentType.isUserDefined());
}
});
}
+ Composite buttonsComposite = new Composite(composite, SWT.NONE);
+ buttonsComposite.setLayoutData(new GridData(SWT.DEFAULT, SWT.TOP, false, false));
+ buttonsComposite.setLayout(new GridLayout(1, false));
+ Button addRootContentTypeButton = new Button(buttonsComposite, SWT.PUSH);
+ setButtonLayoutData(addRootContentTypeButton);
+ addRootContentTypeButton.setText(WorkbenchMessages.ContentTypes_addRootContentTypeButton);
+ addRootContentTypeButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String id = "userCreated" + System.currentTimeMillis(); //$NON-NLS-1$
+ IContentTypeManager manager = (IContentTypeManager) contentTypesViewer.getInput();
+ NewContentTypeDialog dialog = new NewContentTypeDialog(ContentTypesPreferencePage.this.getShell(),
+ manager, null);
+ if (dialog.open() == IDialogConstants.OK_ID) {
+ try {
+ IContentType newContentType = manager.addContentType(id, dialog.getName(), null);
+ contentTypesViewer.refresh();
+ contentTypesViewer.setSelection(new StructuredSelection(newContentType));
+ } catch (CoreException e1) {
+ MessageDialog.openError(getShell(), WorkbenchMessages.ContentTypes_failedAtEditingContentTypes,
+ e1.getMessage());
+ }
+ }
+ }
+ });
+ addChildContentTypeButton = new Button(buttonsComposite, SWT.PUSH);
+ setButtonLayoutData(addChildContentTypeButton);
+ addChildContentTypeButton.setText(WorkbenchMessages.ContentTypes_addChildContentTypeButton);
+ addChildContentTypeButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String id = "userCreated" + System.currentTimeMillis(); //$NON-NLS-1$
+ IContentTypeManager manager = (IContentTypeManager) contentTypesViewer.getInput();
+ NewContentTypeDialog dialog = new NewContentTypeDialog(ContentTypesPreferencePage.this.getShell(),
+ manager,
+ getSelectedContentType());
+ if (dialog.open() == IDialogConstants.OK_ID) {
+ try {
+ IContentType newContentType = manager.addContentType(id, dialog.getName(),
+ getSelectedContentType());
+ contentTypesViewer.refresh(getSelectedContentType());
+ contentTypesViewer.setSelection(new StructuredSelection(newContentType));
+ } catch (CoreException e1) {
+ MessageDialog.openError(getShell(), WorkbenchMessages.ContentTypes_failedAtEditingContentTypes,
+ e1.getMessage());
+ }
+ }
+ }
+ });
+ addChildContentTypeButton.setEnabled(getSelectedContentType() != null);
+ removeContentTypeButton = new Button(buttonsComposite, SWT.PUSH);
+ setButtonLayoutData(removeContentTypeButton);
+ removeContentTypeButton.setText(WorkbenchMessages.ContentTypes_removeContentTypeButton);
+ removeContentTypeButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IContentType selectedContentType = getSelectedContentType();
+ try {
+ Platform.getContentTypeManager().removeContentType(selectedContentType.getId());
+ contentTypesViewer.refresh();
+ } catch (CoreException e1) {
+ MessageDialog.openError(getShell(), WorkbenchMessages.ContentTypes_failedAtEditingContentTypes,
+ e1.getMessage());
+ }
+ }
+ });
+ removeContentTypeButton
+ .setEnabled(getSelectedContentType() != null && getSelectedContentType().isUserDefined());
}
@Override
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/NewContentTypeDialog.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/NewContentTypeDialog.java
new file mode 100644
index 00000000000..f978fcde31b
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/NewContentTypeDialog.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Red Hat Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mickael Istria (Red Hat Inc.) - initial implementation
+ *******************************************************************************/
+package org.eclipse.ui.internal.dialogs;
+
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.internal.WorkbenchMessages;
+
+/**
+ * A dialog that asks for initial values to create a new content-type.
+ *
+ * @since 3.109
+ */
+public class NewContentTypeDialog extends Dialog {
+
+ private String name;
+ private IContentTypeManager manager;
+ private ControlDecoration decorator;
+
+ /**
+ * @param parentShell
+ */
+ protected NewContentTypeDialog(Shell parentShell, IContentTypeManager manager, IContentType parent) {
+ super(parentShell);
+ this.manager = manager;
+ String baseName = name = WorkbenchMessages.ContentTypes_newContentTypeDialog_defaultNameNoParent;
+ if (parent != null) {
+ baseName = name = NLS.bind(WorkbenchMessages.ContentTypes_newContentTypeDialog_defaultNameWithParent,
+ parent.getName());
+ }
+ int suffix = 2;
+ while (manager.getContentType(name) != null) {
+ name = baseName + " (" + suffix + ')'; //$NON-NLS-1$
+ suffix++;
+ }
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite res = (Composite) super.createDialogArea(parent);
+ res.setLayout(new GridLayout(2, false));
+ Label descLabel = new Label(res, SWT.NONE);
+ descLabel.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, false, false, 2, 1));
+ descLabel.setText(WorkbenchMessages.ContentTypes_newContentTypeDialog_descritption);
+ Label nameLabel = new Label(res, SWT.NONE);
+ nameLabel.setText(WorkbenchMessages.ContentTypes_newContentTypeDialog_nameLabel);
+ Text nameText = new Text(res, SWT.NONE);
+ nameText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+ nameText.setText(name);
+ nameText.addModifyListener(event -> {
+ name = nameText.getText();
+ if (validateName()) {
+ getButton(IDialogConstants.OK_ID).setEnabled(true);
+ decorator.hide();
+ } else {
+ getButton(IDialogConstants.OK_ID).setEnabled(false);
+ decorator.show();
+ }
+ });
+ decorator = new ControlDecoration(nameText, SWT.TOP | SWT.LEFT);
+ decorator.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR)
+ .getImage());
+ decorator.setDescriptionText(WorkbenchMessages.ContentTypes_newContentTypeDialog_invalidContentTypeName);
+ decorator.hide();
+ getShell().setText(WorkbenchMessages.ContentTypes_newContentTypeDialog_title);
+ return res;
+ }
+
+ private boolean validateName() {
+ return name.length() > 0 && manager.getContentType(name) == null;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties
index 27064617e36..9b5945c0598 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties
@@ -876,8 +876,16 @@ ContentTypes_editDialog_title=Edit Content Type Association
ContentTypes_editDialog_messageHeader=Edit Content Type Association
ContentTypes_editDialog_message=Edit content type association: (*.doc or report.doc for example)
ContentTypes_editDialog_label=&Content type:
-
-
+ContentTypes_addRootContentTypeButton=Add &Root...
+ContentTypes_addChildContentTypeButton=Add &Child...
+ContentTypes_removeContentTypeButton=Remove
+ContentTypes_newContentTypeDialog_title=Create a new content-type
+ContentTypes_newContentTypeDialog_descritption=Set initial attributes of a new content-type
+ContentTypes_newContentTypeDialog_nameLabel=Name:
+ContentTypes_newContentTypeDialog_defaultNameNoParent=Custom Content-Type
+ContentTypes_newContentTypeDialog_defaultNameWithParent=Custom Sub-type of {0}
+ContentTypes_newContentTypeDialog_invalidContentTypeName=Invalid name for a content-type
+ContentTypes_failedAtEditingContentTypes=Couldn't edit content-type registry
# =========================================================================
# Deprecated actions support

Back to the top