Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications helper to show notifications #27

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.31.0",
org.eclipse.lsp4j.jsonrpc;bundle-version="0.23.1",
com.google.gson;bundle-version="2.11.0",
org.eclipse.ui.ide;bundle-version="3.22.200",
org.eclipse.ui.workbench.texteditor;bundle-version="3.17.400"
org.eclipse.ui.workbench.texteditor;bundle-version="3.17.400",
org.eclipse.mylyn.commons.ui;bundle-version="4.2.0"
Bundle-Classpath: .,
target/dependency/animal-sniffer-annotations-1.9.jar,
target/dependency/batik-constants-1.17.jar,
Expand All @@ -30,7 +31,9 @@ Bundle-Classpath: .,
target/dependency/bcutil-jdk18on-1.78.1.jar,
target/dependency/checker-qual-3.42.0.jar,
target/dependency/commons-codec-1.15.jar,
target/dependency/commons-collections4-4.4.jar,
target/dependency/commons-io-2.16.1.jar,
target/dependency/commons-lang3-3.14.0.jar,
target/dependency/commons-logging-1.2.jar,
target/dependency/error_prone_annotations-2.27.0.jar,
target/dependency/failureaccess-1.0.2.jar,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.mylyn.commons.ui.dialogs.AbstractNotificationPopup;

public final class NotificationHelper extends AbstractNotificationPopup {

private final String title;
private final String description;
private final NotificationType notificationType;

public NotificationHelper(final Display display, final String title, final String description, final NotificationType notificationType) {
super(display);
this.title = title;
this.description = description;
this.notificationType = notificationType;
}

private Image getInfoIcon() {
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
ImageDescriptor imageDescriptor = sharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK);
return imageDescriptor.createImage();
}

private void showStandardNotification(final Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
container.setLayout(new GridLayout(2, false));
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

Label iconLabel = new Label(container, SWT.NONE);
iconLabel.setImage(getInfoIcon());
iconLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));

Label notificationLabel = new Label(container, SWT.WRAP);
notificationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
notificationLabel.setText(this.description);
}

@Override
protected void createContentArea(final Composite parent) {
if (this.notificationType.equals(NotificationType.CUSTOMIZATION_CHANGED)) {
showStandardNotification(parent);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to avoid this tight coupling to a specific NotificationType. If we anticipate multiple notification types we can subclass those off a base ToolkitNotification type. Granular text (e.g. for the customization message) should be passed in at time of use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, then i'll also rename NotificationHelper as ToolkitNotification then and remove the NotificationType enum.

}

@Override
protected String getPopupShellTitle() {
return this.title;
}

@Override
protected Point getInitialSize() {
return new Point(60, 20);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.eclipse.amazonq.util;

public enum NotificationType {
CUSTOMIZATION_CHANGED
}