Commit 83d0b098 authored by Kisslinger's avatar Kisslinger
Browse files

first version of pictures in the glossary

refs 706
parent ca294859
......@@ -51,6 +51,7 @@ import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
......@@ -63,6 +64,7 @@ import org.fortiss.af3.mira.command.glossary.DeleteWordElementCommand;
import org.fortiss.af3.mira.model.glossary.GlossaryEntry;
import org.fortiss.af3.mira.model.glossary.GlossaryEntryStatus;
import org.fortiss.af3.mira.model.glossary.WordElement;
import org.fortiss.af3.mira.ui.editor.images.ImageSection;
import org.fortiss.tooling.base.ui.editor.FormsEditorBase;
/**
......@@ -97,10 +99,13 @@ public class GlossaryEntryEditor extends FormsEditorBase<GlossaryEntry> {
.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true)
.hint(500, 120);
private Image image;
/** {@inheritDoc} */
@Override
protected void createSections() {
createGeneralSection();
createImageSection();
createAbbreviationsSection();
createSynonymSection();
createCommentSection();
......@@ -168,6 +173,13 @@ public class GlossaryEntryEditor extends FormsEditorBase<GlossaryEntry> {
}
/** create section for images */
private void createImageSection() {
Composite imagesComposite = createNewSection("Images",
"Images for futher description of the entry");
new ImageSection(imagesComposite, toolkit, editedObject);
}
/** create section for abbreviations */
private void createAbbreviationsSection() {
......
......@@ -96,7 +96,7 @@ public class GlossaryHoverInformationControl extends BrowserInformationControl {
/** {@inheritDoc} */
@Override
public Point computeSizeHint() {
return new Point(400, 800);
return new Point(400, 1000);
}
}
......@@ -79,6 +79,12 @@ public class GlossaryTextHover extends DefaultTextHover implements
// add HTML code for each result
for (EntrySearchResult resultListEntry : resultList) {
if (resultListEntry.getEntry().getImagesLength() > 0)
hoverText.append("<img src='"
+ resultListEntry.getEntry().getImages(0).getPath()
+ "' width='150' style='float:right;' />");
hoverText
.append("<span style='padding-right:1em;'><b><a href='id:"
+ resultListEntry.getEntry().getId()
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.ui.editor.images;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.fortiss.af3.mira.model.IImageContainer;
import org.fortiss.af3.mira.model.ImageItem;
import org.fortiss.tooling.kernel.service.ICommandStackService;
/**
*
* @author kisslinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class ImageBox {
private Composite composite;
private FormToolkit toolkit;
private ImageItem imageItem;
private Image image;
private IImageContainer editedObject;
/**
* @param imageItems
* @param composite
* @param toolkit
*/
public ImageBox(final Composite composite, FormToolkit toolkit,
ImageItem imageItem, IImageContainer editedObject) {
this.composite = composite;
this.toolkit = toolkit;
this.imageItem = imageItem;
this.editedObject = editedObject;
// load the image
try {
image = new Image(composite.getDisplay(), imageItem.getPath());
} catch (Exception e) {
// TODO: handle exception
return;
}
// create Canvas
final Canvas canvas = new Canvas(composite, SWT.BORDER);
final Rectangle imageSize = calcImageSize(image.getBounds(), 800, 200);
GridDataFactory.swtDefaults().hint(imageSize.width, imageSize.height)
.applyTo(canvas); // .indent(60, 0)
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (image != null) {
e.gc.drawImage(image, 0, 0, image.getBounds().width,
image.getBounds().height, 0, 0, imageSize.width,
imageSize.height);
}
}
});
// create remove button
final Button removePictureButton = toolkit.createButton(composite,
"Remove", SWT.FLAT);
GridDataFactory.swtDefaults().align(SWT.LEFT, SWT.CENTER)
.applyTo(removePictureButton);
removePictureButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
canvas.dispose();
removePictureButton.dispose();
remove();
}
});
}
private void remove() {
image.dispose();
image = null;
ICommandStackService.INSTANCE.runAsCommand(editedObject,
new Runnable() {
@Override
public void run() {
editedObject.getImagesList().remove(imageItem);
}
});
imageItem = null;
composite.getParent().layout();
// composite.getParent().getParent().pack();
composite.getParent().getParent().getParent().layout();
}
private Rectangle calcImageSize(Rectangle imageBounds, int maxWidth,
int maxHeight) {
double scaleFactor = Math.min((double) maxWidth
/ image.getBounds().width,
(double) maxHeight / image.getBounds().height);
return new Rectangle(0, 0, (int) (imageBounds.width * scaleFactor),
(int) (imageBounds.height * scaleFactor));
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.mira.ui.editor.images;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
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.FileDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.fortiss.af3.mira.model.IImageContainer;
import org.fortiss.af3.mira.model.ImageItem;
import org.fortiss.af3.mira.model.MiraFactory;
import org.fortiss.tooling.kernel.service.ICommandStackService;
/**
*
* @author kisslinger
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class ImageSection {
private Composite composite;
private FormToolkit toolkit;
private IImageContainer editedObject;
/**
* @param images
* @param composite
* @param toolkit
*/
public ImageSection(Composite composite, FormToolkit toolkit,
IImageContainer editedObject) {
super();
this.composite = composite;
this.toolkit = toolkit;
this.editedObject = editedObject;
createSectionElements();
}
/**
*
*/
private void createSectionElements() {
composite.setLayout(new GridLayout(1, false));
final Composite imagesComposite = toolkit.createComposite(composite);
imagesComposite.setLayout(new GridLayout(2, false));
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL)
.grab(true, true).hint(SWT.DEFAULT, SWT.DEFAULT)
.applyTo(imagesComposite);
// create image boxes
for (ImageItem item : editedObject.getImagesList()) {
new ImageBox(imagesComposite, toolkit, item, editedObject);
}
// create add button
Composite buttonList = toolkit.createComposite(composite);
buttonList.setLayout(new RowLayout());
Button addPictureButton = toolkit.createButton(buttonList, "Add",
SWT.FLAT);
addPictureButton.addSelectionListener(new SelectionAdapter() {
/** {@inheritDoc} */
@Override
public void widgetSelected(SelectionEvent e) {
String filename = openFileDialog(composite.getShell());
if (filename != null) {
final ImageItem newItem = MiraFactory.eINSTANCE
.createImageItem();
newItem.setPath(filename);
ICommandStackService.INSTANCE.runAsCommand(editedObject,
new Runnable() {
@Override
public void run() {
editedObject.getImagesList().add(newItem);
}
});
new ImageBox(imagesComposite, toolkit, newItem,
editedObject);
composite.layout();
// composite.getParent().pack();
composite.getParent().getParent().layout();
}
}
});
}
private String openFileDialog(Shell shell) {
FileDialog fileChooser = new FileDialog(shell, SWT.OPEN);
fileChooser.setText("Open image file");
// fileChooser.setFilterPath(currentDir);
fileChooser
.setFilterExtensions(new String[] { "*.gif; *.jpg; *.png; *.ico; *.bmp" });
fileChooser.setFilterNames(new String[] { "Image file"
+ " (gif, jpeg, png, ico, bmp)" });
return fileChooser.open();
}
}
......@@ -101,6 +101,13 @@
</eAnnotations>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ImageItem" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//IIdLabeled">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="path" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="IImageContainer">
<eStructuralFeatures xsi:type="ecore:EReference" name="images" upperBound="-1"
eType="#//ImageItem" containment="true"/>
</eClassifiers>
<eSubpackages name="usecase" nsURI="http://www.fortiss.org/af3/mira/usecase" nsPrefix="org-fortiss-af3-mira-usecase">
<eClassifiers xsi:type="ecore:EClass" name="UseCase" eSuperTypes="#//Requirement platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//element/IHierarchicElementContainer">
<eOperations name="getScenariosList">
......@@ -212,7 +219,7 @@
</eGenericType>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="GlossaryEntry" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedCommentedElement platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//element/IHierarchicElement">
<eClassifiers xsi:type="ecore:EClass" name="GlossaryEntry" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedCommentedElement platform:/plugin/org.fortiss.tooling.base/model/base.ecore#//element/IHierarchicElement #//IImageContainer">
<eOperations name="getGlossary" eType="#//glossary/Glossary">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return GlossaryEntryStaticImpl.getGlossary(this);"/>
......
......@@ -49,6 +49,12 @@
<genClasses ecoreClass="mira.ecore#//RequirementSpecification">
<genOperations ecoreOperation="mira.ecore#//RequirementSpecification/getRequirement"/>
</genClasses>
<genClasses ecoreClass="mira.ecore#//ImageItem">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute mira.ecore#//ImageItem/path"/>
</genClasses>
<genClasses ecoreClass="mira.ecore#//IImageContainer">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference mira.ecore#//IImageContainer/images"/>
</genClasses>
<nestedGenPackages prefix="Usecase" basePackage="org.fortiss.af3.mira.model" disposableProviderFactory="true"
ecorePackage="mira.ecore#//usecase">
<genEnums typeSafeEnumCompatible="false" ecoreEnum="mira.ecore#//usecase/ScenarioStepActionType">
......
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